[javascript] Logic
Viewer
- // logic.zonescript
- // Created on: 28-Apr-2019
- // Last modified on: 06-May-2019
- //--------------------------------------------------------------------------
- function findDefinition(array, name)
- {
- for (var i in array)
- {
- if (getDefinitionID(array[i]) == name)
- return array[i];
- }
- return null;
- }
- //--------------------------------------------------------------------------
- function createMapping(name, stance, tag, animation, tagArray, animationArray)
- {
- var mapping = createNewDefinition("eu.cherrytree.isorpg.map.objects.components.animation.AnimationTagMapping");
- generateUUID(mapping, "AnimationTagMapping" + name + stance + tag + animation);
- setEnum(mapping, "stance", stance);
- var tag_obj = findDefinition(tagArray, tag);
- var anim_obj = [ findDefinition(animationArray, animation) ];
- setLink(mapping, "tag", tag_obj);
- setLinkArray(mapping, "animations", anim_obj);
- setPosition(mapping, 400, 0);
- return mapping;
- }
- //--------------------------------------------------------------------------
- function createControl(tags_loc, anim_loc, tgt, name, map_data)
- {
- var control = createNewDefinition("eu.cherrytree.isorpg.map.objects.components.animation.AnimationControlComponentDefinition");
- generateUUID(control, "AnimationControlComponentDefinition" + name);
- var tags = loadZone(tags_loc + ".zone");
- var animations = loadZone(anim_loc + ".zone");
- var mappings = [];
- for (var i in map_data)
- mappings.push(createMapping(name, map_data[i].stance, map_data[i].tag, map_data[i].anim, tags, animations));
- setLinkArray(control, "mappings", mappings);
- var array = [control];
- array = array.concat(mappings);
- saveZone(array, tgt + ".zone");
- }
- //--------------------------------------------------------------------------
- function createTransition(from, to, name, animation, animationArray)
- {
- var transition = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.motion.animations.StanceTransitionDefinition");
- var anim_obj = findDefinition(animationArray, animation);
- setEnum(transition, "from", from);
- setEnum(transition, "to", to);
- setLink(transition, "animation", anim_obj);
- setDefinitionID(transition, from + "_" + to);
- generateUUID(transition, "StanceTransitionDefinition" + from + to + name + animation);
- setPosition(transition, 400, 0);
- return transition;
- }
- //--------------------------------------------------------------------------
- function createMotionControl(anim_loc, tgt, name, stance_data, transition_data, move_data)
- {
- var animations = loadZone(anim_loc + ".zone");
- var control = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.motion.CharacterMotionControlDefinition");
- generateUUID(control, "CharacterMotionControlDefinition" + name);
- var exploration = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.motion.animations.ExplorationStanceDefinition");
- var combat = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.motion.animations.CombatStanceDefinition");
- var crouch = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.motion.animations.CrouchStanceDefinition");
- var ko = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.motion.animations.KnockedOutStanceDefinition");
- setPosition(exploration, 400, 0);
- setPosition(combat, 400, 0);
- setPosition(crouch, 400, 0);
- setPosition(ko, 400, 0);
- generateUUID(exploration, "ExplorationStanceDefinition" + name);
- generateUUID(combat, "CombatStanceDefinition" + name);
- generateUUID(crouch, "CrouchStanceDefinition" + name);
- generateUUID(ko, "KnockedOutStanceDefinition" + name);
- var explore_walk = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.motion.animations.MoveAnimationDefinition");
- var explore_run = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.motion.animations.MoveAnimationDefinition");
- var combat_move = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.motion.animations.MoveAnimationDefinition");
- var crouch_move = createNewDefinition("eu.cherrytree.isorpg.map.objects.dynamic.motion.animations.MoveAnimationDefinition");
- setFloat(explore_walk, "moveSpeed", move_data.walk);
- setFloat(explore_run, "moveSpeed", move_data.run);
- setFloat(combat_move, "moveSpeed", move_data.combat);
- setFloat(crouch_move, "moveSpeed", move_data.crouch);
- setPosition(explore_walk, 650, 0);
- setPosition(explore_run, 650, 0);
- setPosition(combat_move, 650, 0);
- setPosition(crouch_move, 650, 0);
- generateUUID(explore_walk, "MoveAnimationDefinition" + "explore_walk" + name);
- generateUUID(explore_run, "MoveAnimationDefinition" + "explore_run" + name);
- generateUUID(combat_move, "MoveAnimationDefinition" + "combat_move" + name);
- generateUUID(crouch_move, "MoveAnimationDefinition" + "crouch_move" + name);
- var explore_walk_anim = findDefinition(animations, stance_data.exploreWalk);
- var explore_run_anim = findDefinition(animations, stance_data.exploreRun);
- var combat_move_anim = findDefinition(animations, stance_data.combatMove);
- var crouch_move_anim = findDefinition(animations, stance_data.crouchMove);
- var explore_idle_anim = findDefinition(animations, stance_data.exploreIdle);
- var combat_idle_anim = findDefinition(animations, stance_data.combatIdle);
- var crouch_idle_anim = findDefinition(animations, stance_data.crouchIdle);
- var ko_idle_anim = findDefinition(animations, stance_data.koIdle);
- setLink(explore_walk, "movement", explore_walk_anim);
- setLink(explore_run, "movement", explore_run_anim);
- setLink(combat_move, "movement", combat_move_anim);
- setLink(crouch_move, "movement", crouch_move_anim);
- setLink(exploration, "idle", explore_idle_anim);
- setLink(combat, "idle", combat_idle_anim);
- setLink(crouch, "idle", crouch_idle_anim);
- setLink(ko, "idle", ko_idle_anim);
- setLink(exploration, "walkAnimation", explore_walk);
- setLink(exploration, "runAnimation", explore_run);
- setLink(combat, "moveAnimation", combat_move);
- setLink(crouch, "moveAnimation", crouch_move);
- setLink(control, "explorationStance", exploration);
- setLink(control, "combatStance", combat);
- setLink(control, "crouchStance", crouch);
- setLink(control, "knockedOutStance", ko);
- var transitions = [];
- for (var i in transition_data)
- transitions.push(createTransition(transition_data[i].from, transition_data[i].to, name, transition_data[i].anim, animations));
- setLinkArray(control, "stanceTransitions", transitions);
- var array = [ control, exploration, explore_walk, explore_run, combat, combat_move, crouch, crouch_move, ko ];
- array = array.concat(transitions);
- saveZone(array, tgt + ".zone");
- }
- //--------------------------------------------------------------------------
Editor
You can edit this paste and save as new: