From 9d133976fbe00fa0509b0e874c9f36393c339966 Mon Sep 17 00:00:00 2001 From: aonkeeper4 Date: Thu, 18 Apr 2024 23:17:08 +0100 Subject: [PATCH 1/2] Rework `TempleGateAllSwitches` to use the `DashSwitch`'s `OnDashCollide` instead of default `OnDashed` --- Code/FLCC/TempleGateAllSwitches.cs | 78 +++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/Code/FLCC/TempleGateAllSwitches.cs b/Code/FLCC/TempleGateAllSwitches.cs index 9157913..6862312 100644 --- a/Code/FLCC/TempleGateAllSwitches.cs +++ b/Code/FLCC/TempleGateAllSwitches.cs @@ -3,6 +3,10 @@ using MonoMod.Utils; using Microsoft.Xna.Framework; using Monocle; +using System; +using System.IO; +using System.Runtime.CompilerServices; +using Celeste.Mod; namespace vitmod { @@ -17,44 +21,74 @@ public TempleGateAllSwitches(EntityData data, Vector2 offset) : base(data.Positi public static void Load() { - On.Celeste.DashSwitch.OnDashed += DashSwitch_OnDashed; + // On.Celeste.DashSwitch.OnDashed += DashSwitch_OnDashed; + On.Celeste.DashSwitch.Awake += DashSwitch_Awake; } public static void Unload() { - On.Celeste.DashSwitch.OnDashed -= DashSwitch_OnDashed; + // On.Celeste.DashSwitch.OnDashed -= DashSwitch_OnDashed; + On.Celeste.DashSwitch.Awake -= DashSwitch_Awake; } - private static DashCollisionResults DashSwitch_OnDashed(On.Celeste.DashSwitch.orig_OnDashed orig, DashSwitch self, Player player, Vector2 direction) + private static void DashSwitch_Awake(On.Celeste.DashSwitch.orig_Awake orig, DashSwitch self, Scene scene) { - DashCollisionResults result = orig(self, player, direction); - bool finalswitch = true; - if (self.pressed) + orig(self, scene); + DashCollision orig_OnDashCollide = self.OnDashCollide; + self.OnDashCollide = (Player player, Vector2 direction) => { - foreach (Solid solid in self.SceneAs().Tracker.GetEntities()) + DashCollisionResults result = orig_OnDashCollide(player, direction); + bool finalswitch = true; + if (self.pressed) { - if (solid is DashSwitch dashSwitch) + foreach (Solid solid in self.SceneAs().Tracker.GetEntities()) { - if (!dashSwitch.pressed) + if (solid is DashSwitch dashSwitch) { - finalswitch = false; - break; + if (!dashSwitch.pressed) + { + finalswitch = false; + break; + } } } } - } - else - { - finalswitch = false; - } - if (finalswitch) - { - foreach (TempleGateAllSwitches gate in self.SceneAs().Tracker.GetEntities()) + else { - gate.Open(); + finalswitch = false; } - } - return result; + if (finalswitch) + { + foreach (TempleGateAllSwitches gate in self.SceneAs().Tracker.GetEntities()) + { + gate.Open(); + } + } + return result; + }; } + + // private static DashCollisionResults DashSwitch_OnDashed(On.Celeste.DashSwitch.orig_OnDashed orig, DashSwitch self, Player player, Vector2 direction) { + // DashCollisionResults result = orig(self, player, direction); + // bool finalswitch = true; + // if (self.pressed) { + // foreach (Solid solid in self.SceneAs().Tracker.GetEntities()) { + // if (solid is DashSwitch dashSwitch) { + // if (!dashSwitch.pressed) { + // finalswitch = false; + // break; + // } + // } + // } + // } else { + // finalswitch = false; + // } + // if (finalswitch) { + // foreach (TempleGateAllSwitches gate in self.SceneAs().Tracker.GetEntities()) { + // gate.Open(); + // } + // } + // return result; + // } } } From afd4f35e750a8816585ffc82ddef278eb56f0263 Mon Sep 17 00:00:00 2001 From: aonkeeper4 Date: Thu, 18 Apr 2024 23:53:16 +0100 Subject: [PATCH 2/2] Clean up `TempleGateAllSwitches` --- Code/FLCC/TempleGateAllSwitches.cs | 73 ++++++------------------------ 1 file changed, 14 insertions(+), 59 deletions(-) diff --git a/Code/FLCC/TempleGateAllSwitches.cs b/Code/FLCC/TempleGateAllSwitches.cs index 6862312..ec62eba 100644 --- a/Code/FLCC/TempleGateAllSwitches.cs +++ b/Code/FLCC/TempleGateAllSwitches.cs @@ -1,94 +1,49 @@ using Celeste; using Celeste.Mod.Entities; -using MonoMod.Utils; using Microsoft.Xna.Framework; using Monocle; -using System; -using System.IO; -using System.Runtime.CompilerServices; -using Celeste.Mod; -namespace vitmod -{ +namespace vitmod { [Tracked()] [CustomEntity("vitellary/templegateall")] - public class TempleGateAllSwitches : TempleGate - { - public TempleGateAllSwitches(EntityData data, Vector2 offset) : base(data.Position + offset, 48, Types.NearestSwitch, data.Attr("sprite", "default"), data.Level.Name) - { + public class TempleGateAllSwitches : TempleGate { + public TempleGateAllSwitches(EntityData data, Vector2 offset) : base(data.Position + offset, 48, Types.NearestSwitch, data.Attr("sprite", "default"), data.Level.Name) { ClaimedByASwitch = true; } - public static void Load() - { - // On.Celeste.DashSwitch.OnDashed += DashSwitch_OnDashed; + public static void Load() { On.Celeste.DashSwitch.Awake += DashSwitch_Awake; } - public static void Unload() - { - // On.Celeste.DashSwitch.OnDashed -= DashSwitch_OnDashed; + public static void Unload() { On.Celeste.DashSwitch.Awake -= DashSwitch_Awake; } - private static void DashSwitch_Awake(On.Celeste.DashSwitch.orig_Awake orig, DashSwitch self, Scene scene) - { + private static void DashSwitch_Awake(On.Celeste.DashSwitch.orig_Awake orig, DashSwitch self, Scene scene) { orig(self, scene); DashCollision orig_OnDashCollide = self.OnDashCollide; - self.OnDashCollide = (Player player, Vector2 direction) => - { + self.OnDashCollide = (Player player, Vector2 direction) => { DashCollisionResults result = orig_OnDashCollide(player, direction); bool finalswitch = true; - if (self.pressed) - { - foreach (Solid solid in self.SceneAs().Tracker.GetEntities()) - { - if (solid is DashSwitch dashSwitch) - { - if (!dashSwitch.pressed) - { + if (self.pressed) { + foreach (Solid solid in self.SceneAs().Tracker.GetEntities()) { + if (solid is DashSwitch dashSwitch) { + if (!dashSwitch.pressed) { finalswitch = false; break; } } } - } - else - { + } else { finalswitch = false; } - if (finalswitch) - { - foreach (TempleGateAllSwitches gate in self.SceneAs().Tracker.GetEntities()) - { + if (finalswitch) { + foreach (TempleGateAllSwitches gate in self.SceneAs().Tracker.GetEntities()) { gate.Open(); } } return result; }; } - - // private static DashCollisionResults DashSwitch_OnDashed(On.Celeste.DashSwitch.orig_OnDashed orig, DashSwitch self, Player player, Vector2 direction) { - // DashCollisionResults result = orig(self, player, direction); - // bool finalswitch = true; - // if (self.pressed) { - // foreach (Solid solid in self.SceneAs().Tracker.GetEntities()) { - // if (solid is DashSwitch dashSwitch) { - // if (!dashSwitch.pressed) { - // finalswitch = false; - // break; - // } - // } - // } - // } else { - // finalswitch = false; - // } - // if (finalswitch) { - // foreach (TempleGateAllSwitches gate in self.SceneAs().Tracker.GetEntities()) { - // gate.Open(); - // } - // } - // return result; - // } } }