Table of Contents

Class SpendMaterialsRuleById

Namespace
GridPlacement.GDScript
Assembly
MoonBark.GridPlacement.GDScript.dll

Canonical id-keyed material spending rule (5.1.0).\n\nCosts are a [code]Dictionary[StringName, int][/code] of item id -> amount. Ids decouple the placement contract from the consumer's inventory schema: the container owns the id -> item mapping and exposes it through an id-based interface. This is the same id convention used by [BuildCost] for the refund-on-demolish contract.[br][br] [b]Required container interface[/b] (resolved via [member locator] on the owner root):[br] • [code]get_count_by_id(id: StringName) -> int[/code][br] • [code]try_remove_by_id(id: StringName, amount: int) -> int[/code][br] • [code]try_add_by_id(id: StringName, amount: int) -> int[/code] (rollback)[br][br] Replaces the deprecated [SpendMaterialsRuleGeneric] (ResourceStack-keyed).

class SpendMaterialsRuleById extends PlacementRule
SpendMaterialsRuleById

Properties

costs

Item id -> amount that must be spent for placement to succeed.

@export var costs: Dictionary[StringName, int] = {}

locator

Used to find the inventory container on the owner root passed in as a setup parameter, so the rule knows where to spend from.

@export var locator: NodeLocator

missing

var missing: Dictionary[StringName, int] = {}

failed_message

var failed_message = "Not Enough Materials: "

issues

var issues: Array[String] = super.get_setup_issues()

spent

var spent: Dictionary[StringName, int] = {}

removed

var removed: int = _mat_container.try_remove_by_id(id, costs[id])

missing

var missing: Dictionary[StringName, int] = {}

have

var have: int = p_container.get_count_by_id(id)

issues

var issues: Array[String] = super.get_setup_issues()

Methods

setup

func setup(p_gts: GridTargetingState) -> Array[String]:

Parameters

p_gts

Returns

validate_placement

func validate_placement() -> RuleResult:

Returns

apply

func apply() -> Array[String]:

Returns

tear_down

func tear_down() -> void:

Returns

get_missing_costs

func get_missing_costs(p_container: Object) -> Dictionary[StringName, int]:

Parameters

p_container

Returns

get_setup_issues

func get_setup_issues() -> Array[String]:

Returns