class Gosuplus::ResourceLoader
Public Class Methods
new(window, state_name)
click to toggle source
# File lib/Gosuplus/resourceloader.rb, line 3 def initialize(window, state_name) @state_name, @window = window, state_name @resources = {} end
Public Instance Methods
load_resources()
click to toggle source
# File lib/Gosuplus/resourceloader.rb, line 8 def load_resources @state_name.slice! "Gosuplus::" filepath = "./lib/states/#{@state_name}_resources.txt".downcase File.new(filepath, 'w') unless File.file?(filepath) data = File.readlines(filepath) data.each do |content| content = content.strip.split(" ") content[2].insert(0, './assets/') content[1] = content[1].to_sym case content[0] when 'image' load_image(content[1], content[2]) when 'font' load_font(content[1], content[2], content[3].to_i) when 'spritesheet' load_spritesheet(content[1], content[2], content[3].to_i, content[4].to_i) end end @resources end
Private Instance Methods
load_font(key, path, height)
click to toggle source
# File lib/Gosuplus/resourceloader.rb, line 38 def load_font(key, path, height) raise IOError, 'path must point to a existing file!' unless File.file?(path) @resources[key] = Gosu::Font.new(@window, path, height) if @resources[key].nil? end
load_image(key, path)
click to toggle source
# File lib/Gosuplus/resourceloader.rb, line 33 def load_image(key, path) raise IOError, 'path must point to a existing file!' unless File.file?(path) @resources[key] = Gosu::Image.new(@window, path, false) if @resources[key].nil? end
load_spritesheet(key, path, width, height)
click to toggle source
# File lib/Gosuplus/resourceloader.rb, line 43 def load_spritesheet(key, path, width, height) raise IOError, 'path must point to a existing file!' unless File.file?(path) @resources[key] = Gosu::Image.load_tiles(@window, path, width, height, true) if @resources[key].nil? end