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

Shouldn't this only track events assigned to actions? #3

Open
madeleineostoja opened this issue Dec 31, 2023 · 0 comments
Open

Shouldn't this only track events assigned to actions? #3

madeleineostoja opened this issue Dec 31, 2023 · 0 comments

Comments

@madeleineostoja
Copy link

Just wondering, since the method signature is _is_action_press_buffered(action), shouldn't this script only care about events that are assigned to actions in the InputMap? And if so, couldn't you get rid of most of the conditional logic in the keycode checking etc? So it could all be simplified to a dictionary of action names?

Something like this

extends Node

const BUFFER_WINDOW: int = 150

var buffer: Dictionary = {}


func _input(event: InputEvent) -> void:
	var action: StringName = _get_event_action(event)

	if action:
		buffer[action] = Time.get_ticks_msec()


func is_action_pressed_buffered(action: StringName) -> bool:
	if buffer.has(action):
		return Time.get_ticks_msec() - buffer[action] <= BUFFER_WINDOW

	return false


func _get_event_action(event: InputEvent) -> StringName:
	var actions: Array[StringName] = InputMap.get_actions()
	var event_action: StringName

	actions.reverse()

	for action in actions:
		if !event_action && event.is_action(action):
			event_action = action

	return event_action
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