Skip to content

Commit 9e079be

Browse files
committed
add event for Level.End
closes #1041
1 parent 6c342aa commit 9e079be

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Celeste.Mod.mm/Patches/Level.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,23 +596,27 @@ public override void End() {
596596

597597
Scene nextScene = patch_Engine.NextScene;
598598

599+
bool shouldReloadPortraits = nextScene is not (LevelLoader or Pico8.Emulator or OverworldReflectionsFall);
600+
bool shouldDissociateEntities = nextScene is not (Pico8.Emulator or OverworldReflectionsFall);
601+
602+
Everest.Events.Level.End(this, nextScene, ref shouldReloadPortraits, ref shouldDissociateEntities);
603+
599604
// reload the vanilla Portraits.xml when exiting; if a map overrides the Portraits.xml
600605
// and doesn't have portrait_madeline defined, the game would crash when trying to load a save file
601606
// (since it shows madeline's portrait)
602607
//
603608
// however we need to pay attention to the new scene, else we'll reload vanilla portraits too soon
604609
// and make custom portraits stop working. therefore, we ignore these scenes as they don't actually
605610
// exit the map
606-
if (nextScene is not (LevelLoader or Pico8.Emulator or OverworldReflectionsFall)) {
611+
if (shouldReloadPortraits)
607612
GFX.PortraitsSpriteBank = new SpriteBank(GFX.Portraits, Path.Combine("Graphics", "Portraits.xml"));
608-
}
609613

610-
// if we are not entering PICO-8 or the Reflection Fall cutscene...
611-
if (nextScene is not (Pico8.Emulator or OverworldReflectionsFall)) {
614+
// if we are not entering PICO-8, the Reflection Fall cutscene, or some similar modded scene...
615+
if (shouldDissociateEntities) {
612616
// break all links between this level and its entities.
613-
foreach (Entity entity in Entities) {
617+
foreach (Entity entity in Entities)
614618
((patch_Entity) entity).DissociateFromScene();
615-
}
619+
616620
((patch_EntityList) (object) Entities).ClearEntities();
617621
}
618622
}
@@ -775,6 +779,11 @@ internal static void LoadLevel(_Level level, _Player.IntroTypes playerIntro, boo
775779
internal static void Complete(_Level level)
776780
=> OnComplete?.Invoke(level);
777781

782+
public delegate void EndHandler(_Level level, Scene nextScene, ref bool shouldReloadPortraits, ref bool shouldDissociateEntities);
783+
public static event EndHandler OnEnd;
784+
internal static void End(_Level level, Scene nextScene, ref bool shouldReloadPortraits, ref bool shouldDissociateEntities)
785+
=> OnEnd?.Invoke(level, nextScene, ref shouldReloadPortraits, ref shouldDissociateEntities);
786+
778787
/// <summary>
779788
/// Called at the very beginning of <see cref="global::Celeste.Level.Update"/>.
780789
/// </summary>

0 commit comments

Comments
 (0)