diff --git a/Celeste.Mod.mm/Patches/AreaData.cs b/Celeste.Mod.mm/Patches/AreaData.cs index c4aeadde9..9ac537f37 100644 --- a/Celeste.Mod.mm/Patches/AreaData.cs +++ b/Celeste.Mod.mm/Patches/AreaData.cs @@ -300,12 +300,21 @@ public static patch_AreaData Get(string sid) { // Sort areas. Areas.Sort(AreaComparison); + // Remove AreaDatas which are now a mode of another AreaData. + // This can happen late as the map data (.bin) can contain additional metadata. for (int i = 0; i < Areas.Count; i++) { - // Check for .bins possibly belonging to A side .bins by their path and lack of existing modes. patch_AreaData area = Areas[i]; string path = area.Mode[0].Path; + int otherIndex = Areas.FindIndex(other => other.Mode.Any(otherMode => otherMode?.Path == path)); + if (otherIndex != -1 && otherIndex != i) { + Areas.RemoveAt(i); + i--; + continue; + } + ParseName(path, out int? order, out AreaMode side, out string name); + // Also check for .bins possibly belonging to A side .bins by their path and lack of existing modes. for (int ii = 0; ii < Areas.Count; ii++) { patch_AreaData other = Areas[ii]; ParseName(other.Mode[0].Path, out int? otherOrder, out AreaMode otherSide, out string otherName); @@ -329,12 +338,6 @@ public static patch_AreaData Get(string sid) { patch_AreaData area = Areas[i]; area.ID = i; - // Add the A side MapData or update its area key. - if (area.Mode[0].MapData != null) - area.Mode[0].MapData.Area = area.ToKey(); - else - area.Mode[0].MapData = new patch_MapData(area.ToKey()); - // Clean up non-existing modes. int modei = 0; for (; modei < area.Mode.Length; modei++) { @@ -346,6 +349,14 @@ public static patch_AreaData Get(string sid) { Logger.Verbose("AreaData", string.Format("{0}: {1} - {2} sides", i, area.SID, area.Mode.Length)); + // Update old MapData areas and load any new areas. + + // Add the A side MapData or update its area key. + if (area.Mode[0].MapData != null) + area.Mode[0].MapData.Area = area.ToKey(); + else + area.Mode[0].MapData = new patch_MapData(area.ToKey()); + if (area.IsInterludeUnsafe()) continue; @@ -369,22 +380,6 @@ public static patch_AreaData Get(string sid) { } } - for (int i = 0; i < Areas.Count; i++) { - // Remove AreaDatas which are now a mode of another AreaData. - // This can happen late as the map data (.bin) can contain additional metadata. - patch_AreaData area = Areas[i]; - string path = area.Mode[0].Path; - int otherIndex = Areas.FindIndex(other => other.Mode.Any(otherMode => otherMode?.Path == path)); - if (otherIndex != -1 && otherIndex != i) { - Logger.Verbose("AreaData", $"Removing area {i} since it has the same path {path} as one of area {otherIndex}'s modes"); - Areas.RemoveAt(i); - i--; - } - } - for (int i = 0; i < Areas.Count; i++) { - Areas[i].ID = i; - } - // Load custom mountains // This needs to be done after areas are loaded because it depends on the MapMeta MTNExt.LoadMod(); diff --git a/Celeste.Mod.mm/Patches/MapData.cs b/Celeste.Mod.mm/Patches/MapData.cs index 78dd54a28..683e78b71 100644 --- a/Celeste.Mod.mm/Patches/MapData.cs +++ b/Celeste.Mod.mm/Patches/MapData.cs @@ -30,8 +30,8 @@ public MapMetaModeProperties Meta { MapMeta metaAll = patch_AreaData.Get(Area).Meta; return (metaAll?.Modes?.Length ?? 0) > (int) Area.Mode ? - metaAll.Modes[(int) Area.Mode] : - null; + metaAll.Modes[(int) Area.Mode] : + null; } } @@ -195,11 +195,11 @@ private void ProcessMeta(BinaryPacker.Element meta) { MapMeta metaParsed = null; // load metadata from .meta.yaml file - string path = $"Maps/{area.Mode[(int) mode].Path}"; + string path = $"Maps/{area.Mode[(int)mode].Path}"; if (Everest.Content.TryGet(path, out ModAsset asset)) { metaParsedFromFile = asset.GetMeta(); if (metaParsedFromFile != null) { - metaParsedFromFile.Modes[(int) mode] = MapMetaModeProperties.Add(metaParsedFromFile.Mode, metaParsedFromFile.Modes[(int) mode]); + metaParsedFromFile.Modes[(int)mode] = MapMetaModeProperties.Add(metaParsedFromFile.Mode, metaParsedFromFile.Modes[(int)mode]); metaParsedFromFile.Mode = null; } } @@ -207,7 +207,7 @@ private void ProcessMeta(BinaryPacker.Element meta) { // load metadata from .bin file if (meta != null) { metaParsed = new MapMeta(meta); - metaParsed.Modes[(int) mode] = MapMetaModeProperties.Add(metaParsed.Mode, metaParsed.Modes[(int) mode]); + metaParsed.Modes[(int)mode] = MapMetaModeProperties.Add(metaParsed.Mode, metaParsed.Modes[(int)mode]); metaParsed.Mode = null; } @@ -217,9 +217,7 @@ private void ProcessMeta(BinaryPacker.Element meta) { // apply metadata to AreaData if (mode == AreaMode.Normal) { metaParsed.ApplyTo(area); - for (int i = 0; i < metaParsed.Modes.Length; i++) { - metaParsed.Modes[i]?.ApplyTo(area, (AreaMode) i); - } + metaParsed.Modes[(int)mode]?.ApplyTo(area, mode); Area = area.ToKey(); // Backup A-Side's Metadata. Only back up useful data. @@ -234,8 +232,8 @@ private void ProcessMeta(BinaryPacker.Element meta) { }; } else { MapMeta combinedMeta = MapMeta.Add(metaParsed, area.Meta); - area.Mode[(int) mode].MapMeta = combinedMeta; - combinedMeta.Modes[(int) mode]?.ApplyTo(area, mode); + area.Mode[(int)mode].MapMeta = combinedMeta; + combinedMeta.Modes[(int)mode]?.ApplyTo(area, mode); } } @@ -290,7 +288,6 @@ public static void ParseTags(BinaryPacker.Element child, Backdrop backdrop) { } } } - public static class MapDataExt { // Mods can't access patch_ classes directly.