Class: Smagacor::Controller

Inherits:
Object show all
Defined in:
lib/smagacor/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeController

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.expand_path( '~' )
  rescue
    homepath = ENV['USERPROFILE'] || ENV['HOMEDRIVE']+ENV['HOMEPATH']
  end
  @gamespath.unshift File.join( homepath, '.smagacor' )
  @games = []
end

Instance Attribute Details

#gamesObject (readonly)

Returns the value of attribute games.



92
93
94
# File 'lib/smagacor/controller.rb', line 92

def games
  @games
end

#gamespathObject (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_gamesObject



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