Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Add support for actions and other input types #16

Open
ketexon opened this issue Sep 3, 2021 · 0 comments
Open

[Feature request] Add support for actions and other input types #16

ketexon opened this issue Sep 3, 2021 · 0 comments

Comments

@ketexon
Copy link

ketexon commented Sep 3, 2021

Working with scancodes makes it much harder to have configurable input, so being able to use actions would be helpful.
InputEventKey provides the function (from the base class InputEvent) is_action(String action) that could be checked instead of checking solely the scancode.

Proposal

Exports

Export an enum to determine whether actions, scancodes, or both should be used to check input. If more input types are to be added, booleans for each type should replace this. Note also that instead of the break scancode being a private variable, it will be exported in this proposal, along with the action.

The keys for scrolling + accepting input text will also be added as exports.

enum INPUT_TYPES {
	ACTION,
	SCANCODE,
	ACTION_OR_SCANCODE,
}
export(INPUT_TYPES) var INPUT_TYPE = INPUT_TYPES.ACTION_OR_SCANCODE

export(int) var BREAK_SCANCODE = KEY_ENTER
export(String) var BREAK_ACTION = "ui_accept"

export(int) var UP_SCANCODE = KEY_UP
export(String) var UP_ACTION = "ui_up"

export(int) var DOWN_SCANCODE = KEY_DOWN
export(String) var DOWN_ACTION = "ui_down"

export(int) var ACCEPT_SCANCODE = KEY_ENTER
export(String) var ACCEPT_ACTION = "ui_accept"

Helper functions

Add a function to check if the event corresponds to the action/scancode while also taking into consideration the INPUT_TYPE selected.

2 helper functions will be added to more concisely check if the INPUT_TYPE includes action or scancode.

func _is_input_type_action() -> bool:
	return INPUT_TYPE == INPUT_TYPES.ACTION or INPUT_TYPE == INPUT_TYPES.ACTION_OR_SCANCODE

func _is_input_type_scancode() -> bool:
	return INPUT_TYPE == INPUT_TYPES.SCANCODE or INPUT_TYPE == INPUT_TYPES.ACTION_OR_SCANCODE

func _is_input_active(event: InputEventKey, scancode: int, action: String) -> bool:
	return event.pressed and (
		(_is_input_type_action() and event.is_action(action))
		or (_is_input_type_scancode() and event.scancode == scancode)
	)

_input Function

All instances of checking scancodes will be replaced by the helper function (except for backspace)

func _input(event):
	if(event is InputEventKey and event.pressed): 
		if(SCROLL_SKIPPED_LINES and (_is_input_active(event, UP_SCANCODE, UP_ACTION) or _is_input_active(event, DOWN_SCANCODE, DOWN_ACTION))): # User is just scrolling the text
			if(_is_input_active(event, UP_SCANCODE, UP_ACTION)):
				# ...
			else:
				# ...
		elif(_state == 1 and _on_break): # If its on a break
			if(_is_input_active(event, BREAK_SCANCODE, BREAK_ACTION)):
				# ...
		elif(_state == 2): # If its on the input state
			# ...
			if(event.scancode == KEY_BACKSPACE): # Delete last character
				# ...
			elif(_is_input_active(event, ACCEPT_SCANCODE, ACCEPT_ACTION)): # Finish input
				# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant