private void PackStateChanges(PackedAnimation packedAnimation, TRAnimation animation) { for (int stateChangeIndex = 0; stateChangeIndex < animation.NumStateChanges; stateChangeIndex++) { TRStateChange stateChange = Level.StateChanges[animation.StateChangeOffset + stateChangeIndex]; packedAnimation.StateChanges.Add(stateChange); int dispatchOffset = stateChange.AnimDispatch; for (int i = 0; i < stateChange.NumAnimDispatches; i++, dispatchOffset++) { if (!packedAnimation.AnimationDispatches.ContainsKey(dispatchOffset)) { TRAnimDispatch dispatch = Level.AnimDispatches[dispatchOffset]; packedAnimation.AnimationDispatches[dispatchOffset] = dispatch; } } } }
private void UnpackStateChanges(PackedAnimation packedAnimation) { if (packedAnimation.Animation.NumStateChanges == 0) { if (packedAnimation.AnimationDispatches.Count != 0) { throw new Exception(); } return; } // Import the AnimDispatches first, noting their new indices List <TRAnimDispatch> animDispatches = Level.AnimDispatches.ToList(); Dictionary <int, int> indexMap = new Dictionary <int, int>(); foreach (int oldDispatchIndex in packedAnimation.AnimationDispatches.Keys) { TRAnimDispatch dispatch = packedAnimation.AnimationDispatches[oldDispatchIndex]; indexMap[oldDispatchIndex] = animDispatches.Count; animDispatches.Add(dispatch); // The dispatch's NextAnimation will need to be remapped, but this is handled in Import above // once all animations are in place. } // The animation's StateChangeOffset will be the current length of level StateChanges List <TRStateChange> stateChanges = Level.StateChanges.ToList(); packedAnimation.Animation.StateChangeOffset = (ushort)stateChanges.Count; // Import Each state change, re-mapping AnimDispatch to new index foreach (TRStateChange stateChange in packedAnimation.StateChanges) { stateChange.AnimDispatch = (ushort)indexMap[stateChange.AnimDispatch]; stateChanges.Add(stateChange); } // Save back to the level Level.AnimDispatches = animDispatches.ToArray(); Level.NumAnimDispatches = (uint)animDispatches.Count; Level.StateChanges = stateChanges.ToArray(); Level.NumStateChanges = (uint)stateChanges.Count; }