Module: Metro::GosuConstants
- Included in:
- Metro
- Defined in:
- lib/gosu_ext/gosu_constants.rb
Overview
The GosuEvents module creates aliases for the Keyboard and the Gamepad events within the Gosu Namespace. This is so Metro can use the events without requiring the namespace.
This makes the interface of these events more portable.
Class Method Summary collapse
-
.add(options = {}) ⇒ Object
Alias the list of given constants within the given class.
- .extended(base) ⇒ Object
- .find_all_constants_with_prefix(prefix) ⇒ Object
- .gamepad_events ⇒ Object
-
.gosu ⇒ Object
The constant from which to search for all the other constants.
- .keyboard_events ⇒ Object
- .mouse_events ⇒ Object
Class Method Details
.add(options = {}) ⇒ Object
Alias the list of given constants within the given class.
45 46 47 48 49 50 |
# File 'lib/gosu_ext/gosu_constants.rb', line 45 def self.add(={}) events = [:constants] target = [:to] events.each {|event| target.const_set event, gosu.const_get(event) } end |
.extended(base) ⇒ Object
12 13 14 15 16 |
# File 'lib/gosu_ext/gosu_constants.rb', line 12 def self.extended(base) add constants: keyboard_events, to: base add constants: gamepad_events, to: base add constants: mouse_events, to: base end |
.find_all_constants_with_prefix(prefix) ⇒ Object
38 39 40 |
# File 'lib/gosu_ext/gosu_constants.rb', line 38 def self.find_all_constants_with_prefix(prefix) gosu.constants.find_all { |c| c.to_s.start_with? prefix } end |
.gamepad_events ⇒ Object
30 31 32 |
# File 'lib/gosu_ext/gosu_constants.rb', line 30 def self.gamepad_events find_all_constants_with_prefix "Gp" end |
.gosu ⇒ Object
Returns the constant from which to search for all the other constants. This helper method is to to save sprinkling the constant value throughout the rest of the module.
22 23 24 |
# File 'lib/gosu_ext/gosu_constants.rb', line 22 def self.gosu Gosu end |
.keyboard_events ⇒ Object
26 27 28 |
# File 'lib/gosu_ext/gosu_constants.rb', line 26 def self.keyboard_events find_all_constants_with_prefix "Kb" end |
.mouse_events ⇒ Object
34 35 36 |
# File 'lib/gosu_ext/gosu_constants.rb', line 34 def self.mouse_events find_all_constants_with_prefix "Ms" end |