Guest User

Untitled

a guest
Jul 17th, 2022
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.73 KB | None | 0 0
  1. -- The animation file is generated with Panthera Animation Software
  2. -- https://insality.github.io/panthera-editor/editor
  3.  
  4. local PantheraAnimation = {}
  5.  
  6. local ALPHA = "color.w"
  7. local COLOR_X = "color.x"
  8. local COLOR_Y = "color.y"
  9. local COLOR_Z = "color.z"
  10. local POSITION_X = "position.x"
  11. local POSITION_Y = "position.y"
  12. local ROTATION_X = "rotation.x"
  13. local ROTATION_Y = "rotation.y"
  14. local ROTATION_Z = "rotation.z"
  15. local SCALE_X = "scale.x"
  16. local SCALE_Y = "scale.y"
  17. local SIZE_X = "size.x"
  18. local SIZE_Y = "size.y"
  19. local SLICE9_W = "slice9.w"
  20. local SLICE9_X = "slice9.x"
  21. local SLICE9_Y = "slice9.y"
  22. local SLICE9_Z = "slice9.z"
  23.  
  24.  
  25. ---@param nodes table<string, Node>|nil @If nil, it will try to get options.get_node(id) or gui.get_node(id)
  26. ---@param options table|nil @Animation params. Fields: is_loop, speed, callback, is_relative, callback_event, get_node
  27. function PantheraAnimation.start(nodes, options)
  28.     local get_node = options and options.get_node or gui.get_node
  29.     nodes = nodes or {}
  30.     nodes["node"] = nodes["node"] or get_node("node")
  31.     nodes["node1"] = nodes["node1"] or get_node("node1")
  32.     nodes["node2"] = nodes["node2"] or get_node("node2")
  33.     nodes["node3"] = nodes["node3"] or get_node("node3")
  34.  
  35.     ---@type panthera_animation
  36.     local panthera_animation = {}
  37.     panthera_animation.timers = {}
  38.     panthera_animation.nodes = nodes
  39.     panthera_animation.current_time = 0
  40.     panthera_animation.is_playing = false
  41.     panthera_animation.animation_time = 3
  42.     panthera_animation.is_loop = options and options.is_loop or false
  43.     panthera_animation.callback = options and options.callback or nil
  44.     panthera_animation.speed = math.max(options and options.speed or 1, 0)
  45.     panthera_animation.is_relative = options and options.is_relative or false
  46.     panthera_animation.callback_event = options and options.callback_event or function() end
  47.     panthera_animation.properties = {}
  48.     panthera_animation.properties["node"] = { ROTATION_Z, SCALE_X, SCALE_Y }
  49.     panthera_animation.properties["node1"] = { ALPHA, COLOR_X, COLOR_Y, COLOR_Z, POSITION_Y, ROTATION_X, ROTATION_Y, ROTATION_Z, SIZE_X, SIZE_Y }
  50.     panthera_animation.properties["node2"] = { COLOR_X, COLOR_Y, COLOR_Z }
  51.     panthera_animation.properties["node3"] = { POSITION_X, POSITION_Y, ROTATION_Z, SIZE_X, SIZE_Y, SLICE9_W, SLICE9_X, SLICE9_Y, SLICE9_Z }
  52.  
  53.     PantheraAnimation.play(panthera_animation)
  54.  
  55.     return panthera_animation
  56. end
  57.  
  58.  
  59. ---@param panthera_animation panthera_animation
  60. ---@return nil
  61. function PantheraAnimation.stop(panthera_animation)
  62.     for node_name, properties in pairs(panthera_animation.properties) do
  63.         for index = 1, #properties do
  64.             gui.cancel_animation(panthera_animation.nodes[node_name], properties[index])
  65.         end
  66.     end
  67.     for index = #panthera_animation.timers, 1, -1 do
  68.         timer.cancel(panthera_animation.timers[index])
  69.         table.remove(panthera_animation.timers, index)
  70.     end
  71.     panthera_animation.is_playing = false
  72. end
  73.  
  74.  
  75. ---@param panthera_animation panthera_animation
  76. ---@return nil
  77. function PantheraAnimation.play(panthera_animation)
  78.     local nodes = panthera_animation.nodes
  79.     local speed = panthera_animation.speed
  80.     local timers = panthera_animation.timers
  81.     local is_relative = panthera_animation.is_relative
  82.     panthera_animation.is_playing = true
  83.  
  84.     if #timers > 0 then
  85.         PantheraAnimation.stop(panthera_animation)
  86.     end
  87.  
  88.     -- Node: node
  89.     local node_node = nodes["node"]
  90.     local node_node_scale = vmath.vector3(1, 1, 1)
  91.     local node_node_rotation = vmath.vector3(0, 0, 0)
  92.     if is_relative then
  93.         node_node_scale = gui.get_scale(node_node)
  94.         node_node_rotation = gui.get_rotation(node_node)
  95.     else
  96.         gui.set_scale(node_node, node_node_scale)
  97.         gui.set_rotation(node_node, node_node_rotation)
  98.         gui.play_flipbook(node_node, "defold-logo")
  99.     end
  100.     -- ROTATION_Z
  101.     gui.animate(node_node, ROTATION_Z, node_node_rotation.z - 20, gui.EASING_OUTCUBIC, 0.22 / speed, 0.66 / speed, function()
  102.         gui.animate(node_node, ROTATION_Z, node_node_rotation.z + 20, gui.EASING_OUTCUBIC, 0.24 / speed, 0 / speed, function()
  103.             gui.animate(node_node, ROTATION_Z, node_node_rotation.z - 20, gui.EASING_OUTQUAD, 0.24 / speed, 0 / speed, function()
  104.                 gui.animate(node_node, ROTATION_Z, node_node_rotation.z + 20, gui.EASING_OUTQUAD, 0.24 / speed, 0 / speed, function()
  105.                     gui.animate(node_node, ROTATION_Z, node_node_rotation.z, gui.EASING_OUTCUBIC, 0.22 / speed)
  106.                 end)
  107.             end)
  108.         end)
  109.     end)
  110.     -- SCALE_X
  111.     gui.animate(node_node, SCALE_X, node_node_scale.x + 0.5, gui.EASING_OUTSINE, 0.5 / speed, 0 / speed, function()
  112.         gui.animate(node_node, SCALE_X, node_node_scale.x, gui.EASING_OUTBACK, 0.25 / speed, 0 / speed, function()
  113.             gui.animate(node_node, SCALE_X, node_node_scale.x - 0.2, gui.EASING_OUTSINE, 0.26 / speed, 1.13 / speed, function()
  114.                 gui.animate(node_node, SCALE_X, node_node_scale.x + 0.7, gui.EASING_OUTEXPO, 0.5 / speed)
  115.             end)
  116.         end)
  117.     end)
  118.     -- SCALE_Y
  119.     gui.animate(node_node, SCALE_Y, node_node_scale.y + 0.5, gui.EASING_OUTSINE, 0.5 / speed, 0 / speed, function()
  120.         gui.animate(node_node, SCALE_Y, node_node_scale.y, gui.EASING_OUTBACK, 0.25 / speed, 0 / speed, function()
  121.             gui.animate(node_node, SCALE_Y, node_node_scale.y - 0.2, gui.EASING_OUTSINE, 0.26 / speed, 1.13 / speed, function()
  122.                 gui.animate(node_node, SCALE_Y, node_node_scale.y + 0.7, gui.EASING_OUTBACK, 0.5 / speed)
  123.             end)
  124.         end)
  125.     end)
  126.     -- TRIGGER_EVENT
  127.     table.insert(timers, timer.delay(0.31 / speed, false, function()
  128.         panthera_animation.callback_event(node_node, "hi", 0)
  129.     end))
  130.     table.insert(timers, timer.delay(1.01 / speed, false, function()
  131.         panthera_animation.callback_event(node_node, "wow", 0)
  132.     end))
  133.     table.insert(timers, timer.delay(1.74 / speed, false, function()
  134.         panthera_animation.callback_event(node_node, "yea!", 0)
  135.     end))
  136.     -- TRIGGER_SET_IMAGE
  137.     table.insert(timers, timer.delay(0.66 / speed, false, function()
  138.         gui.play_flipbook(node_node, "letter_d")
  139.     end))
  140.     table.insert(timers, timer.delay(0.88 / speed, false, function()
  141.         gui.play_flipbook(node_node, "letter_e")
  142.     end))
  143.     table.insert(timers, timer.delay(1.12 / speed, false, function()
  144.         gui.play_flipbook(node_node, "letter_f")
  145.     end))
  146.     table.insert(timers, timer.delay(1.36 / speed, false, function()
  147.         gui.play_flipbook(node_node, "letter_o")
  148.     end))
  149.     table.insert(timers, timer.delay(1.6 / speed, false, function()
  150.         gui.play_flipbook(node_node, "letter_l")
  151.     end))
  152.     table.insert(timers, timer.delay(1.82 / speed, false, function()
  153.         gui.play_flipbook(node_node, "letter_d")
  154.     end))
  155.     table.insert(timers, timer.delay(2.14 / speed, false, function()
  156.         gui.play_flipbook(node_node, "defold-logo")
  157.     end))
  158.  
  159.     -- Node: node1
  160.     local node_node1 = nodes["node1"]
  161.     local node_node1_position = vmath.vector3(0, 250, 0)
  162.     local node_node1_rotation = vmath.vector3(0, 0, 0)
  163.     local node_node1_color = vmath.vector4(0, 0, 0, 0.26750001311302)
  164.     local node_node1_size = vmath.vector3(40, 40, 0)
  165.     if is_relative then
  166.         node_node1_position = gui.get_position(node_node1)
  167.         node_node1_rotation = gui.get_rotation(node_node1)
  168.         node_node1_size = gui.get_size(node_node1)
  169.     else
  170.         gui.set_position(node_node1, node_node1_position)
  171.         gui.set_rotation(node_node1, node_node1_rotation)
  172.         gui.set_color(node_node1, node_node1_color)
  173.         gui.set_size(node_node1, node_node1_size)
  174.     end
  175.     -- ALPHA
  176.     gui.animate(node_node1, ALPHA, node_node1_color.w, gui.EASING_OUTSINE, 0 / speed, 0 / speed, function()
  177.         gui.animate(node_node1, ALPHA, node_node1_color.w + 0.732, gui.EASING_OUTBACK, 0.33 / speed, 0.18 / speed)
  178.     end)
  179.     -- COLOR_X
  180.     gui.animate(node_node1, COLOR_X, node_node1_color.x + 1, gui.EASING_OUTSINE, 0.27 / speed)
  181.     -- COLOR_Y
  182.     gui.animate(node_node1, COLOR_Y, node_node1_color.y + 1, gui.EASING_OUTSINE, 0.27 / speed)
  183.     -- COLOR_Z
  184.     gui.animate(node_node1, COLOR_Z, node_node1_color.z + 1, gui.EASING_OUTSINE, 0.27 / speed)
  185.     -- POSITION_Y
  186.     gui.animate(node_node1, POSITION_Y, node_node1_position.y - 150, gui.EASING_OUTSINE, 2 / speed, 0 / speed, function()
  187.         gui.animate(node_node1, POSITION_Y, node_node1_position.y, gui.EASING_OUTBACK, 1 / speed)
  188.     end)
  189.     -- ROTATION_X
  190.     gui.animate(node_node1, ROTATION_X, node_node1_rotation.x + 360, gui.EASING_OUTSINE, 0.6 / speed, 0.9 / speed)
  191.     -- ROTATION_Y
  192.     gui.animate(node_node1, ROTATION_Y, node_node1_rotation.y + 360, gui.EASING_OUTSINE, 0.6 / speed, 1.5 / speed)
  193.     -- ROTATION_Z
  194.     gui.animate(node_node1, ROTATION_Z, node_node1_rotation.z + 360, gui.EASING_OUTSINE, 0.6 / speed, 2.1 / speed)
  195.     -- SIZE_X
  196.     gui.animate(node_node1, SIZE_X, node_node1_size.x + 58, gui.EASING_OUTSINE, 0.9 / speed)
  197.     -- SIZE_Y
  198.     gui.animate(node_node1, SIZE_Y, node_node1_size.y + 47, gui.EASING_OUTSINE, 0.9 / speed)
  199.  
  200.     -- Node: node2
  201.     local node_node2 = nodes["node2"]
  202.     local node_node2_color = vmath.vector4(1, 1, 1, 1)
  203.     if not is_relative then
  204.         gui.set_color(node_node2, node_node2_color)
  205.         gui.set_pivot(node_node2, gui.PIVOT_CENTER)
  206.         gui.set_enabled(node_node2, true)
  207.     end
  208.     -- COLOR_X
  209.     gui.animate(node_node2, COLOR_X, node_node2_color.x - 0.02, gui.EASING_OUTSINE, 0.6 / speed, 0 / speed, function()
  210.         gui.animate(node_node2, COLOR_X, node_node2_color.x - 0.16, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  211.             gui.animate(node_node2, COLOR_X, node_node2_color.x, gui.EASING_OUTSINE, 0.4 / speed)
  212.         end)
  213.     end)
  214.     -- COLOR_Y
  215.     gui.animate(node_node2, COLOR_Y, node_node2_color.y - 0.06, gui.EASING_OUTSINE, 0.6 / speed, 0 / speed, function()
  216.         gui.animate(node_node2, COLOR_Y, node_node2_color.y - 0.52, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  217.             gui.animate(node_node2, COLOR_Y, node_node2_color.y, gui.EASING_OUTSINE, 0.4 / speed)
  218.         end)
  219.     end)
  220.     -- COLOR_Z
  221.     gui.animate(node_node2, COLOR_Z, node_node2_color.z - 0.79, gui.EASING_OUTSINE, 0.6 / speed, 0 / speed, function()
  222.         gui.animate(node_node2, COLOR_Z, node_node2_color.z - 0.28, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  223.             gui.animate(node_node2, COLOR_Z, node_node2_color.z, gui.EASING_OUTSINE, 0.4 / speed)
  224.         end)
  225.     end)
  226.     -- TRIGGER_SET_ENABLED
  227.     table.insert(timers, timer.delay(2.1 / speed, false, function()
  228.         gui.set_enabled(node_node2, false)
  229.     end))
  230.     table.insert(timers, timer.delay(2.2 / speed, false, function()
  231.         gui.set_enabled(node_node2, true)
  232.     end))
  233.     table.insert(timers, timer.delay(2.3 / speed, false, function()
  234.         gui.set_enabled(node_node2, false)
  235.     end))
  236.     table.insert(timers, timer.delay(2.4 / speed, false, function()
  237.         gui.set_enabled(node_node2, true)
  238.     end))
  239.     -- TRIGGER_SET_PIVOT
  240.     table.insert(timers, timer.delay(0.4 / speed, false, function()
  241.         gui.set_pivot(node_node2, gui.PIVOT_N)
  242.     end))
  243.     table.insert(timers, timer.delay(0.6 / speed, false, function()
  244.         gui.set_pivot(node_node2, gui.PIVOT_NE)
  245.     end))
  246.     table.insert(timers, timer.delay(0.81 / speed, false, function()
  247.         gui.set_pivot(node_node2, gui.PIVOT_E)
  248.     end))
  249.     table.insert(timers, timer.delay(1 / speed, false, function()
  250.         gui.set_pivot(node_node2, gui.PIVOT_SE)
  251.     end))
  252.     table.insert(timers, timer.delay(1.2 / speed, false, function()
  253.         gui.set_pivot(node_node2, gui.PIVOT_S)
  254.     end))
  255.     table.insert(timers, timer.delay(1.4 / speed, false, function()
  256.         gui.set_pivot(node_node2, gui.PIVOT_SW)
  257.     end))
  258.     table.insert(timers, timer.delay(1.6 / speed, false, function()
  259.         gui.set_pivot(node_node2, gui.PIVOT_W)
  260.     end))
  261.     table.insert(timers, timer.delay(1.8 / speed, false, function()
  262.         gui.set_pivot(node_node2, gui.PIVOT_NW)
  263.     end))
  264.     table.insert(timers, timer.delay(2 / speed, false, function()
  265.         gui.set_pivot(node_node2, gui.PIVOT_CENTER)
  266.     end))
  267.  
  268.     -- Node: node3
  269.     local node_node3 = nodes["node3"]
  270.     local node_node3_position = vmath.vector3(-200, 250, 0)
  271.     local node_node3_rotation = vmath.vector3(0, 0, 0)
  272.     local node_node3_size = vmath.vector3(97, 91, 0)
  273.     local node_node3_slice9 = vmath.vector4(0, 0, 0, 0)
  274.     if is_relative then
  275.         node_node3_position = gui.get_position(node_node3)
  276.         node_node3_rotation = gui.get_rotation(node_node3)
  277.         node_node3_size = gui.get_size(node_node3)
  278.     else
  279.         gui.set_position(node_node3, node_node3_position)
  280.         gui.set_rotation(node_node3, node_node3_rotation)
  281.         gui.set_size(node_node3, node_node3_size)
  282.         gui.set_slice9(node_node3, node_node3_slice9)
  283.     end
  284.     -- POSITION_X
  285.     gui.animate(node_node3, POSITION_X, node_node3_position.x + 211.17, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  286.         gui.animate(node_node3, POSITION_X, node_node3_position.x - 4.5, gui.EASING_OUTSINE, 0.95 / speed, 0 / speed, function()
  287.             gui.animate(node_node3, POSITION_X, node_node3_position.x, gui.EASING_OUTSINE, 1.04 / speed)
  288.         end)
  289.     end)
  290.     -- POSITION_Y
  291.     gui.animate(node_node3, POSITION_Y, node_node3_position.y + 195.93, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  292.         gui.animate(node_node3, POSITION_Y, node_node3_position.y + 44.57, gui.EASING_OUTSINE, 0.95 / speed, 0 / speed, function()
  293.             gui.animate(node_node3, POSITION_Y, node_node3_position.y, gui.EASING_OUTSINE, 1.04 / speed)
  294.         end)
  295.     end)
  296.     -- ROTATION_Z
  297.     gui.animate(node_node3, ROTATION_Z, node_node3_rotation.z - 45, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  298.         gui.animate(node_node3, ROTATION_Z, node_node3_rotation.z, gui.EASING_OUTSINE, 1.99 / speed)
  299.     end)
  300.     -- SIZE_X
  301.     gui.animate(node_node3, SIZE_X, node_node3_size.x + 97, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  302.         gui.animate(node_node3, SIZE_X, node_node3_size.x, gui.EASING_OUTSINE, 2 / speed)
  303.     end)
  304.     -- SIZE_Y
  305.     gui.animate(node_node3, SIZE_Y, node_node3_size.y + 91, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  306.         gui.animate(node_node3, SIZE_Y, node_node3_size.y, gui.EASING_OUTSINE, 2 / speed)
  307.     end)
  308.     -- SLICE9_W
  309.     gui.animate(node_node3, SLICE9_W, node_node3_slice9.w + 1, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  310.         gui.animate(node_node3, SLICE9_W, node_node3_slice9.w, gui.EASING_OUTSINE, 2 / speed)
  311.     end)
  312.     -- SLICE9_X
  313.     gui.animate(node_node3, SLICE9_X, node_node3_slice9.x + 50, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  314.         gui.animate(node_node3, SLICE9_X, node_node3_slice9.x, gui.EASING_OUTSINE, 2 / speed)
  315.     end)
  316.     -- SLICE9_Y
  317.     gui.animate(node_node3, SLICE9_Y, node_node3_slice9.y + 40, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  318.         gui.animate(node_node3, SLICE9_Y, node_node3_slice9.y, gui.EASING_OUTSINE, 2 / speed)
  319.     end)
  320.     -- SLICE9_Z
  321.     gui.animate(node_node3, SLICE9_Z, node_node3_slice9.z + 5, gui.EASING_OUTSINE, 1 / speed, 0 / speed, function()
  322.         gui.animate(node_node3, SLICE9_Z, node_node3_slice9.z, gui.EASING_OUTSINE, 2 / speed)
  323.     end)
  324.  
  325.     local counter_timer_id = timer.delay(1 / 60, true, function(_, _, elapsed)
  326.         panthera_animation.current_time = panthera_animation.current_time + elapsed / speed
  327.     end)
  328.     table.insert(timers, counter_timer_id)
  329.  
  330.     table.insert(timers, timer.delay(panthera_animation.animation_time / speed, false, function()
  331.         if panthera_animation.callback then
  332.             panthera_animation.callback(panthera_animation)
  333.         end
  334.         if panthera_animation.is_loop then
  335.             PantheraAnimation.play(panthera_animation)
  336.         end
  337.     end))
  338. end
  339.  
  340.  
  341. return PantheraAnimation
  342.  
Advertisement
Add Comment
Please, Sign In to add comment