Add building costs

This commit is contained in:
Ategon 2024-09-15 00:22:02 -04:00
parent e14a0ee010
commit f75456cfde
14 changed files with 53 additions and 6 deletions

View file

@ -105,6 +105,13 @@ func place_building():
"key": Persister.get_value("building_key"),
}
var cost = Data.data.buildings[Persister.get_value("building_key")].cost
if cost.has("wood"):
Persister.change_value("wood", -int(cost.wood))
if cost.has("stone"):
Persister.change_value("stone", -int(cost.stone))
Persister.persist_data("drag_mode", false)

View file

@ -465,9 +465,8 @@ key = "essence"
[node name="Control" type="Control" parent="CanvasLayer/UI/Background"]
anchors_preset = 0
offset_top = -28.0
offset_right = 40.0
offset_bottom = 12.0
offset_bottom = 40.0
[node name="WoodIcon" type="TextureRect" parent="CanvasLayer/UI/Background/Control"]
layout_mode = 0
@ -495,9 +494,8 @@ key = "wood"
[node name="Control3" type="Control" parent="CanvasLayer/UI/Background"]
anchors_preset = 0
offset_left = 41.0
offset_top = -28.0
offset_right = 81.0
offset_bottom = 12.0
offset_bottom = 40.0
[node name="WoodIcon" type="TextureRect" parent="CanvasLayer/UI/Background/Control3"]
layout_mode = 0
@ -523,9 +521,8 @@ script = ExtResource("16_knn3d")
[node name="Control2" type="Control" parent="CanvasLayer/UI/Background"]
anchors_preset = 0
offset_top = -28.0
offset_right = 40.0
offset_bottom = 12.0
offset_bottom = 40.0
[node name="StoneIcon" type="TextureRect" parent="CanvasLayer/UI/Background/Control2"]
layout_mode = 0

View file

@ -4,3 +4,6 @@ resource: essence
amount: 1
time: 10
max_workers: 6
cost[]
stone: 3
wood: 2

View file

@ -1,2 +1,4 @@
name: Field
type: utility
cost[]
wood: 2

View file

@ -1,2 +1,5 @@
name: Farmhouse
type: utility
cost[]
wood: 4
stone: 8

View file

@ -1,3 +1,6 @@
name: House
type: housing
amount: 5
cost[]
wood: 18
stone: 10

View file

@ -1,3 +1,6 @@
name: Quarter
type: housing
amount: 3
cost[]
wood: 12
stone: 7

View file

@ -4,3 +4,5 @@ resource: stone
amount: 1
time: 10
max_workers: 6
cost[]
stone: 2

View file

@ -1,3 +1,6 @@
name: Tent
type: housing
amount: 1
cost[]
wood: 6
stone: 4

View file

@ -1,2 +1,5 @@
name: Water Processor
type: utility
cost[]
wood: 6
stone: 10

View file

@ -1,2 +1,4 @@
name: Water Pump
type: utility
cost[]
stone: 3

View file

@ -4,3 +4,5 @@ resource: wood
amount: 1
time: 10
max_workers: 6
cost[]
stone: 3

View file

@ -132,6 +132,7 @@ func place_building():
Dic[str(tile)]["Key"] = building_key
Dic[str(tile)]["Placed"] = true
Drag_Mode = false

View file

@ -26,6 +26,8 @@ extends Control
func _ready() -> void:
swap_to_tab(0)
Triggerer.listen("stone", _trigger_check)
Triggerer.listen("wood", _trigger_check)
func swap_to_tab(index):
@ -51,6 +53,20 @@ func swap_to_tab(index):
if i > 0:
spacers[i - 1].visible = false
_update_icons()
func _trigger_check(_data):
_update_icons()
func _update_icons():
for i in range(0, icons.size()):
if icons[i].visible:
var key = icons[i].key
var build_data = Data.data.buildings[key]
if (build_data.cost.has("stone") and Persister.get_value("stone", PersisterEnums.Scope.UNKNOWN, 0) < int(build_data.cost.stone)) or (build_data.cost.has("wood") and Persister.get_value("wood", PersisterEnums.Scope.UNKNOWN, 0) < int(build_data.cost.wood)):
icons[i].modulate = Color(1, 0.5, 0.5, 0.5)
else:
icons[i].modulate = Color(1, 1, 1, 1)
func _on_building_tab_clicked() -> void:
swap_to_tab(0)