Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions Code/Entities/ColorSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ public class ColorSwitch : Solid
private int nextColorIndex = 0;
private readonly bool singleColor, random;

private readonly bool holdableActivated;

public ColorSwitch(EntityData data, Vector2 offset)
: this(data.Position + offset, data.Width, data.Height,
data.Bool("blue"), data.Bool("rose"), data.Bool("orange"), data.Bool("lime"), data.Bool("random"))
data.Bool("blue"), data.Bool("rose"), data.Bool("orange"), data.Bool("lime"), data.Bool("random"), data.Bool("holdableActivated"))
{ }

public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose, bool orange, bool lime, bool random)
public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose, bool orange, bool lime, bool random, bool holdableActivated)
: base(position, width, height, true)
{
this.SurfaceSoundIndex = SurfaceIndex.ZipMover;
Expand Down Expand Up @@ -78,6 +80,7 @@ public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose
SetEdgeColor(this.EdgeColor, this.EdgeColor);
SetBackgroundColor(col, col);

this.holdableActivated = holdableActivated;
this.OnDashCollide = Dashed;
}

Expand Down Expand Up @@ -267,4 +270,41 @@ private void SmashParticles(Vector2 dir, ParticleType smashParticle)
num += 2;
SceneAs<Level>().Particles.Emit(smashParticle, num, position, positionRange, direction);
}

internal static class Hooks
{
public static void Hook()
{
On.Celeste.TheoCrystal.OnCollideH += TheoCrystal_OnCollideH;
On.Celeste.TheoCrystal.OnCollideV += TheoCrystal_OnCollideV;
On.Celeste.Glider.OnCollideH += Glider_OnCollideH;
On.Celeste.Glider.OnCollideV += Glider_OnCollideV;
}

public static void Unhook()
{
On.Celeste.TheoCrystal.OnCollideH -= TheoCrystal_OnCollideH;
On.Celeste.TheoCrystal.OnCollideV -= TheoCrystal_OnCollideV;
On.Celeste.Glider.OnCollideH -= Glider_OnCollideH;
On.Celeste.Glider.OnCollideV -= Glider_OnCollideV;
}

private static void ActivateSwitch(Action callOrig, CollisionData data, Func<bool> speedChecker)
{
if (data.Hit is ColorSwitch colorSwitch
&& colorSwitch.holdableActivated
&& !colorSwitch.colors[colorSwitch.nextColorIndex].IsActive()
&& speedChecker())
{
colorSwitch.Switch(data.Direction);
}

callOrig();
}

private static void TheoCrystal_OnCollideH(On.Celeste.TheoCrystal.orig_OnCollideH orig, TheoCrystal self, CollisionData data) => ActivateSwitch(() => orig(self, data), data, () => true);
private static void TheoCrystal_OnCollideV(On.Celeste.TheoCrystal.orig_OnCollideV orig, TheoCrystal self, CollisionData data) => ActivateSwitch(() => orig(self, data), data, () => self.Speed.Y > 160f || self.Speed.Y < 0f);
private static void Glider_OnCollideH(On.Celeste.Glider.orig_OnCollideH orig, Glider self, CollisionData data) => ActivateSwitch(() => orig(self, data), data, () => true);
private static void Glider_OnCollideV(On.Celeste.Glider.orig_OnCollideV orig, Glider self, CollisionData data) => ActivateSwitch(() => orig(self, data), data, () => self.Speed.Y < 0f);
}
}
50 changes: 50 additions & 0 deletions Code/Entities/ColorSwitchFlagsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Monocle;
using Microsoft.Xna.Framework;
using System.Collections.Generic;

namespace Celeste.Mod.VortexHelper.Entities;

public class ColorSwitchFlagsController : Entity
{
private static readonly Dictionary<VortexHelperSession.SwitchBlockColor, string> colorsToFlagNames = new() {
{ VortexHelperSession.SwitchBlockColor.Blue, "VortexHelper/SwitchBlockColor_Blue" },
{ VortexHelperSession.SwitchBlockColor.Rose, "VortexHelper/SwitchBlockColor_Rose" },
{ VortexHelperSession.SwitchBlockColor.Lime, "VortexHelper/SwitchBlockColor_Lime" },
{ VortexHelperSession.SwitchBlockColor.Orange, "VortexHelper/SwitchBlockColor_Orange" },
};

public ColorSwitchFlagsController() : base(Vector2.Zero)
{
Depth = -int.MaxValue; // update last
Tag = Tags.Global | Tags.TransitionUpdate;
}

public override void Update()
{
Session session = SceneAs<Level>().Session;
VortexHelperSession.SwitchBlockColor current = VortexHelperModule.SessionProperties.SessionSwitchBlockColor;

foreach (var color in colorsToFlagNames)
{
if (current != color.Key && session.GetFlag(color.Value))
session.SetFlag(color.Value, false);
else if (current == color.Key && !session.GetFlag(color.Value))
session.SetFlag(color.Value, true);
}
}

internal static class Hooks
{
public static void Hook()
{
Everest.Events.LevelLoader.OnLoadingThread += OnLoadingThread;
}

public static void Unhook()
{
Everest.Events.LevelLoader.OnLoadingThread -= OnLoadingThread;
}

private static void OnLoadingThread(Level level) => level.Add(new ColorSwitchFlagsController());
}
}
6 changes: 5 additions & 1 deletion Code/VortexHelperModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ public override void Load()
BowlPuffer.Hooks.Hook();
PufferBarrierRenderer.Hooks.Hook();
StaticMoverWithLiftSpeed.Hooks.Hook();
ColorSwitch.Hooks.Hook();
ColorSwitchFlagsController.Hooks.Hook();
MiscHooks.Hook();

Util.LoadDelegates();

typeof(GravityHelperInterop.Imports).ModInterop();
}

Expand All @@ -84,6 +86,8 @@ public override void Unload()
BowlPuffer.Hooks.Unhook();
PufferBarrierRenderer.Hooks.Unhook();
StaticMoverWithLiftSpeed.Hooks.Unhook();
ColorSwitch.Hooks.Unhook();
ColorSwitchFlagsController.Hooks.Unhook();
MiscHooks.Unhook();
}

Expand Down
12 changes: 10 additions & 2 deletions Loenn/entities/color_switch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ colorSwitch.name = "VortexHelper/ColorSwitch"
colorSwitch.resizable = {true, true}
colorSwitch.minimumSize = {16, 16}

colorSwitch.fieldOrder = {
"x", "y", "width", "height",
"blue", "rose", "orange", "lime", "random",
"holdableActivated"
}

colorSwitch.placements = {
{
name = "all_cycle",
Expand All @@ -17,7 +23,8 @@ colorSwitch.placements = {
rose = true,
orange = true,
lime = true,
random = false
random = false,
holdableActivated = false
}
},
{
Expand All @@ -29,7 +36,8 @@ colorSwitch.placements = {
rose = true,
orange = true,
lime = true,
random = true
random = true,
holdableActivated = false
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Loenn/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ entities.VortexHelper/ColorSwitch.attributes.description.rose=Enables switch to
entities.VortexHelper/ColorSwitch.attributes.description.orange=Enables switch to ORANGE through this Color Switch.
entities.VortexHelper/ColorSwitch.attributes.description.lime=Enables switch to LIME through this Color Switch.
entities.VortexHelper/ColorSwitch.attributes.description.random=Makes this Color Switch randomly pick one of its enabled colors.
entities.VortexHelper/ColorSwitch.attributes.description.holdableActivated=Makes collisions with holdables (Jellyfish and Theo Crystals) activate this Color Switch.

# Vortex Switch Gate
entities.VortexHelper/VortexSwitchGate.placements.name.crush=Custom Switch Gate (Crush)
Expand Down
Loading