Class: Shattered::Input::Controls
- Defined in:
- lib/shattered_model/controls.rb
Overview
Handles parsing and mapping of controls
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
-
#active? ⇒ Boolean
returns true if the controls are on, false otherwise.
-
#initialize(file) ⇒ Controls
constructor
Constructor.
-
#off ⇒ Object
turns the controls off.
-
#on ⇒ Object
turns the controls on.
-
#parse ⇒ Object
parses the file and sets the action map.
-
#path ⇒ Object
getter for path, which is static.
-
#path=(newpath) ⇒ Object
setter for path, which is static.
Constructor Details
#initialize(file) ⇒ Controls
Constructor
11 12 13 |
# File 'lib/shattered_model/controls.rb', line 11 def initialize(file) @file = file end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
8 9 10 |
# File 'lib/shattered_model/controls.rb', line 8 def actions @actions end |
#file ⇒ Object
Returns the value of attribute file.
8 9 10 |
# File 'lib/shattered_model/controls.rb', line 8 def file @file end |
Instance Method Details
#active? ⇒ Boolean
returns true if the controls are on, false otherwise
50 51 52 |
# File 'lib/shattered_model/controls.rb', line 50 def active? @active ||= false end |
#off ⇒ Object
turns the controls off
61 62 63 |
# File 'lib/shattered_model/controls.rb', line 61 def off @active = false end |
#on ⇒ Object
turns the controls on
55 56 57 58 |
# File 'lib/shattered_model/controls.rb', line 55 def on parse if @actions.nil? @active = true end |
#parse ⇒ Object
parses the file and sets the action map
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/shattered_model/controls.rb', line 26 def parse fullpath = File.join(path, @file) fullpath+= ".controls" unless (File.exists? fullpath) || file.ends_with(".controls") file = File.open(fullpath, "r") @actions = {} file.readlines.each_with_index do |line, line_number| line = (line.split("#"))[0] #comments next if line.strip.length == 0 #blank lines action_details = line.split("=>").collect {|x| x.strip} if(action_details.length == 2) action, condition = action_details elsif(action_details.length > 2) raise ControlsParseError.new("Error loading '#{line}' in #{fullpath}:#{line_number+1}. Too many =>'s.") elsif(action_details.length < 2) raise ControlsParseError.new("Problem parsing '#{line}' in #{fullpath}:#{line_number+1}. Badly formed keymap.") end @actions[condition] = action end file.close end |
#path ⇒ Object
getter for path, which is static
21 22 23 |
# File 'lib/shattered_model/controls.rb', line 21 def path @@path ||= File.join(SHATTERED_ROOT,"config") end |
#path=(newpath) ⇒ Object
setter for path, which is static
16 17 18 |
# File 'lib/shattered_model/controls.rb', line 16 def path=(newpath) @@path = newpath end |