Clean up counter script

This commit is contained in:
Ategon 2024-09-13 21:31:14 -04:00
parent d994deb90f
commit 2ca7fe9d40
2 changed files with 12 additions and 43 deletions

View file

@ -57,7 +57,6 @@ texture = ExtResource("4_7fjj4")
expand_mode = 2 expand_mode = 2
[node name="StoneCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"] [node name="StoneCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
offset_right = 55.0 offset_right = 55.0
offset_bottom = 24.0 offset_bottom = 24.0
@ -66,9 +65,9 @@ text = "000"
horizontal_alignment = 2 horizontal_alignment = 2
vertical_alignment = 1 vertical_alignment = 1
script = ExtResource("2_ei01o") script = ExtResource("2_ei01o")
key = "stone"
[node name="WoodCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"] [node name="WoodCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
offset_left = 55.0 offset_left = 55.0
offset_right = 110.0 offset_right = 110.0
@ -78,9 +77,9 @@ text = "000"
horizontal_alignment = 2 horizontal_alignment = 2
vertical_alignment = 1 vertical_alignment = 1
script = ExtResource("2_ei01o") script = ExtResource("2_ei01o")
key = "wood"
[node name="EssenceCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"] [node name="EssenceCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
offset_left = 110.0 offset_left = 110.0
offset_right = 165.0 offset_right = 165.0
@ -90,6 +89,7 @@ text = "000"
horizontal_alignment = 2 horizontal_alignment = 2
vertical_alignment = 1 vertical_alignment = 1
script = ExtResource("2_ei01o") script = ExtResource("2_ei01o")
key = "essence"
[node name="RightCounters" type="VBoxContainer" parent="HBoxContainer"] [node name="RightCounters" type="VBoxContainer" parent="HBoxContainer"]
layout_direction = 2 layout_direction = 2
@ -119,7 +119,6 @@ offset_bottom = 24.0
expand_mode = 2 expand_mode = 2
[node name="PopulationCountLabel" type="Label" parent="HBoxContainer/RightCounters/RightCounters/Background"] [node name="PopulationCountLabel" type="Label" parent="HBoxContainer/RightCounters/RightCounters/Background"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
offset_right = 55.0 offset_right = 55.0
offset_bottom = 24.0 offset_bottom = 24.0
@ -128,9 +127,9 @@ text = "000"
horizontal_alignment = 2 horizontal_alignment = 2
vertical_alignment = 1 vertical_alignment = 1
script = ExtResource("2_ei01o") script = ExtResource("2_ei01o")
key = "population"
[node name="FloodLevelCountLabel" type="Label" parent="HBoxContainer/RightCounters/RightCounters/Background"] [node name="FloodLevelCountLabel" type="Label" parent="HBoxContainer/RightCounters/RightCounters/Background"]
unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
offset_left = 55.0 offset_left = 55.0
offset_right = 110.0 offset_right = 110.0
@ -140,3 +139,4 @@ text = "000"
horizontal_alignment = 2 horizontal_alignment = 2
vertical_alignment = 1 vertical_alignment = 1
script = ExtResource("2_ei01o") script = ExtResource("2_ei01o")
key = "flood_level"

View file

@ -1,42 +1,11 @@
extends Label extends Label
@onready var stone_count_label: Label = %StoneCountLabel @export var key: String
@onready var wood_count_label: Label = %WoodCountLabel
@onready var essence_count_label: Label = %EssenceCountLabel
@onready var population_count_label: Label = %PopulationCountLabel
@onready var flood_level_count_label: Label = %FloodLevelCountLabel
# Called every frame. 'delta' is the elapsed time since the previous frame. func _ready() -> void:
func _process(delta: float) -> void: Triggerer.listen(key, _on_value_change)
var stone_count = 1
var wood_count = 2
var essence_count = 3 func _on_value_change(data):
var population_count = 4 text = data.value
var flood_count = Persister.get_value("flood_level")
if stone_count:
stone_count_label.set_text(str(stone_count))
else:
stone_count_label.set_text(str(0))
if wood_count:
wood_count_label.set_text(str(wood_count))
else:
wood_count_label.set_text(str(0))
if essence_count:
essence_count_label.set_text(str(essence_count))
else:
essence_count_label.set_text(str(0))
if population_count:
population_count_label.set_text(str(population_count))
else:
population_count_label.set_text(str(0))
if flood_count:
flood_level_count_label.set_text(str(flood_count))
else:
flood_level_count_label.set_text(str(0))