#==============================================================================
# ** Custom Input Repeat Intervals for Directions
#------------------------------------------------------------------------------
# © 2023 KotatsuAkira
# Do not redistribute without this copyright notice intact.
#------------------------------------------------------------------------------
# Made for RPGVXAce. For compatibility with RPGXP/VX, try replacing the syms
# (e.g. ":DOWN") with constants (e.g. "DOWN") in directions and repeats list.
#==============================================================================
module Input
#--------------------------------------------------------------------------
# * Module Constants
#--------------------------------------------------------------------------
REPEAT_BASE = 12
REPEAT_INTERVAL = 3
REPEAT_INIT = REPEAT_INTERVAL - REPEAT_BASE
DIRECTIONS = [ :DOWN, :LEFT, :RIGHT, :UP ]
#--------------------------------------------------------------------------
# * Module Variables
#--------------------------------------------------------------------------
@@_repeats = { :DOWN => nil, :LEFT => nil, :RIGHT => nil, :UP => nil }
#--------------------------------------------------------------------------
# * Method Redirects
#--------------------------------------------------------------------------
class << self
alias_method(:__original_update__, :update) unless $@
alias_method(:__original_repeat__, :repeat?) unless $@
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def self.update
__original_update__
DIRECTIONS.each do |sk|
unless press?(sk)
@@_repeats[sk] = nil
next
end
@@_repeats[sk] ||= (trigger?(sk) ? REPEAT_INIT : 0) - 1
@@_repeats[sk] += 1
@@_repeats[sk] %= REPEAT_INTERVAL if @@_repeats[sk] > 0
end
end
#--------------------------------------------------------------------------
# * Check if Key repeats
#--------------------------------------------------------------------------
def self.repeat?(sk)
return __original_repeat__(sk) unless DIRECTIONS.include?(sk)
return @@_repeats[sk] == REPEAT_INIT || @@_repeats[sk] == 0
end
end