SpendMaterialsRuleGeneric
Summary
Section titled “Summary”Generic material spending rule for placement validation.
Allows 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.
Required inventory methods:
• try_add
or add
- Parameters: type: Resource, count: int
• try_remove
or remove
- Parameters: type: Resource, count: int
• get_count
- Parameters: type: Resource - Returns: int
Alternative: inherit from VirtualItemContainer and implement the methods.
Properties
Section titled “Properties”resource_stacks_to_spend: Array[ResourceStack] = []
How many of each type need to be spent for the building rule to pass Resource should have fields type and count defined
locator: NodeLocator
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
Methods
Section titled “Methods”func setup( p_gts: GridTargetingState ) -> Array[String]
func apply( ) -> Array[String]
Tries to spend the resources from the _mat_container Returns an array of issues found during the spending process If the spending was successful, the array will be empty
func tear_down( )
func validate_placement( ) -> RuleResult
Checks to see if there are enough resources to build item
func check_missing_resources( p_owner_root_container ) -> Array[ResourceStack]
Checks the resouce _mat_container to see if it has enough of each resource type Returns ItemStacks that contain the amount missing for each type
func _get_material_container_from_user( user: Node ) -> Node
Finds the container for the spendable materials by searching either for the matching node by name or class name Starts at the user node of the building system and then checks children nodes recursively
func _get_pre_setup_issues( p_gts: GridTargetingState ) -> Array[String]
func _get_post_setup_issues( ) -> Array[String]
func _get_material_name( p_material: Resource ) -> String
Source
Section titled “Source”addons/grid_building/placement/placement_rules/template_rules/spend_materials_rule_generic.gd
This API reference is automatically generated from the plugin source code. For implementation examples and usage guides, see the guides section.