Skip to content

Instantly share code, notes, and snippets.

@willnationsdev
Last active December 25, 2019 07:00
Show Gist options
  • Save willnationsdev/18d0e268dcc8257037015f4a67ed4b11 to your computer and use it in GitHub Desktop.
Save willnationsdev/18d0e268dcc8257037015f4a67ed4b11 to your computer and use it in GitHub Desktop.
A WIP GDScript port of the an XNA InputSequence: https://github.com/SimonDarksideJ/XNAGameStudio/wiki/Input-Sequence
# InputManager.gd
extends Node
export var wait_time := 0.5
export var merge_time := 0.1
var player_index := 0
var buffer := []
var _buf_timer: Timer = null
func _init(p_player_index: int, p_buf_size: int) -> void:
player_index = p_player_index
buffer.resize(p_buf_size)
_buf_timer = Timer.new()
add_child(_buf_timer)
_buf_timer.connect("timeout", self, "_on_buf_timer_timeout")
func _on_buf_timer_timeout() -> void:
buffer.clear()
func _unhandled_input(p_event: InputEvent) -> void:
if p_event.is_action("non_directional_button"):
var merge_input := true
if buffer.empty():
_buf_timer.start(wait_time)
merge_input = false
else:
merge_input |= _buf_timer.time_left > merge_time
# Move.gd
class_name Move
var name := ""
var sequence := []
var is_sub_move := false
func _init(p_name: String, p_sequence: Array) -> void:
name = p_name
sequence = p_sequence
# MoveList.gd
class_name MoveList
var _moves := []
func _init(p_moves: Array) -> void:
_moves = p_moves
_moves.sort_custom(self, "_sort")
static func _sort(a, b):
return a.sequence.size() > b.sequence.size()
func detect_move(p_input: InputEvent) -> Move:
for a_move in _moves:
if p_input.is_action(""):
return a_move
return null
func get_longest_move_length -> int:
return _moves[0].sequence.size() if _moves.size() else 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment