Skip to content

Commit

Permalink
migrate to file-scoped namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Nov 3, 2024
1 parent 333d8a8 commit c49584d
Show file tree
Hide file tree
Showing 651 changed files with 57,640 additions and 58,296 deletions.
87 changes: 43 additions & 44 deletions Automate/Framework/AutomateAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,60 @@
using StardewModdingAPI;
using StardewValley;

namespace Pathoschild.Stardew.Automate.Framework
namespace Pathoschild.Stardew.Automate.Framework;

/// <summary>The API which lets other mods interact with Automate.</summary>
public class AutomateAPI : IAutomateAPI
{
/// <summary>The API which lets other mods interact with Automate.</summary>
public class AutomateAPI : IAutomateAPI
{
/*********
** Fields
*********/
/// <summary>Encapsulates monitoring and logging.</summary>
private readonly IMonitor Monitor;
/*********
** Fields
*********/
/// <summary>Encapsulates monitoring and logging.</summary>
private readonly IMonitor Monitor;

/// <summary>Manages machine groups.</summary>
private readonly MachineManager MachineManager;
/// <summary>Manages machine groups.</summary>
private readonly MachineManager MachineManager;


/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
/// <param name="machineManager">Manages machine groups.</param>
internal AutomateAPI(IMonitor monitor, MachineManager machineManager)
{
this.Monitor = monitor;
this.MachineManager = machineManager;
}
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
/// <param name="machineManager">Manages machine groups.</param>
internal AutomateAPI(IMonitor monitor, MachineManager machineManager)
{
this.Monitor = monitor;
this.MachineManager = machineManager;
}

/// <summary>Add an automation factory.</summary>
/// <param name="factory">An automation factory which construct machines, containers, and connectors.</param>
public void AddFactory(IAutomationFactory factory)
{
this.Monitor.Log($"Adding automation factory: {factory.GetType().AssemblyQualifiedName}");
this.MachineManager.Factory.Add(factory);
}
/// <summary>Add an automation factory.</summary>
/// <param name="factory">An automation factory which construct machines, containers, and connectors.</param>
public void AddFactory(IAutomationFactory factory)
{
this.Monitor.Log($"Adding automation factory: {factory.GetType().AssemblyQualifiedName}");
this.MachineManager.Factory.Add(factory);
}

/// <summary>Get the status of machines in a tile area. This is a specialized API for Data Layers and similar mods.</summary>
/// <param name="location">The location for which to display data.</param>
/// <param name="tileArea">The tile area for which to display data.</param>
public IDictionary<Vector2, int> GetMachineStates(GameLocation location, Rectangle tileArea)
/// <summary>Get the status of machines in a tile area. This is a specialized API for Data Layers and similar mods.</summary>
/// <param name="location">The location for which to display data.</param>
/// <param name="tileArea">The tile area for which to display data.</param>
public IDictionary<Vector2, int> GetMachineStates(GameLocation location, Rectangle tileArea)
{
IDictionary<Vector2, int> data = new Dictionary<Vector2, int>();
foreach (IMachine machine in this.MachineManager.GetForApi(location).SelectMany(group => group.Machines))
{
IDictionary<Vector2, int> data = new Dictionary<Vector2, int>();
foreach (IMachine machine in this.MachineManager.GetForApi(location).SelectMany(group => group.Machines))
if (machine.TileArea.Intersects(tileArea))
{
if (machine.TileArea.Intersects(tileArea))
int state = (int)machine.GetState();
foreach (Vector2 tile in machine.TileArea.GetTiles())
{
int state = (int)machine.GetState();
foreach (Vector2 tile in machine.TileArea.GetTiles())
{
if (tileArea.Contains((int)tile.X, (int)tile.Y))
data[tile] = state;
}
if (tileArea.Contains((int)tile.X, (int)tile.Y))
data[tile] = state;
}
}

return data;
}

return data;
}
}
75 changes: 37 additions & 38 deletions Automate/Framework/AutomateContainerPreference.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
using StardewValley.Mods;

namespace Pathoschild.Stardew.Automate.Framework
namespace Pathoschild.Stardew.Automate.Framework;

/// <summary>How Automate should use a container.</summary>
internal enum AutomateContainerPreference
{
/// <summary>How Automate should use a container.</summary>
internal enum AutomateContainerPreference
{
/// <summary>Allow input/output for this container.</summary>
Allow,
/// <summary>Allow input/output for this container.</summary>
Allow,

/// <summary>Prefer input/output for this container over non-preferred containers.</summary>
Prefer,

/// <summary>Prefer input/output for this container over non-preferred containers.</summary>
Prefer,
/// <summary>Disable input/output for this container.</summary>
Disable
}

/// <summary>Disable input/output for this container.</summary>
Disable
/// <summary>Provides extension methods for <see cref="AutomateContainerPreference"/>.</summary>
internal static class AutomateContainerHelper
{
/*********
** Accessors
*********/
/// <summary>The <see cref="ModDataDictionary"/> key for chest storage options.</summary>
public const string StoreItemsKey = "Pathoschild.Automate/StoreItems";

/// <summary>The <see cref="ModDataDictionary"/> key for chest output options.</summary>
public const string TakeItemsKey = "Pathoschild.Automate/TakeItems";


/*********
** Methods
*********/
/// <summary>Get whether IO is enabled.</summary>
/// <param name="preference">The IO preference.</param>
public static bool IsAllowed(this AutomateContainerPreference preference)
{
return preference != AutomateContainerPreference.Disable;
}

/// <summary>Provides extension methods for <see cref="AutomateContainerPreference"/>.</summary>
internal static class AutomateContainerHelper
/// <summary>Get whether IO is preferred.</summary>
/// <param name="preference">The IO preference.</param>
public static bool IsPreferred(this AutomateContainerPreference preference)
{
/*********
** Accessors
*********/
/// <summary>The <see cref="ModDataDictionary"/> key for chest storage options.</summary>
public const string StoreItemsKey = "Pathoschild.Automate/StoreItems";

/// <summary>The <see cref="ModDataDictionary"/> key for chest output options.</summary>
public const string TakeItemsKey = "Pathoschild.Automate/TakeItems";


/*********
** Methods
*********/
/// <summary>Get whether IO is enabled.</summary>
/// <param name="preference">The IO preference.</param>
public static bool IsAllowed(this AutomateContainerPreference preference)
{
return preference != AutomateContainerPreference.Disable;
}

/// <summary>Get whether IO is preferred.</summary>
/// <param name="preference">The IO preference.</param>
public static bool IsPreferred(this AutomateContainerPreference preference)
{
return preference == AutomateContainerPreference.Prefer;
}
return preference == AutomateContainerPreference.Prefer;
}
}
Loading

0 comments on commit c49584d

Please sign in to comment.