get the group to which the clicked token belongs
This commit is contained in:
@@ -10,8 +10,8 @@ script = ExtResource("1_mn5vm")
|
|||||||
offset = 60.0
|
offset = 60.0
|
||||||
|
|
||||||
[node name="Debug Label" type="Label" parent="Grid"]
|
[node name="Debug Label" type="Label" parent="Grid"]
|
||||||
offset_left = -245.0
|
offset_left = -372.0
|
||||||
offset_top = -134.0
|
offset_top = -206.0
|
||||||
offset_right = -16.0
|
offset_right = 729.0
|
||||||
offset_bottom = -51.0
|
offset_bottom = -123.0
|
||||||
autowrap_mode = 1
|
autowrap_mode = 1
|
||||||
|
|||||||
17
grid.gd
17
grid.gd
@@ -18,17 +18,21 @@ func _ready():
|
|||||||
for row in rows:
|
for row in rows:
|
||||||
grid.append([])
|
grid.append([])
|
||||||
for column in cols:
|
for column in cols:
|
||||||
var token_node = token.instantiate()
|
var token_node: Token = token.instantiate()
|
||||||
add_child(token_node)
|
add_child(token_node)
|
||||||
token_node.position = Vector2(offset*column, offset*row)
|
token_node.position = Vector2(offset*column, offset*row)
|
||||||
token_node.set_type(randi_range(0,3 ))
|
token_node.set_type(randi_range(0,3 ))
|
||||||
token_node.set_debug_label(str(row) + "," + str(column))
|
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)
|
grid[row].append(token_node)
|
||||||
|
|
||||||
|
calculate_token_groups()
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
if Input.is_action_just_pressed("activate"):
|
pass
|
||||||
calculate_token_groups()
|
|
||||||
|
func _on_token_clicked(token_coord):
|
||||||
|
print(str(token_coord) + ", " + str(get_group_of_token(token_coord)))
|
||||||
|
|
||||||
func populate_grid():
|
func populate_grid():
|
||||||
pass
|
pass
|
||||||
@@ -80,3 +84,10 @@ func calculate_token_groups():
|
|||||||
groups.append(new_group)
|
groups.append(new_group)
|
||||||
|
|
||||||
debug_label.text = str(groups)
|
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 []
|
||||||
|
|||||||
Reference in New Issue
Block a user