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

local CreateFrame = CreateFrame

local mtAnimationCreator = {};

--- Creates a new sphere animation.
-- @param parent The parent container.
-- @param animation The animation data.
-- @return The animation.
--
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, skipVisibility)
    if anim then
      self:SetPosition        (0, anim.posX, anim.posY)
      self:SetDisplayInfo     (ss.Animations.get(anim.groupId, anim.id))
      self:SetCamDistanceScale(anim.camDistance)
      self.anim = anim
      
      if not skipVisibility then
        self:SetAlpha(anim.alpha)
        self:Show()
      end
    elseif self.anim then
      self:UpdateAnimation(self.anim, skipVisibility)
    end
  end

  return animationTexture
end

--- Creates a new micro sphere animation.
-- @param parent The parent container.
-- @return The animation.
--
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.Utils.addModule("AnimationCreator", mtAnimationCreator)
