1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 09:32:55 +08:00

Fixed ApplyStateChange to happen in correct order

This commit is contained in:
Terochi 2023-04-30 02:01:18 +02:00
parent 9a9e02b110
commit 8ec2154965

View File

@ -62,19 +62,8 @@ namespace osu.Game.Overlays.SkinEditor
// Store indexes based on type for later lookup // Store indexes based on type for later lookup
var skinnableInfoIndexes = new Dictionary<Type, List<int>>();
var targetComponentsIndexes = new Dictionary<Type, List<int>>(); var targetComponentsIndexes = new Dictionary<Type, List<int>>();
for (int i = 0; i < skinnableInfos.Length; i++)
{
Type lookup = skinnableInfos[i].Type;
if (!skinnableInfoIndexes.TryGetValue(lookup, out List<int>? infoIndexes))
skinnableInfoIndexes.Add(lookup, infoIndexes = new List<int>());
infoIndexes.Add(i);
}
for (int i = 0; i < targetComponents.Length; i++) for (int i = 0; i < targetComponents.Length; i++)
{ {
Type lookup = targetComponents[i].GetType(); Type lookup = targetComponents[i].GetType();
@ -85,35 +74,34 @@ namespace osu.Game.Overlays.SkinEditor
componentIndexes.Add(i); componentIndexes.Add(i);
} }
foreach ((Type lookup, List<int> infoIndexes) in skinnableInfoIndexes) var indexCounting = new Dictionary<Type, int>();
var empty = new List<int>(0);
for (int i = 0; i < skinnableInfos.Length; i++)
{ {
Type lookup = skinnableInfos[i].Type;
if (!targetComponentsIndexes.TryGetValue(lookup, out List<int>? componentIndexes)) if (!targetComponentsIndexes.TryGetValue(lookup, out List<int>? componentIndexes))
componentIndexes = new List<int>(0); componentIndexes = empty;
int j = 0; if (!indexCounting.ContainsKey(lookup))
indexCounting.Add(lookup, 0);
for (int i = 0; i < infoIndexes.Count; i++) if (i >= componentIndexes.Count)
{ // Add new component
if (i >= componentIndexes.Count) firstTarget.Add((ISerialisableDrawable)skinnableInfos[i].CreateInstance());
// Add new component else
firstTarget.Add((ISerialisableDrawable)skinnableInfos[infoIndexes[i]].CreateInstance()); // Modify existing component
else ((Drawable)targetComponents[componentIndexes[indexCounting[lookup]++]]).ApplySerialisedInfo(skinnableInfos[i]);
// Modify existing component
((Drawable)targetComponents[componentIndexes[j++]]).ApplySerialisedInfo(skinnableInfos[infoIndexes[i]]);
}
// Remove extra components
for (; j < componentIndexes.Count; j++)
firstTarget.Remove(targetComponents[componentIndexes[j]], false);
} }
foreach ((Type lookup, List<int> componentIndexes) in targetComponentsIndexes) foreach ((Type lookup, List<int> componentIndexes) in targetComponentsIndexes)
{ {
if (skinnableInfoIndexes.ContainsKey(lookup)) indexCounting.TryGetValue(lookup, out int i);
continue;
// Remove extra components that weren't removed above // Remove extra components that weren't removed above
for (int i = 0; i < componentIndexes.Count; i++) for (; i < componentIndexes.Count; i++)
firstTarget.Remove(targetComponents[componentIndexes[i]], false); firstTarget.Remove(targetComponents[componentIndexes[i]], false);
} }
} }