Skip to content

Commit

Permalink
Revert "Fix B- and C-sides being visible for maps that define them vi…
Browse files Browse the repository at this point in the history
…a meta.yaml"

This reverts commit efcfcb5.
  • Loading branch information
maddie480 committed Aug 24, 2024
1 parent 163eb6d commit 5ed0e8d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
41 changes: 18 additions & 23 deletions Celeste.Mod.mm/Patches/AreaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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++) {
Expand All @@ -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;

Expand All @@ -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();
Expand Down
19 changes: 8 additions & 11 deletions Celeste.Mod.mm/Patches/MapData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -195,19 +195,19 @@ 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<MapMeta>();
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;
}
}

// 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;
}

Expand All @@ -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.
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -290,7 +288,6 @@ public static void ParseTags(BinaryPacker.Element child, Backdrop backdrop) {
}
}
}

public static class MapDataExt {

// Mods can't access patch_ classes directly.
Expand Down

0 comments on commit 5ed0e8d

Please sign in to comment.