Table of Contents

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

Costs IReadOnlyList<ResourceCost>

Fields

Empty

Creates an empty PlaceableCosts.

public static readonly PlaceableCosts Empty

Field Value

PlaceableCosts

Properties

Costs

public IReadOnlyList<ResourceCost> Costs { get; init; }

Property Value

IReadOnlyList<ResourceCost>

IsEmpty

Checks if the costs are empty (no resources required).

public bool IsEmpty { get; }

Property Value

bool

ResourceCount

Gets the total number of different resources required.

public int ResourceCount { get; }

Property Value

int

Methods

Add(ResourceCost)

Adds a resource cost to the costs.

public PlaceableCosts Add(ResourceCost cost)

Parameters

cost ResourceCost

Returns

PlaceableCosts

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

dictionary Dictionary<string, int>

Returns

PlaceableCosts

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

tuples (string Resource, int Amount)[]

Returns

PlaceableCosts

GetCost(ResourceId)

Gets the cost for a specific resource.

public int GetCost(ResourceId resource)

Parameters

resource ResourceId

The 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

resourceId string

The 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

IEnumerator<ResourceCost>

GetResourceIds()

Gets all resource IDs that have a cost.

public IEnumerable<ResourceId> GetResourceIds()

Returns

IEnumerable<ResourceId>

HasCost(ResourceId)

Checks if a resource has a cost.

public bool HasCost(ResourceId resource)

Parameters

resource ResourceId

Returns

bool

HasCost(string)

Checks if a resource has a cost by string ID.

public bool HasCost(string resourceId)

Parameters

resourceId string

Returns

bool

Remove(ResourceId)

Removes a resource cost from the costs.

public PlaceableCosts Remove(ResourceId resource)

Parameters

resource ResourceId

Returns

PlaceableCosts

ToDictionary()

Converts the costs to a dictionary (for backward compatibility).

public Dictionary<string, int> ToDictionary()

Returns

Dictionary<string, int>