module Input

Usage: Input.trigger?(2) Input.trigger?(:DOWN) Input.trigger?(Input::KB_DOWN) Input.trigger?(Input::Key[Gosu::KB_DOWN])

Constants

KEY_MAPPER
KEY_TO_INT
KEY_TO_INT_PROC
Key

A wrapper for Gosu::KB_**** can be used as argument for methods in Input

REVERSE_KEY_MAPPER

Public Class Methods

dir4() click to toggle source
# File lib/rgss3/input.rb, line 123
def self.dir4
  @dir_4_8[0]
end
dir8() click to toggle source
# File lib/rgss3/input.rb, line 127
def self.dir8
  @dir_4_8[1]
end
press?(key) click to toggle source
# File lib/rgss3/input.rb, line 115
def self.press?(key)
  presstime?(key, &:positive?)
end
repeat?(key) click to toggle source
# File lib/rgss3/input.rb, line 119
def self.repeat?(key)
  presstime?(key) { |t| t == 1 || t > 23 && t % 6 == 0 }
end
trigger?(key) click to toggle source
# File lib/rgss3/input.rb, line 111
def self.trigger?(key)
  presstime?(key) { |t| t == 1 }
end
update() click to toggle source
# File lib/rgss3/input.rb, line 104
def self.update
  @states.each_key do |kb_key|
    @states[kb_key] = RGSS3.window.button_down?(kb_key) ? @states[kb_key] + 1 : 0
  end
  @dir_4_8 = calculate_dir_4_8
end

Private Class Methods

calculate_dir_4_8() click to toggle source
# File lib/rgss3/input.rb, line 141
def self.calculate_dir_4_8
  min_presstime = Float::INFINITY
  dir4 = 5
  dir8 = [2, 4, 6, 8].inject(5) do |dir, dir_checking|
    presstime = REVERSE_KEY_MAPPER[dir_checking].map(&@states).select(&:positive?).min
    if presstime
      if presstime < min_presstime
        dir4 = dir_checking
        presstime = min_presstime
      end
      dir + dir_checking - 5
    else
      dir
    end
  end
  return 0, 0 if dir8 == 5
  return dir8, dir8 if [2, 4, 6, 8].include?(dir8)
  return dir4, dir8
end
presstime?(arg) { |states| ... } click to toggle source
# File lib/rgss3/input.rb, line 133
def self.presstime?(arg)
  arg = KEY_TO_INT[arg] if arg.is_a?(Symbol)
  arg = REVERSE_KEY_MAPPER[arg] if arg.is_a?(Integer)
  arg = [arg.kb_key] if arg.is_a?(Key)
  return false unless arg
  arg.any? { |kb_key| yield @states[kb_key] }
end