#==============================================================================
# ** Disabled Keys
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1
# 2007-05-15
# SDK Version 2.2
#------------------------------------------------------------------------------
# * Version History :
#
# Version 1 ---------------------------------------------------- (2007-05-15)
#------------------------------------------------------------------------------
# * Description :
#
# This script was designed to disable keys from being read as pressed. It
# works for any constant in the Input module. You may disable a key until
# it is re-enabled, or you can disable a key for a number of frames.
#------------------------------------------------------------------------------
# * Instructions :
#
# Place The Script Below the SDK and Above Main.
#------------------------------------------------------------------------------
# * Syntax :
#
# Input.disable_key(<constant>)
# Input.disable_key(<constant>, <frames>)
# - <constant> : Any constant defined as a key in the module Input
# - <frames> : Number of frames until key is re-enabled
#
# Input.enable_key(<constant>)
# - <constant> : Any constant defined as a key in the module Input
#==============================================================================
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Disabled Keys', 'SephirothSpawn', 1, '2007-05-15')
SDK.check_requirements(2.2)
#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Disabled Keys')
#==============================================================================
# ** Input
#==============================================================================
module Input
class << self
#------------------------------------------------------------------------
# * Disabled Keys
#------------------------------------------------------------------------
@disabled_keys = []
@disabled_timer = {}
#------------------------------------------------------------------------
# * Alias Listings
#------------------------------------------------------------------------
if @seph_disabledkeys_stack.nil?
alias_method :seph_disabledkeys_input_update, :update
alias_method :seph_disabledkeys_input_press?, :press?
alias_method :seph_disabledkeys_input_trigger?, :trigger?
alias_method :seph_disabledkeys_input_repeat?, :repeat?
alias_method :seph_disabledkeys_input_dir4, :dir4
alias_method :seph_disabledkeys_input_dir8, :dir8
@seph_disabledkeys_stack = true
end
#------------------------------------------------------------------------
# * Disable Key
#------------------------------------------------------------------------
def disable_key(constant, frames = nil)
# Add Key to Disabled List
@disabled_keys << constant unless @disabled_keys.include?(constant)
# Set Disabled Counter if non-nil
@disabled_timer[constant] = frames unless frames.nil?
end
#------------------------------------------------------------------------
# * Enable Key
#------------------------------------------------------------------------
def enable_key(constant)
# Remove Constant From List
@disabled_keys.delete(constant)
# Set Nil Timer
@disabled_timer[constant] = nil
end
#------------------------------------------------------------------------
# * Frame Update
#------------------------------------------------------------------------
def update
# Pass Through Timer List
@disabled_timer.each do |key, timer|
# Next if nil timer or key not-disabled
next if timer.nil? || !@disabled_keys.include?(key)
# If Greater than 0 Timer
if timer > 0
timer -= 1
next
end
# Enable Key
@disabled_keys.delete(key) if @disabled_keys.include?(key)
# Set Timer to Nil
@disabled_timer[key] = nil
end
# Original Update
seph_disabledkeys_input_update
end
#------------------------------------------------------------------------
# * Press? Test
#------------------------------------------------------------------------
def press?(constant)
return @disabled_keys.include?(constant) ?
false : seph_disabledkeys_input_press?(constant)
end
#------------------------------------------------------------------------
# * Trigger? Test
#------------------------------------------------------------------------
def trigger?(constant)
return @disabled_keys.include?(constant) ?
false : seph_disabledkeys_input_trigger?(constant)
end
#------------------------------------------------------------------------
# * Repeat? Test
#------------------------------------------------------------------------
def repeat?(constant)
return @disabled_keys.include?(constant) ?
false : seph_disabledkeys_input_repeat?(constant)
end
#------------------------------------------------------------------------
# * Dir4 Test
#------------------------------------------------------------------------
def dir4
# Gets Original Direction Test
dir = seph_disabledkeys_input_dir4
# Return 0 if Direction Disabled
if (dir == 2 && @disabled_keys.include?(DOWN)) ||
(dir == 4 && @disabled_keys.include?(LEFT)) ||
(dir == 6 && @disabled_keys.include?(RIGHT)) ||
(dir == 8 && @disabled_keys.include?(UP))
return 0
end
# Return Original Dir Test
return dir
end
#------------------------------------------------------------------------
# * Dir8 Test
#------------------------------------------------------------------------
def dir8
# Gets Original Direction Test
dir = seph_disabledkeys_input_dir8
# Return 0 if Direction Disabled
if (dir == 2 && @disabled_keys.include?(DOWN)) ||
(dir == 4 && @disabled_keys.include?(LEFT)) ||
(dir == 6 && @disabled_keys.include?(RIGHT)) ||
(dir == 8 && @disabled_keys.include?(UP)) ||
(dir == 1 && @disabled_keys.include?(DOWN) &&
@disabled_keys.include?(LEFT)) ||
(dir == 3 && @disabled_keys.include?(DOWN) &&
@disabled_keys.include?(RIGHT)) ||
(dir == 7 && @disabled_keys.include?(UP) &&
@disabled_keys.include?(LEFT)) ||
(dir == 9 && @disabled_keys.include?(UP) &&
@disabled_keys.include?(RIGHT)) ||
return 0
end
# Return Original Dir Test
return dir
end
end
end
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end