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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user