-- Autogenerated Essential => Figura script
-- Feature "animations" w/ args {{['type'] = 'IDLE',['target'] = 'ALL',['probability'] = 1,['name'] = 'animation.winged_shoes.idle',['skips'] = 0,['priority'] = 1,['loops'] = 0}}
do

  local animations = {{['type'] = 'IDLE',['target'] = 'ALL',['probability'] = 1,['name'] = 'animation.winged_shoes.idle',['skips'] = 0,['priority'] = 1,['loops'] = 0}}
  local currentAnim
  
  local afterDoneAnim
  
  local skipATick = false
  
  function animations_textureAnimationStart()
    for _, anim in ipairs(animations) do
      if anim.type == 'TEXTURE_ANIMATION_START' then
        if math.random() < anim.probability then
          if anim.skipsleft and anim.skipsleft > 0 then
            anim.skipsleft = anim.skipsleft - 1
          else
            anim.skipsleft = anim.skips
            animation[anim.name].play()
            skipATick = true
            if anim.on_complete then afterDoneAnim = anim.on_complete.name end
          end
        end
      end
    end
  end
  
  local op
  
  local function lengthxy(t)
    return math.sqrt(t[1]^2 + t[3]^2)
  end
  
  function tick()
    if skipATick then
      skipATick = false
      return
    end
  
    local p = player.getPos()
    if not op then op = p end
    local l = lengthxy({p[1] - op[1], p[2] - op[2], p[3] - op[3]})
  
    local anyAnimsPlaying = false
    for anim in pairs(animation) do
      if type(animation[anim]) ~= 'function' and animation[anim].getPlayState() == 'PLAYING' then
        anyAnimsPlaying = true
        break
      end
    end
  
    if not anyAnimsPlaying then
      if afterDoneAnim then
        afterDoneAnim = nil
        animation[afterDoneAnim].play()
      else
        for _, anim in ipairs(animations) do
          if anim.type == 'WALK' and l > 0.1 then
            if math.random() < (anim.probability or 1) then
              animation[anim.name].play()
              skipATick = true
            end
            return
          end
        end
        for _, anim in ipairs(animations) do
          if anim.type == 'IDLE' then
            animation[anim.name].play()
            skipATick = true
            return
          end
        end
      end
    end
  end
  
  if events and events.TICK then -- rewrite
    print('animations arent supported in the rewrite so far and thus are disabled for the converted models. the rest _should_ work fine, but look out for that')
  end
  
end

-- Feature "armor" w/ args {['legs'] = true}
do

  local hide = {['legs'] = true}
  
  function player_init()
    if hide.head then armor_model.HELMET.setEnabled(false); armor_model.HEAD_ITEM.setEnabled(false) end
    if hide.body then armor_model.CHESTPLATE.setEnabled(false) end
    if hide.legs then armor_model.LEGGINGS.setEnabled(false) end
  end
  
  
  if events and events.TICK then -- rewrite
    if hide.head then vanilla_model.HELMET:setVisible(false) end
    if hide.body then vanilla_model.CHESTPLATE_BODY:setVisible(false) end
    if hide.arms then vanilla_model.CHESTPLATE_LEFT_ARM:setVisible(false) vanilla_model.CHESTPLATE_RIGHT_ARM:setVisible(false) end
    if hide.legs then vanilla_model.LEGGINGS:setVisible(false) vanilla_model.BOOTS:setVisible(false) end
  end
  
end
