get the group to which the clicked token belongs

This commit is contained in:
Jack Case
2025-08-21 21:27:40 -04:00
parent 0a8890acf5
commit ffb837132b
3 changed files with 20 additions and 8 deletions

View File

@@ -10,8 +10,8 @@ script = ExtResource("1_mn5vm")
offset = 60.0
[node name="Debug Label" type="Label" parent="Grid"]
offset_left = -245.0
offset_top = -134.0
offset_right = -16.0
offset_bottom = -51.0
offset_left = -372.0
offset_top = -206.0
offset_right = 729.0
offset_bottom = -123.0
autowrap_mode = 1

17
grid.gd
View File

@@ -18,17 +18,21 @@ func _ready():
for row in rows:
grid.append([])
for column in cols:
var token_node = token.instantiate()
var token_node: Token = token.instantiate()
add_child(token_node)
token_node.position = Vector2(offset*column, offset*row)
token_node.set_type(randi_range(0,3 ))
token_node.set_debug_label(str(row) + "," + str(column))
token_node.token_clicked.connect(_on_token_clicked.bind([row,column]))
grid[row].append(token_node)
calculate_token_groups()
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("activate"):
calculate_token_groups()
pass
func _on_token_clicked(token_coord):
print(str(token_coord) + ", " + str(get_group_of_token(token_coord)))
func populate_grid():
pass
@@ -80,3 +84,10 @@ func calculate_token_groups():
groups.append(new_group)
debug_label.text = str(groups)
func get_group_of_token(token_coord) -> Array:
for group in groups:
if token_coord in group:
return group
return []

View File

@@ -1,4 +1,5 @@
extends Node2D
class_name Token
signal token_clicked