Made building consume resources

Now may build more than one if resources allow
building placement is red/green for indicating success
This commit is contained in:
2024-03-10 07:50:26 -05:00
parent 856b6a0400
commit d74bfda9a3
8 changed files with 53 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
extends Node
signal changed_resource
@export var resources := {}
@@ -10,6 +10,29 @@ func _on_gained_resource(res: GameResource) -> void:
}
changed_resource.emit(ResourceChangedSignal.new(changed_resources))
func pickup(resource: GameResource) -> void:
if not resources.has(resource):
resources[resource] = 0
resources[resource] += resource.pickup_value
var changed_resources := {
resource: resource.pickup_value
}
changed_resource.emit(ResourceChangedSignal.new(changed_resources))
func has_amount(res: GameResource, amount: int) -> bool:
return resources[res] >= amount if resources.has(res) else false
func has_resources(cost: Dictionary) -> bool:
return cost.keys().reduce(func(accum, res): return accum and has_amount(res, cost[res]), true)
func use_resources(cost: Dictionary) -> void:
var changed_resources := {
}
for res in cost.keys():
resources[res] -= cost[res]
changed_resources[res] = -cost[res]
changed_resource.emit(ResourceChangedSignal.new(changed_resources))
#func _on_timer_timeout() -> void:
#var corrupted_resources := Grid.get_corrupted_resources()
#if corrupted_resources.size() > 0: