Class: Metro::Controls

Inherits:
Object
  • Object
show all
Defined in:
lib/metro/events/controls.rb

Overview

Assists in creating and the storing of ControlDefinitions.

See Also:

  • DSL

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *params, &block) ⇒ Object

Creation through controls is usually done with an instance_eval of a block and this allows for a flexible interface.

Parameters:

  • name (String, Symbol)

    the name or the alias of the control as it will be used within the course of the game.



18
19
20
21
# File 'lib/metro/events/controls.rb', line 18

def method_missing(name,*params,&block)
  options = params.find {|param| param.is_a? Hash }
  define_control(name,options)
end

Instance Method Details

#_event_args(options) ⇒ Object



34
35
36
# File 'lib/metro/events/controls.rb', line 34

def _event_args(options)
  options[:with]
end

#_event_type(options) ⇒ Object



30
31
32
# File 'lib/metro/events/controls.rb', line 30

def _event_type(options)
  options[:is]
end

#define_control(name, options) ⇒ Object



23
24
25
26
27
28
# File 'lib/metro/events/controls.rb', line 23

def define_control(name,options)
  event = _event_type(options)
  args = _event_args(options)

  defined_controls.push ControlDefinition.new name, event, args
end

#defined_controlsObject



38
39
40
# File 'lib/metro/events/controls.rb', line 38

def defined_controls
  @defined_controls ||= []
end