module MiniGL::Res

def clear

Releases the memory used by all non-global resources.
def clear
  @imgs.clear
  @tilesets.clear
  @sounds.clear
  @songs.clear
  @fonts.clear
end

def font(id, size, global = true, ext = '.ttf')

other than ".ttf".
[ext] The extension of the file being loaded. Specify only if it is
when you call +clear+.
game execution is finished. If false, the font will be released
[global] Set to true if you want to keep the font in memory until the
approximately, to the height of the tallest character when drawn.
[size] The size of the font, in pixels. This will correspond,
+prefix+/+font_dir+.
specified the same way as in +img+, but the base directory is
[id] A string or symbol representing the path to the song. It must be
Parameters:

objects.
and used by MiniGL elements like buttons, text fields and TextHelper
Returns a Gosu::Font object. Fonts are needed to draw text
def font(id, size, global = true, ext = '.ttf')
  if global; a = @global_fonts; else; a = @fonts; end
  id_size = "#{id}_#{size}"
  return a[id_size] if a[id_size]
  s = @prefix + @font_dir + id.to_s.split(@separator).join('/') + ext
  font = Gosu::Font.new G.window, s, size
  a[id_size] = font
end

def font_dir=(value)

Sets the path to font files (under +prefix+). Default is 'font'.
def font_dir=(value)
  value += '/' if value != '' and value[-1] != '/'
  @font_dir = value
end

def img(id, global = false, tileable = false, ext = '.png')

other than '.png'.
[ext] The extension of the file being loaded. Specify only if it is
continuous composition.
will be drawn repeated times, side by side, forming a
proper for images that will be used as a tile, i.e., that
[tileable] Whether the image should be loaded in tileable mode, which is
released when you call +clear+.
game execution is finished. If false, the image will be
[global] Set to true if you want to keep the image in memory until the
+img_dir+ and +separator+, provide +:sprite_1+ or "sprite_1".
to load 'data/img/sprite/1.png', with the default values of +prefix+,
prefixed by each subdirectory name followed by +separator+. Example:
inside a subdirectory of +prefix+/+img_dir+, the id must be
is inside +prefix+/+img_dir+, only the file name is needed. If it's
[id] A string or symbol representing the path to the image. If the file
Parameters:

Returns a Gosu::Image object.
def img(id, global = false, tileable = false, ext = '.png')
  if global; a = @global_imgs; else; a = @imgs; end
  return a[id] if a[id]
  s = @prefix + @img_dir + id.to_s.split(@separator).join('/') + ext
  img = Gosu::Image.new G.window, s, tileable
  a[id] = img
end

def img_dir=(value)

Sets the path to image files (under +prefix+). Default is 'img'.
def img_dir=(value)
  value += '/' if value != '' and value[-1] != '/'
  @img_dir = value
end

def imgs(id, sprite_cols, sprite_rows, global = false, ext = '.png')

other than ".png".
[ext] The extension of the file being loaded. Specify only if it is
released when you call +clear+.
game execution is finished. If false, the image will be
[global] Set to true if you want to keep the image in memory until the
[sprite_rows] Number of rows in the spritesheet.
[sprite_cols] Number of columns in the spritesheet.
for details.
[id] A string or symbol representing the path to the image. See +img+
Parameters:

to bottom.
the following indices raise first from left to right and then from top
a spritesheet. The image with index 0 will be the top left sprite, and
Returns an array of Gosu::Image objects, using the image as
def imgs(id, sprite_cols, sprite_rows, global = false, ext = '.png')
  if global; a = @global_imgs; else; a = @imgs; end
  return a[id] if a[id]
  s = @prefix + @img_dir + id.to_s.split(@separator).join('/') + ext
  imgs = Gosu::Image.load_tiles G.window, s, -sprite_cols, -sprite_rows, false
  a[id] = imgs
end

def initialize

explicitly.
This is called by GameWindow.initialize. Don't call it
def initialize
  @imgs = {}
  @global_imgs = {}
  @tilesets = {}
  @global_tilesets = {}
  @sounds = {}
  @global_sounds = {}
  @songs = {}
  @global_songs = {}
  @fonts = {}
  @global_fonts = {}
  @prefix = File.expand_path(File.dirname($0)) + '/data/'
  @img_dir = 'img/'
  @tileset_dir = 'tileset/'
  @sound_dir = 'sound/'
  @song_dir = 'song/'
  @font_dir = 'font/'
  @separator = '_'
end

def prefix=(value)

'img', 'sound', 'song', etc. folders are located.
directory of the game script. The prefix is the directory under which
Set a custom prefix for loading resources. By default, the prefix is the
def prefix=(value)
  value += '/' if value != '' and value[-1] != '/'
  @prefix = value
end

def song(id, global = false, ext = '.ogg')

other than ".ogg".
[ext] The extension of the file being loaded. Specify only if it is
when you call +clear+.
game execution is finished. If false, the song will be released
[global] Set to true if you want to keep the song in memory until the
+prefix+/+song_dir+.
specified the same way as in +img+, but the base directory is
[id] A string or symbol representing the path to the song. It must be
Parameters:

background musics of your game.
Returns a Gosu::Song object. This should be used for the
def song(id, global = false, ext = '.ogg')
  if global; a = @global_songs; else; a = @songs; end
  return a[id] if a[id]
  s = @prefix + @song_dir + id.to_s.split(@separator).join('/') + ext
  song = Gosu::Song.new G.window, s
  a[id] = song
end

def song_dir=(value)

Sets the path to song files (under +prefix+). Default is 'song'.
def song_dir=(value)
  value += '/' if value != '' and value[-1] != '/'
  @song_dir = value
end

def sound(id, global = false, ext = '.wav')

other than ".wav".
[ext] The extension of the file being loaded. Specify only if it is
released when you call +clear+.
game execution is finished. If false, the sound will be
[global] Set to true if you want to keep the sound in memory until the
+prefix+/+sound_dir+.
specified the same way as in +img+, but the base directory is
[id] A string or symbol representing the path to the sound. It must be
Parameters:

simple and short sound effects.
Returns a Gosu::Sample object. This should be used for
def sound(id, global = false, ext = '.wav')
  if global; a = @global_sounds; else; a = @sounds; end
  return a[id] if a[id]
  s = @prefix + @sound_dir + id.to_s.split(@separator).join('/') + ext
  sound = Gosu::Sample.new G.window, s
  a[id] = sound
end

def sound_dir=(value)

Sets the path to sound files (under +prefix+). Default is 'sound'.
def sound_dir=(value)
  value += '/' if value != '' and value[-1] != '/'
  @sound_dir = value
end

def tileset(id, tile_width = 32, tile_height = 32, global = false, ext = '.png')

other than ".png".
[ext] The extension of the file being loaded. Specify only if it is
released when you call +clear+.
game execution is finished. If false, the image will be
[global] Set to true if you want to keep the image in memory until the
[tile_height] Height of each tile, in pixels.
[tile_width] Width of each tile, in pixels.
+prefix+/+tileset_dir+.
specified the same way as in +img+, but the base directory is
[id] A string or symbol representing the path to the image. It must be
Parameters:

be loaded as tileable.
size instead of the number of columns and rows, and that the images will
a tileset. Works the same as +imgs+, except you must provide the tile
Returns an array of Gosu::Image objects, using the image as
def tileset(id, tile_width = 32, tile_height = 32, global = false, ext = '.png')
  if global; a = @global_tilesets; else; a = @tilesets; end
  return a[id] if a[id]
  s = @prefix + @tileset_dir + id.to_s.split(@separator).join('/') + ext
  tileset = Gosu::Image.load_tiles G.window, s, tile_width, tile_height, true
  a[id] = tileset
end

def tileset_dir=(value)

Sets the path to tilset files (under +prefix+). Default is 'tileset'.
def tileset_dir=(value)
  value += '/' if value != '' and value[-1] != '/'
  @tileset_dir = value
end