diff --git a/Main.tscn b/Main.tscn index 77a4589..4e5397e 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=8 format=3 uid="uid://5ske2hm55rce"] +[gd_scene load_steps=10 format=3 uid="uid://5ske2hm55rce"] [ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_xbn5h"] [ext_resource type="Texture2D" uid="uid://bsrh0u02bckhy" path="res://iso_building.png" id="3_qa5pv"] [ext_resource type="Texture2D" uid="uid://bvn5lewpp7pmd" path="res://iso_tile.png" id="4_7pks7"] +[ext_resource type="PackedScene" uid="uid://dykc1mgg5uopw" path="res://components/Cursor/MouseHandler.tscn" id="5_6lpdu"] [ext_resource type="Script" path="res://tile_map.gd" id="5_v47eg"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_dxrqb"] @@ -25,6 +26,8 @@ tile_size = Vector2i(16, 8) sources/0 = SubResource("TileSetAtlasSource_dxrqb") sources/1 = SubResource("TileSetAtlasSource_j7eew") +[sub_resource type="CircleShape2D" id="CircleShape2D_s8q4l"] + [node name="Main" type="Node2D"] [node name="Control" type="Control" parent="."] @@ -41,4 +44,12 @@ format = 2 layer_1/name = "Layer1" script = ExtResource("5_v47eg") +[node name="MouseHandler" parent="TileMap" instance=ExtResource("5_6lpdu")] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="TileMap/MouseHandler"] +shape = SubResource("CircleShape2D_s8q4l") + [node name="Camera2D" type="Camera2D" parent="."] + +[connection signal="clicked" from="TileMap/MouseHandler" to="TileMap" method="_on_mouse_handler_clicked"] +[connection signal="rclicked" from="TileMap/MouseHandler" to="TileMap" method="_on_mouse_handler_rclicked"] diff --git a/tile_map.gd b/tile_map.gd index 663690d..480291a 100644 --- a/tile_map.gd +++ b/tile_map.gd @@ -2,29 +2,43 @@ extends TileMap var GridSize = 16 var Dic = {} -var placed = [] +var Building_Mode: bool = false func _ready(): for x in GridSize: for y in GridSize: Dic[str(Vector2(x,y))] = { - "Type": "Ground", - "Position": str(Vector2(x,y)), + #"Type": "Ground", "Placed": false } set_cell(0, Vector2(x, y), 0, Vector2i(0,0), 0) func _process(delta): - var tile = local_to_map(get_global_mouse_position()) + 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)) - for x in GridSize: - for y in GridSize: - if !Dic[str(Vector2(x,y))].get("Placed"): - erase_cell(1, Vector2(x,y)) - - if Dic.has(str(tile)): - set_cell(1, tile, 1, Vector2i(0,0), 0) - #print(Dic[str(tile)]) + if Building_Mode: + var tile = local_to_map(get_global_mouse_position()) - if Input.is_action_just_pressed("lclick"): - Dic[str(tile)]["Placed"] = true + for x in GridSize: + for y in GridSize: + if !Dic[str(Vector2(x,y))].get("Placed"): + erase_cell(1, Vector2(x,y)) + + 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. + + +func _on_mouse_handler_rclicked(): + pass # Replace with function body.