// generate.zonescript
// Last modified on: 23-Feb-2019
//--------------------------------------------------------------------------
function processDirections(array, animation_array, char_name, out_name, anim_name, frameDuration, looped, reversed, offset, event, event_frame)
{
var north = []
var north_east = []
var north_west = []
var south = []
var south_east = []
var south_west = []
var east = []
var west = []
for (var i in array)
{
var name = getDefinitionID(array[i]);
if (name.startsWith(anim_name + "_n_"))
north.push(array[i]);
else if (name.startsWith(anim_name + "_ne_"))
north_east.push(array[i]);
else if (name.startsWith(anim_name + "_nw_"))
north_west.push(array[i]);
else if (name.startsWith(anim_name + "_s_"))
south.push(array[i]);
else if (name.startsWith(anim_name + "_se_"))
south_east.push(array[i]);
else if (name.startsWith(anim_name + "_sw_"))
south_west.push(array[i]);
else if (name.startsWith(anim_name + "_e_"))
east.push(array[i]);
else if (name.startsWith(anim_name + "_w_"))
west.push(array[i]);
else
trace("Unknown frame: " + name);
}
north.sort();
north_east.sort();
north_west.sort();
south.sort();
south_east.sort();
south_west.sort();
east.sort();
west.sort();
var animation_north = createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
var animation_north_east = createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
var animation_north_west = createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
var animation_south = createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
var animation_south_east = createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
var animation_south_west = createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
var animation_east = createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
var animation_west = createNewDefinition("eu.cherrytree.gdx.animation.AnimationDefinition");
setDefinitionID(animation_north, out_name + "_North");
setDefinitionID(animation_north_east, out_name + "_NorthEast");
setDefinitionID(animation_north_west, out_name + "_NorthWest");
setDefinitionID(animation_south, out_name + "_South");
setDefinitionID(animation_south_east, out_name + "_SouthEast");
setDefinitionID(animation_south_west, out_name + "_SouthWest");
setDefinitionID(animation_east, out_name + "_East");
setDefinitionID(animation_west, out_name + "_West");
setPosition(animation_north, 400, 0);
setPosition(animation_north_east, 400, 0);
setPosition(animation_north_west, 400, 0);
setPosition(animation_south, 400, 0);
setPosition(animation_south_east, 400, 0);
setPosition(animation_south_west, 400, 0);
setPosition(animation_east, 400, 0);
setPosition(animation_west, 400, 0);
generateUUID(animation_north, char_name + "_" + getDefinitionID(animation_north));
generateUUID(animation_north_east, char_name + "_" + getDefinitionID(animation_north_east));
generateUUID(animation_north_west, char_name + "_" + getDefinitionID(animation_north_west));
generateUUID(animation_south, char_name + "_" + getDefinitionID(animation_south));
generateUUID(animation_south_east, char_name + "_" + getDefinitionID(animation_south_east));
generateUUID(animation_south_west, char_name + "_" + getDefinitionID(animation_south_west));
generateUUID(animation_east, char_name + "_" + getDefinitionID(animation_east));
generateUUID(animation_west, char_name + "_" + getDefinitionID(animation_west));
setLinkArray(animation_north, "frames", north);
setLinkArray(animation_north_east, "frames", north_east);
setLinkArray(animation_north_west, "frames", north_west);
setLinkArray(animation_south, "frames", south);
setLinkArray(animation_south_east, "frames", south_east);
setLinkArray(animation_south_west, "frames", south_west);
setLinkArray(animation_east, "frames", east);
setLinkArray(animation_west, "frames", west);
setFloat(animation_north, "frameDuration", frameDuration);
setFloat(animation_north_east, "frameDuration", frameDuration);
setFloat(animation_north_west, "frameDuration", frameDuration);
setFloat(animation_south, "frameDuration", frameDuration);
setFloat(animation_south_east, "frameDuration", frameDuration);
setFloat(animation_south_west, "frameDuration", frameDuration);
setFloat(animation_east, "frameDuration", frameDuration);
setFloat(animation_west, "frameDuration", frameDuration);
setFloat(animation_north, "offsetY", offset);
setFloat(animation_north_east, "offsetY", offset);
setFloat(animation_north_west, "offsetY", offset);
setFloat(animation_south, "offsetY", offset);
setFloat(animation_south_east, "offsetY", offset);
setFloat(animation_south_west, "offsetY", offset);
setFloat(animation_east, "offsetY", offset);
setFloat(animation_west, "offsetY", offset);
if (looped)
{
setEnum(animation_north, "playMode", "LOOP");
setEnum(animation_north_east, "playMode", "LOOP");
setEnum(animation_north_west, "playMode", "LOOP");
setEnum(animation_south, "playMode", "LOOP");
setEnum(animation_south_east, "playMode", "LOOP");
setEnum(animation_south_west, "playMode", "LOOP");
setEnum(animation_east, "playMode", "LOOP");
setEnum(animation_west, "playMode", "LOOP");
}
else if (reversed)
{
setEnum(animation_north, "playMode", "REVERSED");
setEnum(animation_north_east, "playMode", "REVERSED");
setEnum(animation_north_west, "playMode", "REVERSED");
setEnum(animation_south, "playMode", "REVERSED");
setEnum(animation_south_east, "playMode", "REVERSED");
setEnum(animation_south_west, "playMode", "REVERSED");
setEnum(animation_east, "playMode", "REVERSED");
setEnum(animation_west, "playMode", "REVERSED");
}
var animation = createNewDefinition("eu.cherrytree.isorpg.animation.DirectedAnimation");
setDefinitionID(animation, out_name);
generateUUID(animation, char_name + "_" + out_name);
setPosition(animation, 200, 0);
setLink(animation, "north", animation_north);
setLink(animation, "northEast", animation_north_east);
setLink(animation, "northWest", animation_north_west);
setLink(animation, "south", animation_south);
setLink(animation, "southEast", animation_south_east);
setLink(animation, "southWest", animation_south_west);
setLink(animation, "east", animation_east);
setLink(animation, "west", animation_west);
animation_array.push(animation_north);
animation_array.push(animation_north_east);
animation_array.push(animation_north_west);
animation_array.push(animation_south);
animation_array.push(animation_south_east);
animation_array.push(animation_south_west);
animation_array.push(animation_east);
animation_array.push(animation_west);
var ret = [ animation , animation_north , animation_north_east, animation_north_west , animation_south , animation_south_east, animation_south_west , animation_east, animation_west ]
if (event_frame >= 0)
{
var events = loadZone("characters/animation_events.zone");
var ev = null;
for (var i in events)
{
if (getDefinitionID(events[i]) == event)
{
ev = events[i];
break;
}
}
if (ev != null)
{
var event_mapping = createNewDefinition("eu.cherrytree.gdx.animation.AnimationEventMapping");
setDefinitionID(event_mapping, event + "_" + out_name);
generateUUID(event_mapping, event + "_" + char_name + "_" + out_name);
setInt(event_mapping, "frame", event_frame);
setLink(event_mapping, "event", ev);
setPosition(event_mapping, 600, 0);
var event_array = [ event_mapping ];
setLinkArray(animation_north, "events", event_array);
setLinkArray(animation_north_east, "events", event_array);
setLinkArray(animation_north_west, "events", event_array);
setLinkArray(animation_south, "events", event_array);
setLinkArray(animation_south_east, "events", event_array);
setLinkArray(animation_south_west, "events", event_array);
setLinkArray(animation_east, "events", event_array);
setLinkArray(animation_west, "events", event_array);
ret.push(event_mapping);
}
}
return ret;
}
//--------------------------------------------------------------------------
function processAnimation(src, anim_name, looped, character_name, animation_array, offset, event, event_frame)
{
var all = loadZone(src + ".zone");
var frames = [];
for (var i in all)
{
var name = getDefinitionID(all[i]);
if (name.startsWith(anim_name))
frames.push(all[i]);
}
return processDirections(frames, animation_array, character_name, anim_name, anim_name, 0.06, looped, false, offset, event, event_frame);
}
//--------------------------------------------------------------------------
function saveAnimations(tgt, character_name, array, animations)
{
var animation_list = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.AnimationList");
setDefinitionID(animation_list, character_name + "_AnimationList");
generateUUID(animation_list, character_name + "_AnimationList");
array.unshift(animation_list);
setLinkArray(animation_list, "animations", animations);
saveZone(array, tgt + "_animations.zone");
}
//--------------------------------------------------------------------------