Skip to content

Commit

Permalink
Add better error prevention for mouses with 5+ buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
PunchablePlushie committed Jun 17, 2023
1 parent 9d8e294 commit 59ccbba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
13 changes: 0 additions & 13 deletions addons/ggs/classes/ggs_input_helper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@ func _get_kb_event_string(event: InputEventKey) -> String:

func _get_mouse_event_as_text(event: InputEventMouseButton) -> String:
var modifiers: String = _get_modifiers_string(event, true)

var btn_index: int = event.button_index - 1

if not _button_index_is_valid(event.button_index):
return "Unknown Mouse Button"

var btn: String = keywords["mouse"][event.button_index - 1].to_upper()
var result: String = "%s"%btn if modifiers.is_empty() else "%s+%s"%[modifiers, btn]
return result
Expand All @@ -210,10 +204,6 @@ func _create_mouse_event(modifiers: PackedStringArray, btn: String) -> InputEven

func _get_mouse_event_string(event: InputEventMouseButton) -> String:
var modifiers: String = _get_modifiers_string(event)

if not _button_index_is_valid(event.button_index):
return "unknown_mb"

var btn: String = keywords["mouse"][event.button_index - 1]
var result: String = "%s"%btn if modifiers.is_empty() else "%s,%s"%[modifiers, btn]

Expand All @@ -224,9 +214,6 @@ func _string_is_for_mouse(btn: String) -> bool:
return keywords["mouse"].has(btn)


func _button_index_is_valid(btn_index: int) -> bool:
return btn_index >= 0 and btn_index <= 9


### Gamepad

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,26 @@ func _event_is_valid(event: InputEvent) -> bool:
has_modifier = (event.shift_pressed or event.alt_pressed or event.ctrl_pressed)

var is_double_click: bool = false
var mouse_button_is_valid: bool = true
if event is InputEventMouseButton:
is_double_click = event.double_click
mouse_button_is_valid = (event.button_index >= 0 and event.button_index <= 9)

var is_valid: bool
if accept_modifiers:
is_valid = (
type_is_valid and
event.is_pressed() and
not event.is_echo() and
not is_double_click)
not is_double_click and
mouse_button_is_valid)
else:
is_valid = (
type_is_valid and
event.is_pressed() and
not event.is_echo() and
not is_double_click and
not is_double_click and
mouse_button_is_valid and
not has_modifier)

return is_valid
Expand Down

0 comments on commit 59ccbba

Please sign in to comment.