diff --git a/project.godot b/project.godot index 39dd6b7..5d46001 100644 --- a/project.godot +++ b/project.godot @@ -50,6 +50,17 @@ plc_rotate_up={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null) ] } +plc_rotate_down={ +"deadzone": 1.0, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":16,"position":Vector2(239, 1),"global_position":Vector2(243, 38),"factor":1.0,"button_index":5,"canceled":false,"pressed":true,"double_click":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":82,"location":0,"echo":false,"script":null) +] +} +plc_remove_toggle={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null) +] +} [layer_names] diff --git a/scripts/grid_controller.gd b/scripts/grid_controller.gd index 15cb8b4..dc927d0 100644 --- a/scripts/grid_controller.gd +++ b/scripts/grid_controller.gd @@ -38,5 +38,12 @@ func get_at(point : Vector2) -> Structure: return null return structures[index] +func destroy_at(point : Vector2) -> void: + var index = building_zone.indexify_global_point(point) + if index == -1: + return + structures[index].queue_free() + structures[index] = null + func is_point_occupied(point : Vector2) -> bool: return get_at(point) != null diff --git a/scripts/placement_manager.gd b/scripts/placement_manager.gd index 4281d46..ebedeab 100644 --- a/scripts/placement_manager.gd +++ b/scripts/placement_manager.gd @@ -3,13 +3,31 @@ extends Node2D ## Currently held structure var held_construction : Structure var selected_prototype : Prototype +var delete_mode : bool = false func _ready() -> void: GuiEventBus.construction_selected.connect(on_construction_selected) func _input(event: InputEvent) -> void: - if held_construction == null: + + if event.is_action_pressed("plc_remove_toggle"): + delete_mode = not delete_mode + if held_construction: + held_construction.queue_free() + selected_prototype = null + + if event.is_action_pressed("plc_place") and delete_mode: + print(delete_mode) + var zone : PlacementZone = try_get_zone(global_position) + if zone != null and zone.grid_controller.is_point_occupied(global_position): + zone.grid_controller.destroy_at(global_position) + + if event.is_action_pressed("plc_cancel") and delete_mode: + delete_mode = false + + if held_construction == null or delete_mode: return + if event.is_action_pressed("plc_place"): var zone = try_get_zone(held_construction.global_position) if zone != null and held_construction.try_place(zone): @@ -17,15 +35,22 @@ func _input(event: InputEvent) -> void: held_construction = selected_prototype.scene.instantiate() add_child(held_construction) held_construction.set_facing(facing) + if event.is_action_pressed("plc_rotate_up"): if held_construction != null: held_construction.cycle_up_facing() - + + if event.is_action_pressed("plc_rotate_down"): + if held_construction != null: + held_construction.cycle_down_facing() + if event.is_action_pressed("plc_cancel"): held_construction.queue_free() selected_prototype = null func on_construction_selected(constructible : Prototype): + if delete_mode: + return if held_construction: held_construction.queue_free() held_construction = constructible.scene.instantiate() @@ -34,9 +59,10 @@ func on_construction_selected(constructible : Prototype): func _process(_delta: float) -> void: - if held_construction == null: - return var mouse_pos = get_global_mouse_position() + if held_construction == null: + global_position = mouse_pos + return var zone = try_get_zone(mouse_pos) if zone and held_construction.can_be_placed(zone): global_position = zone.get_placement_position(mouse_pos)