From 2ca7fe9d406475cf82b1aaad678ce9b6f5eca2c7 Mon Sep 17 00:00:00 2001 From: Ategon Date: Fri, 13 Sep 2024 21:31:14 -0400 Subject: [PATCH] Clean up counter script --- ui/UI.tscn | 10 +++++----- ui/counters.gd | 45 +++++++-------------------------------------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/ui/UI.tscn b/ui/UI.tscn index c25943c..3bd9e77 100644 --- a/ui/UI.tscn +++ b/ui/UI.tscn @@ -57,7 +57,6 @@ texture = ExtResource("4_7fjj4") expand_mode = 2 [node name="StoneCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"] -unique_name_in_owner = true layout_mode = 2 offset_right = 55.0 offset_bottom = 24.0 @@ -66,9 +65,9 @@ text = "000" horizontal_alignment = 2 vertical_alignment = 1 script = ExtResource("2_ei01o") +key = "stone" [node name="WoodCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"] -unique_name_in_owner = true layout_mode = 2 offset_left = 55.0 offset_right = 110.0 @@ -78,9 +77,9 @@ text = "000" horizontal_alignment = 2 vertical_alignment = 1 script = ExtResource("2_ei01o") +key = "wood" [node name="EssenceCountLabel" type="Label" parent="HBoxContainer/LeftCounters/Resources/Background"] -unique_name_in_owner = true layout_mode = 2 offset_left = 110.0 offset_right = 165.0 @@ -90,6 +89,7 @@ text = "000" horizontal_alignment = 2 vertical_alignment = 1 script = ExtResource("2_ei01o") +key = "essence" [node name="RightCounters" type="VBoxContainer" parent="HBoxContainer"] layout_direction = 2 @@ -119,7 +119,6 @@ offset_bottom = 24.0 expand_mode = 2 [node name="PopulationCountLabel" type="Label" parent="HBoxContainer/RightCounters/RightCounters/Background"] -unique_name_in_owner = true layout_mode = 2 offset_right = 55.0 offset_bottom = 24.0 @@ -128,9 +127,9 @@ text = "000" horizontal_alignment = 2 vertical_alignment = 1 script = ExtResource("2_ei01o") +key = "population" [node name="FloodLevelCountLabel" type="Label" parent="HBoxContainer/RightCounters/RightCounters/Background"] -unique_name_in_owner = true layout_mode = 2 offset_left = 55.0 offset_right = 110.0 @@ -140,3 +139,4 @@ text = "000" horizontal_alignment = 2 vertical_alignment = 1 script = ExtResource("2_ei01o") +key = "flood_level" diff --git a/ui/counters.gd b/ui/counters.gd index c1942fa..df24e67 100644 --- a/ui/counters.gd +++ b/ui/counters.gd @@ -1,42 +1,11 @@ extends Label -@onready var stone_count_label: Label = %StoneCountLabel -@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 +@export var key: String -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - var stone_count = 1 - var wood_count = 2 - var essence_count = 3 - var population_count = 4 - 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)) - +func _ready() -> void: + Triggerer.listen(key, _on_value_change) + + +func _on_value_change(data): + text = data.value