Module: Chingu::Helpers::InputDispatcher
Overview
Methods for parsing and dispatching Chingus input-maps Mixed into Chingu::Window and Chingu::GameState
Instance Attribute Summary collapse
-
#input_clients ⇒ Object
readonly
Returns the value of attribute input_clients.
Instance Method Summary collapse
-
#add_input_client(object) ⇒ Object
Called by input_clients to add themselves from forwarding.
-
#dispatch_button_down(id, object) ⇒ Object
Dispatch button press to one of your clients.
-
#dispatch_button_up(id, object) ⇒ Object
Dispatch button release to one of your clients.
-
#dispatch_input_for(object, prefix = "holding_") ⇒ Object
Dispatches input-mapper for any given object.
-
#remove_input_client(object) ⇒ Object
Called by input_clients to remove themselves from forwarding.
Instance Attribute Details
#input_clients ⇒ Object (readonly)
Returns the value of attribute input_clients
29 30 31 |
# File 'lib/chingu/helpers/input_dispatcher.rb', line 29 def input_clients @input_clients end |
Instance Method Details
#add_input_client(object) ⇒ Object
Called by input_clients to add themselves from forwarding.
32 33 34 |
# File 'lib/chingu/helpers/input_dispatcher.rb', line 32 def add_input_client(object) @input_clients << object unless @input_clients.include?(object) end |
#dispatch_button_down(id, object) ⇒ Object
Dispatch button press to one of your clients.
42 43 44 45 46 47 |
# File 'lib/chingu/helpers/input_dispatcher.rb', line 42 def (id, object) return unless Input::CONSTANT_TO_SYMBOL[id] if actions = object.input[Input::CONSTANT_TO_SYMBOL[id].first] dispatch_actions(actions) end end |
#dispatch_button_up(id, object) ⇒ Object
Dispatch button release to one of your clients.
50 51 52 53 54 55 |
# File 'lib/chingu/helpers/input_dispatcher.rb', line 50 def (id, object) return unless Input::CONSTANT_TO_SYMBOL[id] if actions = object.input[:"released_#{Input::CONSTANT_TO_SYMBOL[id].first}"] dispatch_actions(actions) end end |
#dispatch_input_for(object, prefix = "holding_") ⇒ Object
Dispatches input-mapper for any given object
60 61 62 63 64 65 66 67 |
# File 'lib/chingu/helpers/input_dispatcher.rb', line 60 def dispatch_input_for(object, prefix = "holding_") pattern = /^#{prefix}/ object.input.each do |symbol, actions| if symbol.to_s =~ pattern and $window.(Input::SYMBOL_TO_CONSTANT[$'.to_sym]) dispatch_actions(actions) end end end |
#remove_input_client(object) ⇒ Object
Called by input_clients to remove themselves from forwarding.
37 38 39 |
# File 'lib/chingu/helpers/input_dispatcher.rb', line 37 def remove_input_client(object) @input_clients.delete(object) end |