-- Autogenerated Essential => Figura script
-- Feature "animate" w/ args 70, 1120
do

  local segmentHeight = 70
  local fullHeight = 1120
  
  local frames = math.floor(fullHeight / segmentHeight)
  local ticks = 0
  
  function tick()
    ticks = ticks + 1
    if ticks % 2 == 0 then
      local startedOver = false
      local uvYoffset = segmentHeight / fullHeight
      local function step(group)
        if group.getChildren then
          for k, v in pairs(group.getChildren()) do
            step(v)
          end
        else
          local uv = group.getUV()
          local newy = uv.y + uvYoffset
          if newy > 1 then
            startedOver = true
          end
          group.setUV({uv.x, newy % 1})
        end
      end
      for _, v in pairs(model) do
        step(v)
      end
  
      if startedOver and animations_textureAnimationStart then
        animations_textureAnimationStart()
      end
    end
  end
  
  if events and events.TICK then -- rewrite
    local uvY = 0 -- gotta manually track this bc no getUV
    events.TICK:register(function()
      ticks = ticks + 1
      if ticks % 2 == 0 then
        local startedOver = false
        local uvYoffset = segmentHeight / fullHeight
        local function step(group)
          if group:getType() == 'CUBE' then
            for k, v in pairs(group:getChildren()) do
              step(v)
            end
          else
            uvY = uvY + uvYoffset
            if uvY > 1 then
              startedOver = true
              uvY = uvY - 1
            end
            group:setUV(0, uvY)
          end
        end
        for _, v in pairs(models['player_model']:getChildren()) do
          step(v)
        end
  
        --if startedOver and animations_textureAnimationStart then
        --  animations_textureAnimationStart()
        --end
      end
    end)
  end
  
end
