Class PlaceableCosts
- Namespace
- MoonBark.GridPlacement.Core.Types
- Assembly
- MoonBark.GridPlacement.Core.dll
Strongly-typed collection of resource costs. Replaces Dictionary<string, int> with type safety and better API.
public record PlaceableCosts : IEquatable<PlaceableCosts>
- Inheritance
-
PlaceableCosts
- Implements
- Inherited Members
Constructors
PlaceableCosts(IReadOnlyList<ResourceCost>)
Strongly-typed collection of resource costs. Replaces Dictionary<string, int> with type safety and better API.
public PlaceableCosts(IReadOnlyList<ResourceCost> Costs)
Parameters
CostsIReadOnlyList<ResourceCost>
Fields
Empty
Creates an empty PlaceableCosts.
public static readonly PlaceableCosts Empty
Field Value
Properties
Costs
public IReadOnlyList<ResourceCost> Costs { get; init; }
Property Value
IsEmpty
Checks if the costs are empty (no resources required).
public bool IsEmpty { get; }
Property Value
ResourceCount
Gets the total number of different resources required.
public int ResourceCount { get; }
Property Value
Methods
Add(ResourceCost)
Adds a resource cost to the costs.
public PlaceableCosts Add(ResourceCost cost)
Parameters
costResourceCost
Returns
FromDictionary(Dictionary<string, int>)
Creates a PlaceableCosts from a dictionary of string resource IDs to amounts.
public static PlaceableCosts FromDictionary(Dictionary<string, int> dictionary)
Parameters
dictionaryDictionary<string, int>
Returns
FromTuples(params (string Resource, int Amount)[])
Creates a PlaceableCosts from a list of tuples.
public static PlaceableCosts FromTuples(params (string Resource, int Amount)[] tuples)
Parameters
Returns
GetCost(ResourceId)
Gets the cost for a specific resource.
public int GetCost(ResourceId resource)
Parameters
resourceResourceIdThe resource ID to look up.
Returns
- int
The cost amount, or 0 if the resource is not in the costs.
GetCost(string)
Gets the cost for a specific resource by string ID.
public int GetCost(string resourceId)
Parameters
resourceIdstringThe resource ID string to look up.
Returns
- int
The cost amount, or 0 if the resource is not in the costs.
GetEnumerator()
public IEnumerator<ResourceCost> GetEnumerator()
Returns
GetResourceIds()
Gets all resource IDs that have a cost.
public IEnumerable<ResourceId> GetResourceIds()
Returns
HasCost(ResourceId)
Checks if a resource has a cost.
public bool HasCost(ResourceId resource)
Parameters
resourceResourceId
Returns
HasCost(string)
Checks if a resource has a cost by string ID.
public bool HasCost(string resourceId)
Parameters
resourceIdstring
Returns
Remove(ResourceId)
Removes a resource cost from the costs.
public PlaceableCosts Remove(ResourceId resource)
Parameters
resourceResourceId
Returns
ToDictionary()
Converts the costs to a dictionary (for backward compatibility).
public Dictionary<string, int> ToDictionary()