Module: Lotu::Resourceful
- Defined in:
- lib/lotu/behaviors/resourceful.rb
Class Method Summary collapse
Instance Method Summary collapse
- #image(name) ⇒ Object
- #init_behavior ⇒ Object
- #load_images(path) ⇒ Object
- #load_resources(container, regexp, path, klass) ⇒ Object
- #load_songs(path) ⇒ Object
- #load_sounds(path) ⇒ Object
- #song(name) ⇒ Object
- #sound(name) ⇒ Object
- #with_path(path, &blk) ⇒ Object
Class Method Details
.extended(instance) ⇒ Object
5 6 7 |
# File 'lib/lotu/behaviors/resourceful.rb', line 5 def self.extended(instance) instance.init_behavior end |
Instance Method Details
#image(name) ⇒ Object
15 16 17 |
# File 'lib/lotu/behaviors/resourceful.rb', line 15 def image(name) @images[name] end |
#init_behavior ⇒ Object
9 10 11 12 13 |
# File 'lib/lotu/behaviors/resourceful.rb', line 9 def init_behavior @images = {} @sounds = {} @songs = {} end |
#load_images(path) ⇒ Object
27 28 29 |
# File 'lib/lotu/behaviors/resourceful.rb', line 27 def load_images(path) load_resources(@images, /\.png|\.jpg|\.bmp/, path, Gosu::Image) end |
#load_resources(container, regexp, path, klass) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lotu/behaviors/resourceful.rb', line 44 def load_resources(container, regexp, path, klass) path = File.(File.join(@path, path)) puts "Loading from: #{path}" count = 0 Dir.entries(path).grep(regexp).each do |entry| begin container[entry] = klass.new($window, File.join(path, entry)) count += 1 rescue Exception => e puts e, File.join(path, entry) end end puts "#{count} #{klass} files loaded." end |
#load_songs(path) ⇒ Object
35 36 37 |
# File 'lib/lotu/behaviors/resourceful.rb', line 35 def load_songs(path) load_resources(@songs, /\.ogg|\.mp3|\.wav/, path, Gosu::Song) end |
#load_sounds(path) ⇒ Object
31 32 33 |
# File 'lib/lotu/behaviors/resourceful.rb', line 31 def load_sounds(path) load_resources(@sounds, /\.ogg|\.mp3|\.wav/, path, Gosu::Sample) end |
#song(name) ⇒ Object
23 24 25 |
# File 'lib/lotu/behaviors/resourceful.rb', line 23 def song(name) @songs[name] end |
#sound(name) ⇒ Object
19 20 21 |
# File 'lib/lotu/behaviors/resourceful.rb', line 19 def sound(name) @sounds[name] end |
#with_path(path, &blk) ⇒ Object
39 40 41 42 |
# File 'lib/lotu/behaviors/resourceful.rb', line 39 def with_path(path, &blk) @path = File.(File.dirname path) yield end |