More building work

This commit is contained in:
2024-03-13 09:57:10 -05:00
parent 4718108407
commit 4f0f97b91d
10 changed files with 43 additions and 31 deletions

View File

@@ -13,11 +13,13 @@ func _on_gained_resource(res: GameResource) -> void:
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))
var pickup_amount = min(resource.pickup_value, resource.storage_max - resources[resource])
if pickup_amount > 0:
resources[resource] += pickup_amount
var changed_resources := {
resource: pickup_amount
}
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

View File

@@ -29,7 +29,7 @@ func change_building(data: BuildingBase) -> void:
layer_info[Constants.TilemapLayers.BUILDINGS] = data
func get_resource() -> GameResource:
return layer_info[Constants.TilemapLayerss.ENVIRONMENT] as GameResource
return layer_info[Constants.TilemapLayers.ENVIRONMENT] as GameResource
func has_resource() -> bool:
return has_layer(Constants.TilemapLayers.ENVIRONMENT)

View File

@@ -7,6 +7,7 @@ signal gained_resource(res: GameResource)
@export var pickup_value: int
@export var name: String
@export var spawn_patterns: Array[SpawnPattern]
@export var storage_max: int
func _to_string() -> String:
return name

View File

@@ -21,7 +21,6 @@ func _on_resource_manager_changed_resource(changed: ResourceChangedSignal) -> vo
resource_container.add_child(img)
var label := Label.new()
label.text = str(changed.changed_resources[resource])
resource_container.add_child(label)
var data := ResourceData.new()
@@ -29,10 +28,12 @@ func _on_resource_manager_changed_resource(changed: ResourceChangedSignal) -> vo
data.label = label
data.value = changed.changed_resources[resource]
_resource_displays[resource] = data
label.text = "%s / %s" % [data.value, resource.storage_max]
else:
var data: ResourceData = _resource_displays[resource]
data.value += changed.changed_resources[resource]
data.label.text = str(data.value)
data.label.text = "%s / %s" % [data.value, resource.storage_max]
class ResourceData:
var image: TextureRect