Class: Nimo::InputListener::KeyAction

Inherits:
Object
  • Object
show all
Defined in:
lib/nimo/listeners/input_listener.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, options) ⇒ KeyAction

Returns a new instance of KeyAction.



51
52
53
54
55
# File 'lib/nimo/listeners/input_listener.rb', line 51

def initialize(action, options)
  @action = action
  @options = {:repeatable => true}.merge(options)
  @pressed_since = nil
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



49
50
51
# File 'lib/nimo/listeners/input_listener.rb', line 49

def action
  @action
end

Instance Method Details

#should_execute?(is_button_down) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
# File 'lib/nimo/listeners/input_listener.rb', line 57

def should_execute?(is_button_down)
  should_execute = false
  if is_button_down
    should_execute = @pressed_since.nil? || @options[:repeatable]
    @pressed_since = Time.now if @pressed_since.nil?
  else
    @pressed_since = nil
  end
  return should_execute
end