23 lines
774 B
GDScript
23 lines
774 B
GDScript
class_name ActionEdges
|
|
extends RefCounted
|
|
## Per-tick "just pressed" for input actions. A press counts once, either from its input event
|
|
## (note(), so a tap between two ticks still registers) or from the action turning pressed since
|
|
## the previous poll (which also covers simulated input). Poll every action once per tick.
|
|
|
|
var _held := {}
|
|
var _requested := {}
|
|
|
|
|
|
func note(event: InputEvent, actions: Array) -> void:
|
|
for a in actions:
|
|
if event.is_action_pressed(a, false):
|
|
_requested[a] = true
|
|
|
|
|
|
func pressed(action: StringName) -> bool:
|
|
var held := Input.is_action_pressed(action)
|
|
var was: bool = _held.get(action, false)
|
|
_held[action] = held
|
|
var requested: bool = _requested.get(action, false)
|
|
_requested.erase(action)
|
|
return requested or (held and not was)
|