Skip to content

Commit 7962df3

Browse files
committed
Unlock player movement on reload if in-game overworld was open + close in-game overworld if player dies
1 parent faed662 commit 7962df3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

UI/InGameOverworldHelper.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public static void Load() {
4545
IL.Celeste.StrawberriesCounter.Render += ModStrawberriesCounterRender;
4646
On.Celeste.MapData.Load += ModMapDataLoad;
4747
On.Celeste.OuiChapterPanel.Start += OnOuiChapterPanelStart;
48+
On.Celeste.Player.Die += OnPlayerDie;
49+
On.Celeste.Mod.AssetReloadHelper.ReloadLevel += OnReloadLevel;
4850
}
4951

5052
public static void Unload() {
@@ -63,6 +65,8 @@ public static void Unload() {
6365
IL.Celeste.StrawberriesCounter.Render -= ModStrawberriesCounterRender;
6466
On.Celeste.MapData.Load -= ModMapDataLoad;
6567
On.Celeste.OuiChapterPanel.Start -= OnOuiChapterPanelStart;
68+
On.Celeste.Player.Die -= OnPlayerDie;
69+
On.Celeste.Mod.AssetReloadHelper.ReloadLevel -= OnReloadLevel;
6670
}
6771

6872
private static void OnOuiChapterPanelStart(On.Celeste.OuiChapterPanel.orig_Start orig, OuiChapterPanel self, string checkpoint) {
@@ -77,6 +81,35 @@ private static void OnPause(Level level, int startIndex, bool minimal, bool quic
7781
if (overworldWrapper != null) {
7882
Close(level, true, true);
7983
}
84+
}
85+
86+
private static PlayerDeadBody OnPlayerDie(On.Celeste.Player.orig_Die orig, Player self, Vector2 direction, bool evenIfInvincible, bool registerDeathInStats) {
87+
PlayerDeadBody result = orig(self, direction, evenIfInvincible, registerDeathInStats);
88+
if (result != null && self.Scene is Level level && overworldWrapper != null) {
89+
// the player died, so we should close the "in-game overworld" before weird stuff happens.
90+
Close(level, true, true);
91+
}
92+
return result;
93+
}
94+
95+
private static void OnReloadLevel(On.Celeste.Mod.AssetReloadHelper.orig_ReloadLevel orig) {
96+
if (overworldWrapper != null) {
97+
Level level = Engine.Scene as Level;
98+
if (level == null) {
99+
level = AssetReloadHelper.ReturnToScene as Level;
100+
}
101+
102+
if (level != null) {
103+
// the level is about to get reloaded: make sure to unlock player movement if it is locked.
104+
// (no need to close the in-game overworld, the reload will do that for us.)
105+
Player player = level.Tracker.GetEntity<Player>();
106+
if (player != null && player.StateMachine.State == Player.StDummy) {
107+
player.StateMachine.State = Player.StNormal;
108+
}
109+
}
110+
}
111+
112+
orig();
80113
}
81114

82115
private static bool OnSetMusic(On.Celeste.Audio.orig_SetMusic orig, string path, bool startPlaying, bool allowFadeOut) {

UI/ReturnToLobbyHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ private static IEnumerator modChapterPanelStartRoutine(On.Celeste.OuiChapterPane
5151
Player player = Engine.Scene.Tracker.GetEntity<Player>();
5252
if (player != null) {
5353
temporarySpawnPointHolder = (Engine.Scene as Level).GetSpawnPoint(player.Position);
54+
} else {
55+
// player is dead, presumably? AAAAA
56+
// let's use camera position instead.
57+
temporarySpawnPointHolder = (Engine.Scene as Level).GetSpawnPoint((Engine.Scene as Level).Camera.Position + new Vector2(320 / 2, 180 / 2));
5458
}
5559
} else if (returnToLobbyMode == ChapterPanelTrigger.ReturnToLobbyMode.RemoveReturn) {
5660
// make sure the "temporary" variables are empty.

0 commit comments

Comments
 (0)