Add logic to right-click delete tiles

This commit is contained in:
kayomn 2023-01-28 00:13:49 +00:00
parent 300f1db0d5
commit a9f7437d01
3 changed files with 32 additions and 13 deletions

BIN
local_player.scn (Stored with Git LFS)

Binary file not shown.

BIN
map_editor.scn (Stored with Git LFS)

Binary file not shown.

View File

@ -1,5 +1,14 @@
class_name PlayerController extends Node3D class_name PlayerController extends Node3D
##
##
##
enum SelectAction {
NONE,
PRIMARY,
SECONDARY,
}
## ##
## Supported selection input devices. ## Supported selection input devices.
## ##
@ -54,7 +63,7 @@ var _cursor_point := Vector2.ZERO
var _is_drag_panning := false var _is_drag_panning := false
var _is_selecting := false var _select_action := SelectAction.NONE
var _select_mode := SelectMode.NONE var _select_mode := SelectMode.NONE
@ -77,12 +86,25 @@ func _input(event: InputEvent) -> void:
_is_drag_panning else Input.MOUSE_MODE_VISIBLE _is_drag_panning else Input.MOUSE_MODE_VISIBLE
MOUSE_BUTTON_LEFT: MOUSE_BUTTON_LEFT:
_is_selecting = event.is_pressed() if event.is_pressed():
_select_action = SelectAction.PRIMARY
if _is_selecting:
selection_started.emit() selection_started.emit()
else: else:
_select_action = SelectAction.NONE
selection_stopped.emit()
MOUSE_BUTTON_RIGHT:
if event.is_pressed():
_select_action = SelectAction.SECONDARY
selection_started.emit()
else:
_select_action = SelectAction.NONE
selection_stopped.emit() selection_stopped.emit()
return return
@ -173,14 +195,11 @@ func in_select_area() -> bool:
return _select_mode != SelectMode.NONE return _select_mode != SelectMode.NONE
## ##
## Returns [code]true[/code] if the player controller is currently selecting a location on the ## Returns the [code]SelectAction[/code] currently being performed, or
## screen, otherwise [code]false[/code]. ## [code]SelectAction.NONE[/code] if no action is currently being performed.
## ##
## *Note* that it is discouraged that this be continuously polled for single-fire events. Instead, func get_select_action() -> SelectAction:
## see [signal selection_started] and [signal selection_stopped]. return _select_action
##
func is_selecting() -> bool:
return _is_selecting
## ##
## ##