Class: Smagacor::Controller
Instance Attribute Summary collapse
-
#games ⇒ Object
readonly
Returns the value of attribute games.
-
#gamespath ⇒ Object
readonly
Returns the value of attribute gamespath.
Instance Method Summary collapse
- #get_file(file) ⇒ Object
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
- #load_games ⇒ Object
Constructor Details
#initialize ⇒ Controller
Returns a new instance of Controller.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/smagacor/controller.rb', line 94 def initialize @gamespath = [ File.join( ::Config::CONFIG["datadir"], "smagacor" ), 'data/smagacor' ] if defined? Gem::Cache gem = Gem::Cache.from_installed_gems.search( "smagacor", "=#{::Smagacor::VERSION.join('.')}" ).last @gamespath << File.join( gem.full_gem_path, "data", "smagacor" ) if gem end begin homepath = File.( '~' ) rescue homepath = ENV['USERPROFILE'] || ENV['HOMEDRIVE']+ENV['HOMEPATH'] end @gamespath.unshift File.join( homepath, '.smagacor' ) @games = [] end |
Instance Attribute Details
#games ⇒ Object (readonly)
Returns the value of attribute games.
92 93 94 |
# File 'lib/smagacor/controller.rb', line 92 def games @games end |
#gamespath ⇒ Object (readonly)
Returns the value of attribute gamespath.
91 92 93 |
# File 'lib/smagacor/controller.rb', line 91 def gamespath @gamespath end |
Instance Method Details
#get_file(file) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/smagacor/controller.rb', line 109 def get_file( file ) @gamespath.each do |path| name = File.join( path, file ) return name if File.exists?( name ) end end |
#load_games ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/smagacor/controller.rb', line 116 def load_games @games = [] @gamespath.each do |path| Dir[path + '/*/game.info'].each do |file| gi = YAML::load( File.open( file ) ) gi.directory = File.dirname( file ) @games.push gi end end end |