class AuthorEngine::Image
Constants
- CACHE
Public Class Methods
new(path, retro: true)
click to toggle source
# File lib/author_engine/image.rb, line 6 def initialize(path, retro: true) @retro = retro @image = image_from_cache(path) end
Public Instance Methods
draw(*args)
click to toggle source
# File lib/author_engine/image.rb, line 46 def draw(*args) @image.draw(*args) end
draw_rot(*args)
click to toggle source
# File lib/author_engine/image.rb, line 50 def draw_rot(*args) @image.draw_rot(*args) end
height()
click to toggle source
# File lib/author_engine/image.rb, line 12 def height; @image.height; end
image_from_cache(path)
click to toggle source
# File lib/author_engine/image.rb, line 14 def image_from_cache(path) path = "#{File.expand_path("../../../", __FILE__)}/#{path}" image = nil if image = CACHE.dig(path) return image else _image = nil begin _image = Gosu::Image.new(path, retro: @retro) rescue RuntimeError => e if e.message.downcase.include?("cannot open file") warn e.message warn caller[0..2].map{|s| s = " #{s}"}.reverse _image = image_missing else raise end end image = CACHE[path] = _image end return image end
image_missing()
click to toggle source
# File lib/author_engine/image.rb, line 39 def image_missing return Gosu.render(window.sprite_size, window.sprite_size) do Gosu.draw_rect(0, 0, window.sprite_size, window.sprite_size, Gosu::Color::YELLOW) Gosu.draw_rect(2, 2, window.sprite_size-4, window.sprite_size-4, Gosu::Color::RED) end end
width()
click to toggle source
# File lib/author_engine/image.rb, line 11 def width; @image.width; end