MontyTRC89 / Tomb-Editor

Tomb Editor
55 stars 15 forks source link

WT: Swap animations #844

Open Sezzary opened 1 month ago

Sezzary commented 1 month ago

In WT, reordering animations is impossible without manually tracking all links and state dispatches. An automated swap feature would be useful to aid in keeping things organised when working on new animations. Possible placement for the tool could be in the Animations drop-down menu in the top row.

I don't know how to make the appropriate UI changes, but functionally the swap can work like this in the wad animation object:

public void SwapAnimations(ushort animNumber0, ushort animNumber1)
 {
     foreach (var animation in Animations)
     {
         // Update next animation.
         if (animation.NextAnimation == animNumber0)
         {
             animation.NextAnimation = animNumber1;
         }
         else if (animation.NextAnimation == animNumber1)
         {
             animation.NextAnimation = animNumber0;
         }

         // Update next animations in state dispatches.
         foreach (var stateChange in animation.StateChanges)
         {
             foreach (var dispatch in stateChange.Dispatches)
             {
                 if (dispatch.NextAnimation == animNumber0)
                 {
                     dispatch.NextAnimation = animNumber1;
                 }
                 else if (dispatch.NextAnimation == animNumber1)
                 {
                     dispatch.NextAnimation = animNumber0;
                 }
             }
         }
     }
 }