Class: Conjuration::InputManager
- Inherits:
-
Object
- Object
- Conjuration::InputManager
- Defined in:
- lib/conjuration/managers/input_manager.rb
Constant Summary collapse
- LEFT_CLICK =
:left_click
- RIGHT_CLICK =
:right_click
- UP =
:up
- LEFT =
:left
- DOWN =
:down
- RIGHT =
:right
Instance Method Summary collapse
-
#action_map ⇒ Object
Returns a hash of actions mapped to key bindings.
- #button_down?(action) ⇒ Boolean
-
#input_map ⇒ Object
Returns a hash of key bindings mapped to actions.
- #map_button(key_id) ⇒ Object
Instance Method Details
#action_map ⇒ Object
Returns a hash of actions mapped to key bindings.
{ action => [key_id] }
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/conjuration/managers/input_manager.rb', line 24 def action_map @action_map ||= { LEFT_CLICK => [Gosu::MsLeft], RIGHT_CLICK => [Gosu::MsRight], UP => [Gosu::KbUp, Gosu::GpUp, Gosu::KB_W], LEFT => [Gosu::KbLeft, Gosu::GpLeft, Gosu::KB_A], DOWN => [Gosu::KbDown, Gosu::GpDown, Gosu::KB_S], RIGHT => [Gosu::KbRight, Gosu::GpRight, Gosu::KB_D] } end |
#button_down?(action) ⇒ Boolean
17 18 19 |
# File 'lib/conjuration/managers/input_manager.rb', line 17 def (action) action_map[action]&.any? { |key_id| Gosu.(key_id) } || false end |
#input_map ⇒ Object
Returns a hash of key bindings mapped to actions.
{ key_id => action }
39 40 41 42 43 44 45 |
# File 'lib/conjuration/managers/input_manager.rb', line 39 def input_map @input_map ||= action_map.each_with_object({}) do |(action, key_ids), hash| key_ids.each do |key_id| hash[key_id] = action end end end |
#map_button(key_id) ⇒ Object
13 14 15 |
# File 'lib/conjuration/managers/input_manager.rb', line 13 def (key_id) input_map[key_id] end |