Class SpendMaterialsRuleGeneric
- Namespace
- GridPlacement.GDScript
- Assembly
- MoonBark.GridPlacement.GDScript.dll
Generic material spending rule for placement validation.\n\nAllows custom resource classes without building system inventory dependencies. Expects resource stacks with type and count properties. Looks for _mat_container on the target building node.[br][br] [b]Required inventory methods:[/b][br] • [code]try_add[/code] or [code]add[/code] - Parameters: type: Resource, count: int[br] • [code]try_remove[/code] or [code]remove[/code] - Parameters: type: Resource, count: int[br] • [code]get_count[/code] - Parameters: type: Resource - Returns: int[br][br] Alternative: inherit from VirtualItemContainer and implement the methods.
class SpendMaterialsRuleGeneric extends PlacementRule
Properties
resource_stacks_to_spend
How many of each type need to be spent for the building rule to pass Resource should have fields type and count defined
@export var resource_stacks_to_spend: Array[ResourceStack] = []
locator
Used to find the inventory on the _owner_root passed in as a setup parameter so that the rule knows where to spend the resource_stacks_to_spend from
@export var locator: NodeLocator
issues
var issues: Array[String] = []
spent_stacks
var spent_stacks: Array[ResourceStack] = []
success
var success = true
spent_stack
var spent_stack: ResourceStack
spent
var spent = 0
missing_resources_stacks
var missing_resources_stacks: Array[ResourceStack] = check_missing_resources(_mat_container)
failed_message
var failed_message: String = "Not Enough Materials: "
material_name
var material_name = _get_material_name(missing_stack.type)
missing_resources
var missing_resources: Array[ResourceStack] = []
had_count
var had_count: int = p_owner_root_container.get_count(needed_resource.type)
missing_count
var missing_count = needed_resource.count - had_count
missing_stack
var missing_stack = ResourceStack.new(needed_resource.type, missing_count)
issues
var issues: Array[String] = []
issues
var issues: Array[String] = []
Methods
setup
func setup(p_gts : GridTargetingState) -> Array[String]:
Parameters
p_gts
Returns
apply
func apply() -> Array[String]:
Returns
tear_down
func tear_down() -> void:
Returns
validate_placement
func validate_placement() -> RuleResult:
Returns
check_missing_resources
func check_missing_resources(p_owner_root_container) -> Array[ResourceStack]:
Parameters
p_owner_root_container