[javascript] Generate

Viewer

copydownloadembedprintName: Generate
  1. // generate.zonescript
  2. // Last modified on: 23-Feb-2019
  3.  
  4. //--------------------------------------------------------------------------
  5.  
  6. function processDirections(array, animation_array, char_name, out_name, anim_name, frameDuration, looped, reversed, offset, event, event_frame)
  7. {
  8.         var north = []
  9.         var north_east = []
  10.         var north_west = []
  11.         var south = []
  12.         var south_east = []
  13.         var south_west = []
  14.         var east = []
  15.         var west = []
  16.  
  17.         for (var i in array)
  18.         {
  19.                 var name = getDefinitionID(array[i]);
  20.  
  21.                 if (name.startsWith(anim_name + "_n_"))
  22.                         north.push(array[i]);
  23.                 else if (name.startsWith(anim_name + "_ne_"))
  24.                         north_east.push(array[i]);
  25.                 else if (name.startsWith(anim_name + "_nw_"))
  26.                         north_west.push(array[i]);
  27.                 else if (name.startsWith(anim_name + "_s_"))
  28.                         south.push(array[i]);
  29.                 else if (name.startsWith(anim_name + "_se_"))
  30.                         south_east.push(array[i]);
  31.                 else if (name.startsWith(anim_name + "_sw_"))
  32.                         south_west.push(array[i]);
  33.                 else if (name.startsWith(anim_name + "_e_"))
  34.                         east.push(array[i]);
  35.                 else if (name.startsWith(anim_name + "_w_"))
  36.                         west.push(array[i]);
  37.                 else
  38.                         trace("Unknown frame: " + name);
  39.         }
  40.  
  41.         north.sort();
  42.         north_east.sort();
  43.         north_west.sort();
  44.         south.sort();
  45.         south_east.sort();
  46.         south_west.sort();
  47.         east.sort();
  48.         west.sort();
  49.  
  50.         var animation_north =                createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
  51.         var animation_north_east =   createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
  52.         var animation_north_west =   createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
  53.         var animation_south =                createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
  54.         var animation_south_east =   createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
  55.         var animation_south_west =   createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
  56.         var animation_east =                 createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
  57.         var animation_west =                 createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
  58.  
  59.         setDefinitionID(animation_north,               out_name + "_North");
  60.         setDefinitionID(animation_north_east,  out_name + "_NorthEast");
  61.         setDefinitionID(animation_north_west,  out_name + "_NorthWest");
  62.         setDefinitionID(animation_south,               out_name + "_South");
  63.         setDefinitionID(animation_south_east,  out_name + "_SouthEast");
  64.         setDefinitionID(animation_south_west,  out_name + "_SouthWest");
  65.         setDefinitionID(animation_east,                out_name + "_East");
  66.         setDefinitionID(animation_west,                out_name + "_West");
  67.  
  68.         setPosition(animation_north,                   400, 0);
  69.         setPosition(animation_north_east,              400, 0);
  70.         setPosition(animation_north_west,              400, 0);
  71.         setPosition(animation_south,                   400, 0);
  72.         setPosition(animation_south_east,              400, 0);
  73.         setPosition(animation_south_west,              400, 0);
  74.         setPosition(animation_east,                    400, 0);
  75.         setPosition(animation_west,                    400, 0);
  76.  
  77.         generateUUID(animation_north,          char_name + "_" + getDefinitionID(animation_north));
  78.         generateUUID(animation_north_east,     char_name + "_" + getDefinitionID(animation_north_east));
  79.         generateUUID(animation_north_west,     char_name + "_" + getDefinitionID(animation_north_west));
  80.         generateUUID(animation_south,          char_name + "_" + getDefinitionID(animation_south));
  81.         generateUUID(animation_south_east,     char_name + "_" + getDefinitionID(animation_south_east));
  82.         generateUUID(animation_south_west,     char_name + "_" + getDefinitionID(animation_south_west));
  83.         generateUUID(animation_east,                   char_name + "_" + getDefinitionID(animation_east));
  84.         generateUUID(animation_west,                   char_name + "_" + getDefinitionID(animation_west));
  85.  
  86.         setLinkArray(animation_north,          "frames", north);
  87.         setLinkArray(animation_north_east,     "frames", north_east);
  88.         setLinkArray(animation_north_west,     "frames", north_west);
  89.         setLinkArray(animation_south,          "frames", south);
  90.         setLinkArray(animation_south_east,     "frames", south_east);
  91.         setLinkArray(animation_south_west,     "frames", south_west);
  92.         setLinkArray(animation_east,                   "frames", east);
  93.         setLinkArray(animation_west,                   "frames", west);
  94.  
  95.         setFloat(animation_north,                      "frameDuration", frameDuration);
  96.         setFloat(animation_north_east,                 "frameDuration", frameDuration);
  97.         setFloat(animation_north_west,                 "frameDuration", frameDuration);
  98.         setFloat(animation_south,                      "frameDuration", frameDuration);
  99.         setFloat(animation_south_east,                 "frameDuration", frameDuration);
  100.         setFloat(animation_south_west,                 "frameDuration", frameDuration);
  101.         setFloat(animation_east,                       "frameDuration", frameDuration);
  102.         setFloat(animation_west,                       "frameDuration", frameDuration);
  103.  
  104.         setFloat(animation_north,                      "offsetY", offset);
  105.         setFloat(animation_north_east,                 "offsetY", offset);
  106.         setFloat(animation_north_west,                 "offsetY", offset);
  107.         setFloat(animation_south,                      "offsetY", offset);
  108.         setFloat(animation_south_east,                 "offsetY", offset);
  109.         setFloat(animation_south_west,                 "offsetY", offset);
  110.         setFloat(animation_east,                       "offsetY", offset);
  111.         setFloat(animation_west,                       "offsetY", offset);
  112.  
  113.         if (looped)
  114.         {
  115.                 setEnum(animation_north,       "playMode", "LOOP");
  116.                 setEnum(animation_north_east, "playMode", "LOOP");
  117.                 setEnum(animation_north_west, "playMode", "LOOP");
  118.                 setEnum(animation_south,       "playMode", "LOOP");
  119.                 setEnum(animation_south_east, "playMode", "LOOP");
  120.                 setEnum(animation_south_west, "playMode", "LOOP");
  121.                 setEnum(animation_east,                "playMode", "LOOP");
  122.                 setEnum(animation_west,                "playMode", "LOOP");
  123.         }
  124.         else if (reversed)
  125.         {
  126.                 setEnum(animation_north,       "playMode", "REVERSED");
  127.                 setEnum(animation_north_east, "playMode", "REVERSED");
  128.                 setEnum(animation_north_west, "playMode", "REVERSED");
  129.                 setEnum(animation_south,       "playMode", "REVERSED");
  130.                 setEnum(animation_south_east, "playMode", "REVERSED");
  131.                 setEnum(animation_south_west, "playMode", "REVERSED");
  132.                 setEnum(animation_east,                "playMode", "REVERSED");
  133.                 setEnum(animation_west,                "playMode", "REVERSED");
  134.         }
  135.  
  136.         var animation = createNewDefinition("eu.cherrytree.isorpg.animation.DirectedAnimation");
  137.         setDefinitionID(animation, out_name);
  138.         generateUUID(animation, char_name + "_" + out_name);
  139.  
  140.         setPosition(animation, 200, 0);
  141.  
  142.         setLink(animation, "north",           animation_north);
  143.         setLink(animation, "northEast",       animation_north_east);
  144.         setLink(animation, "northWest",       animation_north_west);
  145.         setLink(animation, "south",           animation_south);
  146.         setLink(animation, "southEast",       animation_south_east);
  147.         setLink(animation, "southWest",       animation_south_west);
  148.         setLink(animation, "east",            animation_east);
  149.         setLink(animation, "west",            animation_west);
  150.  
  151.         animation_array.push(animation_north);
  152.         animation_array.push(animation_north_east);
  153.         animation_array.push(animation_north_west);
  154.         animation_array.push(animation_south);
  155.         animation_array.push(animation_south_east);
  156.         animation_array.push(animation_south_west);
  157.         animation_array.push(animation_east);
  158.         animation_array.push(animation_west);
  159.  
  160.         var ret = [ animation , animation_north , animation_north_east, animation_north_west , animation_south , animation_south_east, animation_south_west , animation_east, animation_west ]
  161.  
  162.         if (event_frame >= 0)
  163.         {
  164.                 var events = loadZone("characters/animation_events.zone");
  165.                 var ev = null;
  166.  
  167.                 for (var i in events)
  168.                 {
  169.                         if (getDefinitionID(events[i]) == event)
  170.                         {
  171.                                 ev = events[i];
  172.                                 break;
  173.                         }
  174.                 }
  175.  
  176.                 if (ev != null)
  177.                 {
  178.                         var event_mapping = createNewDefinition("eu.cherrytree.gdx.animation.AnimationEventMapping");
  179.                         setDefinitionID(event_mapping, event + "_" + out_name);
  180.                         generateUUID(event_mapping, event + "_" + char_name + "_" + out_name);
  181.  
  182.                         setInt(event_mapping, "frame", event_frame);
  183.                         setLink(event_mapping, "event", ev);
  184.  
  185.                         setPosition(event_mapping, 600, 0);
  186.  
  187.                         var event_array = [ event_mapping ];
  188.  
  189.                         setLinkArray(animation_north,          "events", event_array);
  190.                         setLinkArray(animation_north_east,     "events", event_array);
  191.                         setLinkArray(animation_north_west,     "events", event_array);
  192.                         setLinkArray(animation_south,          "events", event_array);
  193.                         setLinkArray(animation_south_east,     "events", event_array);
  194.                         setLinkArray(animation_south_west,     "events", event_array);
  195.                         setLinkArray(animation_east,                   "events", event_array);
  196.                         setLinkArray(animation_west,                   "events", event_array);
  197.  
  198.                         ret.push(event_mapping);
  199.                 }
  200.         }
  201.  
  202.         return ret;
  203. }
  204.  
  205. //--------------------------------------------------------------------------
  206.  
  207. function processAnimation(src, anim_name, looped, character_name, animation_array, offset, event, event_frame)
  208. {
  209.         var all = loadZone(src + ".zone");
  210.  
  211.         var frames = [];
  212.  
  213.         for (var i in all)
  214.         {
  215.                 var name = getDefinitionID(all[i]);
  216.  
  217.                 if (name.startsWith(anim_name))
  218.                         frames.push(all[i]);
  219.         }
  220.  
  221.         return processDirections(frames, animation_array, character_name, anim_name, anim_name, 0.06, looped, false, offset, event, event_frame);
  222. }
  223.  
  224. //--------------------------------------------------------------------------
  225.  
  226. function saveAnimations(tgt, character_name, array, animations)
  227. {
  228.         var animation_list = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.AnimationList");
  229.         setDefinitionID(animation_list, character_name + "_AnimationList");
  230.         generateUUID(animation_list, character_name + "_AnimationList");
  231.  
  232.         array.unshift(animation_list);
  233.  
  234.         setLinkArray(animation_list, "animations", animations);
  235.  
  236.         saveZone(array, tgt + "_animations.zone");
  237. }
  238.  
  239. //--------------------------------------------------------------------------
  240.  

Editor

You can edit this paste and save as new: