diff --git a/project.godot b/project.godot index 2d6855c..807f921 100644 --- a/project.godot +++ b/project.godot @@ -76,6 +76,11 @@ interact={ "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":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null) ] } +left_click_interact={ +"deadzone": 0.2, +"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":1,"position":Vector2(67, 28),"global_position":Vector2(76, 74),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} [layer_names] diff --git a/scenes/blocks/block.gd b/scenes/blocks/block.gd index 2a4c7f7..fda7c7a 100644 --- a/scenes/blocks/block.gd +++ b/scenes/blocks/block.gd @@ -15,6 +15,10 @@ var id: String var resource: BlockResource +func _exit_tree() -> void: + if Waila.ref.get_target() == self: + Waila.ref.release_target() + func _ready() -> void: _apply_materials() @@ -25,6 +29,10 @@ func get_id() -> String: func hook() -> void: highlight_mesh.visible = true +# TODO: Rename to something else (maybe remove()) +func interact_left_click() -> void: + queue_free() + func release() -> void: highlight_mesh.visible = false @@ -35,7 +43,7 @@ func set_id(block_id: String) -> void: ## Apply a specific material to a MeshInstance3D -## If material is null, the EastFace material will be used +## If material is null, the EastFace material from the BlockResource will be utilized func _apply_material(face: MeshInstance3D, material: StandardMaterial3D) -> void: if material == null: material = resource.material_east # Default to East face (first) diff --git a/scenes/player/ray_cast_3d.gd b/scenes/player/ray_cast_3d.gd index 9676607..e1cc76b 100644 --- a/scenes/player/ray_cast_3d.gd +++ b/scenes/player/ray_cast_3d.gd @@ -6,6 +6,9 @@ func _process(_delta: float) -> void: var collider: Object = get_collider() if collider is Block: + if Input.is_action_just_pressed("left_click_interact"): + collider.interact_left_click() + if Waila.ref.get_target() == collider: return if not Waila.ref.get_target(): diff --git a/scenes/ui/waila.gd b/scenes/ui/waila.gd index d83348b..e85dfb8 100644 --- a/scenes/ui/waila.gd +++ b/scenes/ui/waila.gd @@ -37,6 +37,7 @@ func hook_target(id: String) -> void: ## Not looking at anything, hide Waila func release_target() -> void: visible = false + set_target(null) func set_target(target_block: Block) -> void: _target = target_block