diff --git a/src/HexManiac.Core/ViewModels/DexReorderTab.cs b/src/HexManiac.Core/ViewModels/DexReorderTab.cs index f631559f..112928d6 100644 --- a/src/HexManiac.Core/ViewModels/DexReorderTab.cs +++ b/src/HexManiac.Core/ViewModels/DexReorderTab.cs @@ -97,6 +97,16 @@ namespace HavenSoft.HexManiac.Core.ViewModels { Debug.Assert(Elements.All(item => item != null), "Dex Reorder only works if there are no empty pokedex slots!"); } + private static IDictionary Diff(IList oldList, IList newList) where T : IEquatable { + var result = new Dictionary(); + Debug.Assert(oldList.Count == newList.Count, "Cannot diff lists unless they're the same length!"); + for (int i = 0; i < oldList.Count; i++) { + if (oldList[i].Equals(newList[i])) continue; + result[i] = (oldList[i], newList[i]); + } + return result; + } + private void UpdateDexFromSortOrder() { var token = history.CurrentChange; // Elements is in the new desired pokedex order @@ -134,7 +144,11 @@ namespace HavenSoft.HexManiac.Core.ViewModels { } } } - model.WriteMultiByteValue(dexOrder.Start + dexOrder.ElementLength * (i - 1), 2, token, newOrder[i - 1]); + } + + for (int i = 0; i < newOrder.Count; i++) { + int start = dexOrder.Start + dexOrder.ElementLength * i; + model.WriteMultiByteValue(start, dexOrder.ElementContent[0].Length, token, newOrder[i]); } // restore dexInfo format