class AdventureRL::Image

Constants

DEFAULT_SETTINGS
IMAGE_OPTION_KEYS

Valid image option keys for the Gosu::Image constructor.

Public Class Methods

new(settings = {}) click to toggle source

Pass the filepath to the image as the value of the key :file in your passed Settings instance or hash.

Calls superclass method
# File lib/AdventureRL/Image.rb, line 33
def initialize settings = {}
  @settings = DEFAULT_SETTINGS.merge settings
  @z_index       = @settings.get :z_index
  @image_options = get_image_options_from @settings
  @image         = get_image_from @settings.get(:file)  unless (@settings.get(:dont_create_image))
  super @settings
end

Public Instance Methods

draw() click to toggle source
# File lib/AdventureRL/Image.rb, line 41
def draw
  corner = get_corner :left, :top
  scale  = get_image_scale
  @image.draw(
    corner.x, corner.y,
    @z_index,
    scale[:x], scale[:y]
  )
end

Private Instance Methods

get_image_from(file) click to toggle source
# File lib/AdventureRL/Image.rb, line 61
def get_image_from file
  filepath = Pathname.new file
  error_no_file filepath  unless (file_exists? filepath)
  return Gosu::Image.new(
    filepath.to_path,
    @image_options
  )
end
get_image_options_from(settings = @settings) click to toggle source
# File lib/AdventureRL/Image.rb, line 53
def get_image_options_from settings = @settings
  return IMAGE_OPTION_KEYS.map do |key|
    setting = settings.get key
    next [key, setting]  if (setting)
    next nil
  end .compact.to_h
end
get_image_scale() click to toggle source
# File lib/AdventureRL/Image.rb, line 70
def get_image_scale
  return {
    x: (get_size(:width).to_f  / @image.width.to_f),
    y: (get_size(:height).to_f / @image.height.to_f)
  }
end