Make tilemap use mouse handler

This commit is contained in:
Ategon 2024-09-09 14:19:38 -04:00
parent 285479f89b
commit ab188c54e0
2 changed files with 12 additions and 11 deletions

View file

@ -27,6 +27,7 @@ sources/0 = SubResource("TileSetAtlasSource_dxrqb")
sources/1 = SubResource("TileSetAtlasSource_j7eew")
[sub_resource type="CircleShape2D" id="CircleShape2D_s8q4l"]
radius = 134.7
[node name="Main" type="Node2D"]
@ -45,6 +46,7 @@ layer_1/name = "Layer1"
script = ExtResource("5_v47eg")
[node name="MouseHandler" parent="TileMap" instance=ExtResource("5_6lpdu")]
position = Vector2(318, 178)
[node name="CollisionShape2D" type="CollisionShape2D" parent="TileMap/MouseHandler"]
shape = SubResource("CircleShape2D_s8q4l")

View file

@ -14,12 +14,8 @@ func _ready():
set_cell(0, Vector2(x, y), 0, Vector2i(0,0), 0)
func _process(delta):
if (Input.is_action_just_pressed("rclick")):
Building_Mode = !Building_Mode
for x in GridSize:
for y in GridSize:
if !Dic[str(Vector2(x,y))].get("Placed"):
erase_cell(1, Vector2(x,y))
#if (Input.is_action_just_pressed("rclick")):
if Building_Mode:
var tile = local_to_map(get_global_mouse_position())
@ -31,14 +27,17 @@ func _process(delta):
if Dic.has(str(tile)):
set_cell(1, tile, 1, Vector2i(0,0), 0)
if Input.is_action_just_pressed("lclick"):
Dic[str(tile)]["Placed"] = true
func _on_mouse_handler_clicked():
pass # Replace with function body.
if Building_Mode:
var tile = local_to_map(get_global_mouse_position())
Dic[str(tile)]["Placed"] = true
func _on_mouse_handler_rclicked():
pass # Replace with function body.
Building_Mode = !Building_Mode
for x in GridSize:
for y in GridSize:
if !Dic[str(Vector2(x,y))].get("Placed"):
erase_cell(1, Vector2(x,y))