Skip to content

Commit a9e38bf

Browse files
committed
WIP: timer works well
1 parent 849f8d3 commit a9e38bf

File tree

7 files changed

+90
-23
lines changed

7 files changed

+90
-23
lines changed

enums.gd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
extends Node
2-
2+
# APP
33
const APP_VER:String = "0.5.0"
44
const APP_BLD:String = "20240519"
5+
# GAME
56
const TWEEN_TIME:float = 0.25
67
const EXPLODE_DELAY:float = TWEEN_TIME*2.0
78
const SRPITE_POS:Vector2 = Vector2(64,64)
9+
const HINT_DELAY:int = 5
10+
# VARS
811
var current_debug_level = DEBUG_LEVEL.INFO # Global variable to set the current debug level
912

1013
# =========================================================

game_boards/all_common/cmn_gem_cell.tscn

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ tracks/0/keys = {
3535

3636
[sub_resource type="Animation" id="Animation_xv0ay"]
3737
resource_name = "highlight"
38-
length = 3.6
39-
loop_mode = 1
38+
length = 0.8
4039
step = 0.2
4140
tracks/0/type = "value"
4241
tracks/0/imported = false

game_boards/all_common/common.gd

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ func highlight_first_swap(hbox:HBoxContainer) -> void:
8989
highlight_gem2 = swap[1]
9090
highlight_gem1.highlight()
9191
highlight_gem2.highlight()
92-
# Optionally set a timer to remove highlight after a few seconds
93-
await delay_time(hbox, 3)
94-
_on_HighlightTimer_timeout()
95-
96-
func _on_HighlightTimer_timeout():
97-
if highlight_gem1 and highlight_gem2:
98-
highlight_gem1.unhighlight()
99-
highlight_gem2.unhighlight()
100-
# Reset highlight gems to null
101-
highlight_gem1 = null
102-
highlight_gem2 = null
10392

10493
func has_match_at(x, y, board):
10594
var color = board[x][y].gem_color

game_boards/board_space/board_space.gd

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ signal show_game_msg(msg:String)
99
# SCENES
1010
@onready var grid_container:GridContainer = $GridContainer
1111
@onready var hbox_container:HBoxContainer = $HBoxContainer
12-
#VARS
12+
@onready var inactivity_timer:Timer = $InactivityTimer
13+
@onready var cont_debug_label:Label = $"../../ContDebug/VBoxContainer/ContDebugLabel"
14+
@onready var cont_debug_value:Label = $"../../ContDebug/VBoxContainer/ContDebugValue"
15+
# PRELOAD
1316
var CmnFunc = preload("res://game_boards/all_common/common.gd").new()
1417
var CmnDbg = preload("res://game_boards/all_common/common_debug.gd").new()
18+
# CONST
1519
const GEM_COLOR_NAMES = [Enums.GemColor.RED, Enums.GemColor.ORG, Enums.GemColor.YLW, Enums.GemColor.GRN, Enums.GemColor.BLU, Enums.GemColor.PRP]
1620
const GEM_POINTS:int = 25
1721
const GEM_DICT:Enums.GemDict = Enums.GemDict.SPACE
22+
# VARS
1823
var selected_cell_1:CommonGemCell = null
1924
var selected_cell_2:CommonGemCell = null
2025
var undo_cell_1:CommonGemCell = null
@@ -27,14 +32,15 @@ var board_props_score:int = 0
2732
func _ready():
2833
# godot setup
2934
randomize()
35+
inactivity_timer.wait_time = Enums.HINT_DELAY # sync UI to logic
3036
# A: populate board
3137
const brd_sq0 = "res://game_boards/board_space/assets/board_square_0.tscn"
3238
const brd_sq1 = "res://game_boards/board_space/assets/board_square_1.tscn"
3339
CmnFunc.fill_grid(hbox_container, grid_container, brd_sq0, brd_sq1)
34-
# 20240520: WIP: moved below to "init_game"
35-
#CmnFunc.fill_hbox(hbox_container, GEM_DICT, self._on_cell_click)
36-
# B: check board after init
37-
#process_game_round()
40+
41+
func _process(delta):
42+
cont_debug_label.text = "TIMER left secs..."
43+
cont_debug_value.text = str(round(inactivity_timer.time_left))
3844

3945
# NOTE: iOS [Xcode] has no cells if "CmnFunc.fill_hbox()" is in the _ready() func above
4046
# So, instead of having [game_space.gd] flip `visible` flag on this scene, let's do both of these here to alleviate the issue
@@ -81,6 +87,10 @@ func _on_cell_click(gem_cell:CommonGemCell):
8187
Enums.debug_print("[_on_cell_click] gem_cell.......: "+JSON.stringify(CmnFunc.find_gem_indices(gem_cell)), Enums.DEBUG_LEVEL.INFO)
8288
Enums.debug_print("[_on_cell_click] ---------------------------------------------", Enums.DEBUG_LEVEL.INFO)
8389

90+
# A: Reset the inactivity_timer timer on any user input
91+
inactivity_timer.stop()
92+
inactivity_timer.start()
93+
8494
# Clear first, we'll set later
8595
if selected_cell_1:
8696
selected_cell_1.play_selected_anim(false)
@@ -214,8 +224,6 @@ func process_game_round():
214224
# B: TODO: check for "NO MORE MOVES"
215225
var brent = CmnFunc.check_for_possible_moves(hbox_container)
216226
print("CHECK FOR MOVES = ", str(brent))
217-
# C: TODO: highlight available moves after short delay
218-
CmnFunc.highlight_first_swap(hbox_container)
219227
# C: Reset undo cells or perform other cleanup here.
220228
if undo_cell_1 and undo_cell_2:
221229
swap_gem_cells(undo_cell_2, undo_cell_1)
@@ -329,3 +337,13 @@ func debug_make_gem_grid():
329337

330338
func debug_clear_debug_labels():
331339
CmnDbg.debug_clear_debug_labels(hbox_container)
340+
341+
func _on_inactivity_timer_timeout():
342+
# A: Deselect all (e.g.: maybe one gem was clicked on and is just pulsating on screen)
343+
# TODO: ^^^
344+
# B: Call the highlight function on timeout
345+
# WIP: highlight available moves after short delay
346+
#cont_debug_label.text += "- highlight_first_swap! \n"
347+
CmnFunc.highlight_first_swap(hbox_container)
348+
# C: Restart timer
349+
inactivity_timer.start()

game_boards/board_space/board_space.tscn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,9 @@ theme_override_constants/separation = 0
8484
custom_minimum_size = Vector2(128, 0)
8585
layout_mode = 2
8686
theme_override_constants/separation = 0
87+
88+
[node name="InactivityTimer" type="Timer" parent="."]
89+
wait_time = 10.0
90+
one_shot = true
91+
92+
[connection signal="timeout" from="InactivityTimer" to="." method="_on_inactivity_timer_timeout"]

game_boards/board_space/game_space.gd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
extends Node2D
2-
#
2+
# VARS
33
var CmnFunc = preload("res://game_boards/all_common/common.gd").new()
44
# SCENES
55
@onready var game_top_h_box:HBoxContainer = $ContTopBar/GameTopHBox
@@ -20,6 +20,8 @@ func _ready():
2020
# B:
2121
center_container.visible = false
2222

23+
# =========================================================
24+
2325
func _on_props_updated_gemsdict(gems_dict:Dictionary):
2426
# EX: `{ "RED": 9, "ORG": 11, "YLW": 14, "GRN": 9, "BLU": 9, "PRP": 12 }`
2527
game_stats.get_child(0).get_child(1).text = str(gems_dict["RED"])
@@ -61,5 +63,7 @@ func _on_btn_checkerboard():
6163
func _on_btn_debug_pressed():
6264
game_board.debug_clear_debug_labels()
6365

66+
# =========================================================
67+
6468
func init_game():
6569
game_board.init_game()

game_boards/board_space/game_space.tscn

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=32 format=3 uid="uid://bkaimvifjwkai"]
1+
[gd_scene load_steps=34 format=3 uid="uid://bkaimvifjwkai"]
22

33
[ext_resource type="Script" path="res://game_boards/board_space/game_space.gd" id="1_w6e46"]
44
[ext_resource type="Texture2D" uid="uid://cwhjcn0y744nv" path="res://assets/gems/background-space.png" id="3_f5frv"]
@@ -14,8 +14,10 @@
1414
[ext_resource type="Texture2D" uid="uid://cvlodafggu8vg" path="res://assets/gems/space/Space_B.png" id="12_rwo65"]
1515
[ext_resource type="Texture2D" uid="uid://cnx5i4dv14xma" path="res://assets/gems/space/Space_P.png" id="13_wc6j4"]
1616
[ext_resource type="PackedScene" uid="uid://b02gonq6mjgh8" path="res://game_boards/board_space/board_space.tscn" id="14_xjwh6"]
17+
[ext_resource type="FontFile" uid="uid://dlhwrp5jwkrll" path="res://assets/fonts/Acme-Regular.ttf" id="15_qcr5o"]
1718
[ext_resource type="Texture2D" uid="uid://27rcw10bp2xt" path="res://assets/gui/ButtonText_Large_Green_Round.png" id="15_qjgsg"]
1819
[ext_resource type="Texture2D" uid="uid://bebhmcgujnoxc" path="res://assets/gui/ButtonText_Large_GreyOutline_Round.png" id="16_20lur"]
20+
[ext_resource type="FontFile" uid="uid://bylgyjavx5yts" path="res://assets/fonts/Quicksand-Regular.ttf" id="16_donlk"]
1921
[ext_resource type="Texture2D" uid="uid://dcow071sb2a7i" path="res://assets/gui/ButtonText_Large_Orange_Round.png" id="17_oxovp"]
2022
[ext_resource type="Theme" uid="uid://duftrpb020ewi" path="res://themes/game_msg_btm.tres" id="18_jrjnv"]
2123
[ext_resource type="Texture2D" uid="uid://chrsqb6yhlqeq" path="res://assets/gui/ButtonText_Large_Blue_Round.png" id="18_y8cds"]
@@ -420,6 +422,52 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_103kv")
420422
[node name="GemBoard" parent="ContBoard" instance=ExtResource("14_xjwh6")]
421423
position = Vector2(500, 250)
422424

425+
[node name="ContDebug" type="Control" parent="."]
426+
layout_mode = 3
427+
anchors_preset = 0
428+
offset_left = 1642.0
429+
offset_top = 881.0
430+
offset_right = 1892.0
431+
offset_bottom = 1231.0
432+
433+
[node name="ContDebugBkgd" type="Panel" parent="ContDebug"]
434+
layout_mode = 1
435+
anchors_preset = 15
436+
anchor_right = 1.0
437+
anchor_bottom = 1.0
438+
grow_horizontal = 2
439+
grow_vertical = 2
440+
theme_override_styles/panel = SubResource("StyleBoxFlat_k3sk6")
441+
442+
[node name="VBoxContainer" type="VBoxContainer" parent="ContDebug"]
443+
layout_mode = 1
444+
anchors_preset = 15
445+
anchor_right = 1.0
446+
anchor_bottom = 1.0
447+
offset_left = 10.0
448+
offset_top = 10.0
449+
offset_right = -10.0
450+
offset_bottom = -10.0
451+
grow_horizontal = 2
452+
grow_vertical = 2
453+
454+
[node name="ContDebugLabel" type="Label" parent="ContDebug/VBoxContainer"]
455+
layout_mode = 2
456+
size_flags_vertical = 3
457+
theme_override_fonts/font = ExtResource("15_qcr5o")
458+
theme_override_font_sizes/font_size = 32
459+
text = "ContDebugLabel"
460+
vertical_alignment = 1
461+
text_overrun_behavior = 1
462+
463+
[node name="ContDebugValue" type="Label" parent="ContDebug/VBoxContainer"]
464+
layout_mode = 2
465+
theme_override_fonts/font = ExtResource("16_donlk")
466+
theme_override_font_sizes/font_size = 52
467+
text = "Cont
468+
Debug
469+
Value"
470+
423471
[node name="BtnNewGame" type="TextureButton" parent="."]
424472
offset_left = 1600.0
425473
offset_top = 250.0

0 commit comments

Comments
 (0)