class Equinox_LargeSprites
  # This class exists as a means to directly draw large sprites "LargeSprite" into the world,
  # reducing how much "single-use" props are taken up in Tilesets
  
  # Known bug: Don't know how to fix depth to function like tileset..
  # will just prevent anything from moving right in front of one
  
  attr_accessor :sprites    # List of active LargeSprites
  
  def initialize(viewport)
    @viewport = viewport
    @sprites = []
    
    @@instance = self
  end
  
  def self.instance
    @@instance
  end
  
  def dispose
    for direct_sprite in @sprites
      direct_sprite.dispose
    end
    @viewport = nil
    @sprites = []
    @@instance = nil
  end
  
  def update
    for direct_sprite in @sprites
      direct_sprite.update
    end
  end
  
  def add_sprite(sprite_name, x, y, type = 0, multiplier = 1)
    sprite = LargeSprite.new(sprite_name, x, y, type, multiplier, @viewport)
    
    @sprites.push(sprite)
  end
end

class LargeSprite
  # A directly-drawn sprite
  attr_accessor :sprite     # Sprite object
  attr_accessor :x          # Defined X value
  attr_accessor :y          # Defined Y value
  attr_accessor :multiplier # Parallax Multiplier, >1 = closer to view, <1 = farther to view
  
  def initialize(sprite_name, x, y, type, multiplier, viewport)
    @sprite = Sprite.new
    @sprite.bitmap = RPG::Cache.large(sprite_name) 
    @x = x
    @y = y
    @multiplier = multiplier
    @viewport = viewport
    
    if type == 0
      # Default: Horizontally center, Vertically grow from bottom
      @sprite.x = x * 32 - (@sprite.bitmap.width / 2) + 16
      @sprite.y = y * 32 - @sprite.bitmap.height + 32
    elsif type == 1
      # Top-left aligned
      @sprite.x = x * 32
      @sprite.y = y * 32
    else
      print("Unknown type provided for LargeSprite")
    end
  end
  
  def update
    @sprite.ox = $game_map.display_x / 4 * @multiplier
    @sprite.oy = $game_map.display_y / 4 * @multiplier
    @sprite.z = ((@y * 128) - $game_map.display_y + 3) / 4 + 32
  end
  
  def dispose
    @sprite.dispose
  end
end