Skip to content

Commit

Permalink
Merge pull request #47 from aonkeeper4/bettertemplegateallswitches
Browse files Browse the repository at this point in the history
Rework `TempleGateAllSwitches` to use the `DashSwitch`'s `OnDashCollide` instead of default `OnDashed`
catapillie authored Apr 26, 2024
2 parents 5d4a4c8 + afd4f35 commit d30d120
Showing 1 changed file with 28 additions and 39 deletions.
67 changes: 28 additions & 39 deletions Code/FLCC/TempleGateAllSwitches.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,49 @@
using Celeste;
using Celeste.Mod.Entities;
using MonoMod.Utils;
using Microsoft.Xna.Framework;
using Monocle;

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 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<Level>().Tracker.GetEntities<Solid>())
{
if (solid is DashSwitch dashSwitch)
{
if (!dashSwitch.pressed)
{
finalswitch = false;
break;
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) => {
DashCollisionResults result = orig_OnDashCollide(player, direction);
bool finalswitch = true;
if (self.pressed) {
foreach (Solid solid in self.SceneAs<Level>().Tracker.GetEntities<Solid>()) {
if (solid is DashSwitch dashSwitch) {
if (!dashSwitch.pressed) {
finalswitch = false;
break;
}
}
}
} else {
finalswitch = false;
}
}
else
{
finalswitch = false;
}
if (finalswitch)
{
foreach (TempleGateAllSwitches gate in self.SceneAs<Level>().Tracker.GetEntities<TempleGateAllSwitches>())
{
gate.Open();
if (finalswitch) {
foreach (TempleGateAllSwitches gate in self.SceneAs<Level>().Tracker.GetEntities<TempleGateAllSwitches>()) {
gate.Open();
}
}
}
return result;
return result;
};
}
}
}

0 comments on commit d30d120

Please sign in to comment.