Skip to content

Commit 3ff00cf

Browse files
committed
fixed/added: gem counts work now
1 parent 52365ea commit 3ff00cf

File tree

5 files changed

+71
-24
lines changed

5 files changed

+71
-24
lines changed

enums.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ enum GemColor {
1313
WHITE,
1414
RED,
1515
YELLOW,
16-
BROWN,
1716
GREEN,
18-
PURPLE
17+
PURPLE,
18+
BROWN
1919
}
2020

2121
func get_color_name_by_value(value: int) -> String:

game.gd

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,26 @@ extends Node2D
66
func _ready():
77
game_board.connect("props_updated_moves", self._on_props_updated_moves)
88
game_board.connect("props_updated_score", self._on_props_updated_score)
9+
game_board.connect("props_updated_gemsdict", self._on_props_updated_gemsdict)
10+
11+
func _on_props_updated_gemsdict(gems_dict:Dictionary):
12+
# EX: `{ "WHITE": 9, "RED": 11, "YELLOW": 14, "BROWN": 9, "GREEN": 9, "PURPLE": 12 }`
13+
game_stats.get_child(0).get_child(1).text = str(gems_dict["WHITE"])
14+
game_stats.get_child(1).get_child(1).text = str(gems_dict["RED"])
15+
game_stats.get_child(2).get_child(1).text = str(gems_dict["YELLOW"])
16+
game_stats.get_child(3).get_child(1).text = str(gems_dict["GREEN"])
17+
game_stats.get_child(4).get_child(1).text = str(gems_dict["PURPLE"])
18+
game_stats.get_child(5).get_child(1).text = str(gems_dict["BROWN"])
919

1020
func _on_props_updated_moves(moves:int):
1121
# TODO: name labels, then update base on this
12-
game_stats.get_child(0).get_child(1).text = str(moves)
22+
#game_stats.get_child(4).get_child(1).text = str(moves)
23+
print("TODO:") # TODO:
1324

1425
func _on_props_updated_score(score:int):
1526
# TODO: name labels, then update base on this
16-
game_stats.get_child(1).get_child(1).text = str(score)
17-
game_stats.get_child(2).get_child(1).text = str(score)
27+
#game_stats.get_child(5).get_child(1).text = str(score)
28+
print("TODO:") # TODO:
1829

1930
func _on_newgame_button_pressed():
2031
game_board.new_game()

game.tscn

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ offset_bottom = 1207.0
5555
theme_override_styles/panel = SubResource("StyleBoxFlat_k3sk6")
5656

5757
[node name="GameStats" type="VBoxContainer" parent="."]
58-
offset_left = 100.0
59-
offset_top = 203.0
60-
offset_right = 425.0
61-
offset_bottom = 1227.0
58+
offset_left = 120.0
59+
offset_top = 205.0
60+
offset_right = 370.0
61+
offset_bottom = 1229.0
6262
theme_override_constants/separation = 40
6363

6464
[node name="HBoxContainer1" type="HBoxContainer" parent="GameStats"]
@@ -80,6 +80,8 @@ size_flags_horizontal = 3
8080
theme = ExtResource("4_xf0vf")
8181
theme_override_font_sizes/font_size = 96
8282
text = "0"
83+
horizontal_alignment = 2
84+
vertical_alignment = 1
8385

8486
[node name="HBoxContainer2" type="HBoxContainer" parent="GameStats"]
8587
layout_mode = 2
@@ -98,9 +100,10 @@ centered = false
98100
layout_mode = 2
99101
size_flags_horizontal = 3
100102
theme = ExtResource("4_xf0vf")
101-
theme_override_colors/font_color = Color(0.945098, 0.945098, 0.945098, 1)
102103
theme_override_font_sizes/font_size = 96
103104
text = "0"
105+
horizontal_alignment = 2
106+
vertical_alignment = 1
104107

105108
[node name="HBoxContainer3" type="HBoxContainer" parent="GameStats"]
106109
layout_mode = 2
@@ -122,6 +125,8 @@ theme = ExtResource("4_xf0vf")
122125
theme_override_colors/font_color = Color(0.945098, 0.945098, 0.945098, 1)
123126
theme_override_font_sizes/font_size = 96
124127
text = "0"
128+
horizontal_alignment = 2
129+
vertical_alignment = 1
125130

126131
[node name="HBoxContainer4" type="HBoxContainer" parent="GameStats"]
127132
layout_mode = 2
@@ -143,48 +148,54 @@ theme = ExtResource("4_xf0vf")
143148
theme_override_colors/font_color = Color(0.945098, 0.945098, 0.945098, 1)
144149
theme_override_font_sizes/font_size = 96
145150
text = "0"
151+
horizontal_alignment = 2
152+
vertical_alignment = 1
146153

147-
[node name="HBoxContainer5" type="HBoxContainer" parent="GameStats"]
154+
[node name="HBoxContainer6" type="HBoxContainer" parent="GameStats"]
148155
layout_mode = 2
149156
theme_override_constants/separation = 25
150157

151-
[node name="Control" type="Control" parent="GameStats/HBoxContainer5"]
158+
[node name="Control" type="Control" parent="GameStats/HBoxContainer6"]
152159
custom_minimum_size = Vector2(128, 128)
153160
layout_mode = 2
154161

155-
[node name="Sprite2D" type="Sprite2D" parent="GameStats/HBoxContainer5/Control"]
162+
[node name="Sprite2D" type="Sprite2D" parent="GameStats/HBoxContainer6/Control"]
156163
scale = Vector2(0.5, 0.5)
157-
texture = ExtResource("7_o4d3d")
164+
texture = ExtResource("6_ot4tf")
158165
centered = false
159166

160-
[node name="Label" type="Label" parent="GameStats/HBoxContainer5"]
167+
[node name="Label" type="Label" parent="GameStats/HBoxContainer6"]
161168
layout_mode = 2
162169
size_flags_horizontal = 3
163170
theme = ExtResource("4_xf0vf")
164171
theme_override_colors/font_color = Color(0.945098, 0.945098, 0.945098, 1)
165172
theme_override_font_sizes/font_size = 96
166173
text = "0"
174+
horizontal_alignment = 2
175+
vertical_alignment = 1
167176

168-
[node name="HBoxContainer6" type="HBoxContainer" parent="GameStats"]
177+
[node name="HBoxContainer5" type="HBoxContainer" parent="GameStats"]
169178
layout_mode = 2
170179
theme_override_constants/separation = 25
171180

172-
[node name="Control" type="Control" parent="GameStats/HBoxContainer6"]
181+
[node name="Control" type="Control" parent="GameStats/HBoxContainer5"]
173182
custom_minimum_size = Vector2(128, 128)
174183
layout_mode = 2
175184

176-
[node name="Sprite2D" type="Sprite2D" parent="GameStats/HBoxContainer6/Control"]
185+
[node name="Sprite2D" type="Sprite2D" parent="GameStats/HBoxContainer5/Control"]
177186
scale = Vector2(0.5, 0.5)
178-
texture = ExtResource("6_ot4tf")
187+
texture = ExtResource("7_o4d3d")
179188
centered = false
180189

181-
[node name="Label" type="Label" parent="GameStats/HBoxContainer6"]
190+
[node name="Label" type="Label" parent="GameStats/HBoxContainer5"]
182191
layout_mode = 2
183192
size_flags_horizontal = 3
184193
theme = ExtResource("4_xf0vf")
185194
theme_override_colors/font_color = Color(0.945098, 0.945098, 0.945098, 1)
186195
theme_override_font_sizes/font_size = 96
187196
text = "0"
197+
horizontal_alignment = 2
198+
vertical_alignment = 1
188199

189200
[node name="BoardTextRect" type="Panel" parent="."]
190201
visible = false

game_board/GameBoard.gd

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ class_name GameBoard
55
# SIGNALS
66
signal props_updated_moves(moves:int)
77
signal props_updated_score(score:int)
8+
signal props_updated_gemsdict(gems_dict:Dictionary)
89
# SCENES
910
@onready var grid_container:GridContainer = $GridContainer
1011
@onready var hbox_container:HBoxContainer = $HBoxContainer
1112
#VARS
12-
const GEM_COLOR_NAMES = [Enums.GemColor.WHITE, Enums.GemColor.RED, Enums.GemColor.YELLOW, Enums.GemColor.BROWN, Enums.GemColor.GREEN, Enums.GemColor.PURPLE]
13+
const GEM_COLOR_NAMES = [Enums.GemColor.WHITE, Enums.GemColor.RED, Enums.GemColor.YELLOW, Enums.GemColor.GREEN, Enums.GemColor.PURPLE, Enums.GemColor.BROWN]
1314
var selected_cell_1:GemCell = null
1415
var selected_cell_2:GemCell = null
1516
var undo_cell_1:GemCell = null
@@ -285,7 +286,11 @@ func check_board_explode_matches():
285286
debug_print_ascii_table(gem_matches)
286287
if gem_matches.size() == 0:
287288
Enums.debug_print("[check_board_explode_matches]: No more matches. Board stable.", Enums.DEBUG_LEVEL.INFO)
288-
# Reset undo cells or perform other cleanup here.
289+
# A:
290+
signal_game_props_count_gems()
291+
292+
# B: TODO: check for "NO MORE MOVES"
293+
# C: Reset undo cells or perform other cleanup here.
289294
if undo_cell_1 and undo_cell_2:
290295
swap_gem_cells(undo_cell_2, undo_cell_1)
291296
undo_cell_1 = null
@@ -357,6 +362,22 @@ func refill_column(column_index: int, highest_exploded_row: int, count_exploded:
357362
var debug_str3 = "[-------refill] ["+str(i)+"] ADD: " + Enums.get_color_name_by_value(random_color)
358363
Enums.debug_print(debug_str3, Enums.DEBUG_LEVEL.DEBUG)
359364

365+
func signal_game_props_count_gems():
366+
var gems_dict = {}
367+
# Initialize dictionary with all gem types set to 0
368+
for color in Enums.GemColor.values():
369+
gems_dict[Enums.get_color_name_by_value(color)] = 0
370+
371+
# Assuming you have a way to iterate over all gem nodes
372+
# For example, if all gems are children of a node called "GemsContainer"
373+
for col in hbox_container.get_children():
374+
for gem in col.get_children():
375+
var color_name = Enums.get_color_name_by_value(gem.gem_color)
376+
gems_dict[color_name] += 1
377+
378+
# Emit signal with the updated gems dictionary
379+
emit_signal("props_updated_gemsdict", gems_dict)
380+
360381
# DEBUG =======================================================================
361382

362383
func debug_print_column_ascii(column: VBoxContainer, column_index: int):

game_stats_label_theme.tres

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44

55
[resource]
66
default_font = ExtResource("1_mun42")
7-
default_font_size = 96
8-
Label/colors/font_color = Color(0.901961, 0.901961, 0.901961, 1)
7+
Label/colors/font_color = Color(0.945098, 0.945098, 0.945098, 1)
8+
Label/colors/font_outline_color = Color(0, 0, 0, 0.411765)
9+
Label/colors/font_shadow_color = Color(0, 0, 0, 0.411765)
10+
Label/constants/shadow_offset_x = 3
11+
Label/constants/shadow_offset_y = 3
12+
Label/font_sizes/font_size = 84

0 commit comments

Comments
 (0)