Class: Nimo::Resources

Inherits:
Object show all
Defined in:
lib/nimo/utils/resources.rb

Overview

Resource loader.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game_window) ⇒ Resources

Returns a new instance of Resources.



9
10
11
12
13
14
# File 'lib/nimo/utils/resources.rb', line 9

def initialize(game_window)
  @game_window = game_window
  @images = {}
  @fonts  = {}
  @sounds = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



28
29
30
31
# File 'lib/nimo/utils/resources.rb', line 28

def method_missing(meth, *args, &blk)
  super unless [:image, :sound, :font].include?(meth)
  validate_and_return_resource(meth, args.shift)
end

Instance Attribute Details

#fontsObject (readonly)

Returns the value of attribute fonts.



7
8
9
# File 'lib/nimo/utils/resources.rb', line 7

def fonts
  @fonts
end

#imagesObject (readonly)

Returns the value of attribute images.



7
8
9
# File 'lib/nimo/utils/resources.rb', line 7

def images
  @images
end

#soundsObject (readonly)

Returns the value of attribute sounds.



7
8
9
# File 'lib/nimo/utils/resources.rb', line 7

def sounds
  @sounds
end

Instance Method Details

#load_fonts(font_definitions) ⇒ Object



20
21
22
# File 'lib/nimo/utils/resources.rb', line 20

def load_fonts(font_definitions)
  font_definitions.each { |tag, definition| @fonts[tag] ||= Gosu::Font.new(@game_window, definition[:type], definition[:size]) }
end

#load_images(image_definitions) ⇒ Object



16
17
18
# File 'lib/nimo/utils/resources.rb', line 16

def load_images(image_definitions)
  image_definitions.each { |tag, definition| @images[tag] ||= create_image_from(definition) }
end

#load_sounds(sound_definitions) ⇒ Object



24
25
26
# File 'lib/nimo/utils/resources.rb', line 24

def load_sounds(sound_definitions)
  sound_definitions.each { |tag, definition| @sounds[tag] ||= Gosu::Song.new(@game_window, definition[:filename]) }
end