-----------------------
-- Sphere Animation --
----------------------
local addon, ns = ...
local ss = ns.SS

local setmetatable = setmetatable
local CreateFrame = CreateFrame

local mtAnimationCreator = {};

function mtAnimationCreator:New(parent, animation)
  local animationTexture = CreateFrame("PlayerModel",nil, parent)
  local size             = parent:GetWidth() * 2.172

  animationTexture:SetPoint           ("CENTER",animation.posX,animation.posY)
  animationTexture:SetHeight          (size)
  animationTexture:SetWidth           (size)
  animationTexture:SetFrameLevel      (animation.frameLevel or 3)
  animationTexture:SetAlpha           (animation.alpha)
  animationTexture:SetDisplayInfo     (ss.Animations.get(animation.groupId, animation.id))
  animationTexture:SetCamDistanceScale(animation.camDistance)
  animationTexture:SetPosition        (0,animation.posX,animation.posY)

  function animationTexture:UpdateAnimation(anim)
    if anim then
      self:SetPosition        (0,anim.posX,anim.posY)
      self:SetAlpha           (anim.alpha)
      self:SetDisplayInfo     (ss.Animations.get(anim.groupId, anim.id))
      self:SetCamDistanceScale(anim.camDistance)
      self.anim = anim
      self:Show()
    elseif self.anim then
      self:UpdateAnimation(self.anim)
    end
  end

  return animationTexture
end

function mtAnimationCreator:NewGroupItem(parent)
  local animationTexture = CreateFrame("PlayerModel",nil, parent)
  local size             = parent:GetWidth() * 2.172

  animationTexture:SetPoint           ("CENTER",0,0.075)
  animationTexture:SetHeight          (size)
  animationTexture:SetWidth           (size)
  animationTexture:SetFrameLevel      (4)
  animationTexture:SetAlpha           (0.3)
  animationTexture:SetDisplayInfo     (ss.Animations.get("orbtacular", "pearl"))
  animationTexture:SetCamDistanceScale(1.85)
  animationTexture:SetPosition        (0,0,0.075)

  function animationTexture:UpdateAnimation()
      self:SetAlpha           (0.3)
      self:SetDisplayInfo     (ss.Animations.get("orbtacular", "pearl"))
      self:SetCamDistanceScale(1.85)
      self:Show()
  end

  return animationTexture
end

ss["AnimationCreator"] = setmetatable({}, { __index = mtAnimationCreator });
