Skip to content

Commit f758a33

Browse files
committed
Add Remove Light Source Trigger
When inside, deactivates all BloomPoints and LightVertexes in the current screen. Upon exiting, all become reactivated. If it is marked as persistent, the lights will ALWAYS stay off in every room in that level once the player goes inside of the trigger. (Including after S&Q's and room transitions)
1 parent a3e0c95 commit f758a33

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

Ahorn/lang/en_gb.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ placements.triggers.SpringCollab2020/SmoothCameraOffsetTrigger.tooltips.offsetYT
2727
placements.triggers.SpringCollab2020/SmoothCameraOffsetTrigger.tooltips.positionMode=The fade direction.
2828
placements.triggers.SpringCollab2020/SmoothCameraOffsetTrigger.tooltips.onlyOnce=If checked, the trigger will be disabled when the player first leaves it.
2929

30+
# Remove Light Sources Trigger
31+
placements.triggers.SpringCollab2020/RemoveLightSourcesTrigger.tooltips.isPersistent=If checked, all light sources will stay disabled even after leaving the trigger.
32+
3033
# Dash Spring
3134
placements.entities.SpringCollab2020/dashSpring.tooltips.playerCanUse=Determines whether the player is able to interact with the spring.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module SpringCollab2020RemoveLightSources
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Trigger "SpringCollab2020/RemoveLightSourcesTrigger" RemoveLightSourcesTrigger(x::Integer, y::Integer, width::Integer=Maple.defaultTriggerWidth, height::Integer=Maple.defaultTriggerHeight, isPersistent::Bool=true)
6+
7+
const placements = Ahorn.PlacementDict(
8+
"Remove Light Sources (Spring Collab 2020)" => Ahorn.EntityPlacement(
9+
RemoveLightSourcesTrigger,
10+
"rectangle",
11+
),
12+
)
13+
14+
end

SpringCollab2020Module.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ public SpringCollab2020Module() {
1313
public override void Load() {
1414
NoRefillField.Load();
1515
FloatierSpaceBlock.Load();
16+
RemoveLightSourcesTrigger.Load();
1617
}
1718

1819
public override void Unload() {
1920
NoRefillField.Unload();
2021
FloatierSpaceBlock.Unload();
22+
RemoveLightSourcesTrigger.Unload();
2123
}
2224
}
2325
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using Celeste.Mod.Entities;
2+
using Monocle;
3+
using Microsoft.Xna.Framework;
4+
using System.Collections.Generic;
5+
6+
namespace Celeste.Mod.SpringCollab2020.Triggers {
7+
8+
[CustomEntity("SpringCollab2020/RemoveLightSourcesTrigger")]
9+
[Tracked]
10+
class RemoveLightSourcesTrigger : Trigger {
11+
public RemoveLightSourcesTrigger(EntityData data, Vector2 offset) : base(data, offset) {
12+
IsPersistent = data.Bool("isPersistent", true);
13+
level = SceneAs<Level>();
14+
}
15+
16+
public static void Load() {
17+
Everest.Events.Level.OnLoadLevel += LevelLoadHandler;
18+
Everest.Events.Level.OnExit += OnExitHandler;
19+
}
20+
21+
public static void Unload() {
22+
Everest.Events.Level.OnLoadLevel -= LevelLoadHandler;
23+
Everest.Events.Level.OnExit -= OnExitHandler;
24+
}
25+
26+
private static void LevelLoadHandler(Level loadedLevel, Player.IntroTypes playerIntro, bool isFromLoader) {
27+
if(loadedLevel.Session.GetFlag("lightsDisabled") == true)
28+
DisableAllLights(loadedLevel);
29+
30+
if (loadedLevel.Session.GetFlag("lightsDisabled") == true)
31+
On.Celeste.Level.TransitionTo += TransitionLightSources;
32+
}
33+
34+
private static void OnExitHandler(Level exitLevel, LevelExit exit, LevelExit.Mode mode, Session session, HiresSnow snow) {
35+
On.Celeste.Level.TransitionTo -= TransitionLightSources;
36+
}
37+
38+
private static void TransitionLightSources(On.Celeste.Level.orig_TransitionTo orig, Level transitionLevel, LevelData next, Vector2 direction) {
39+
lightSources = new List<Component>();
40+
bloomSources = new List<Component>();
41+
42+
DisableAllLights(transitionLevel);
43+
orig(transitionLevel, next, direction);
44+
}
45+
46+
private static void DisableAllLights(Level disableLevel) {
47+
EntityList entities = disableLevel.Entities;
48+
49+
foreach (Entity entity in entities) {
50+
foreach (Component component in entity.Components.ToArray()) {
51+
if (component is VertexLight) {
52+
lightSources.Add(component);
53+
component.Visible = false;
54+
}
55+
56+
if (component is BloomPoint) {
57+
bloomSources.Add(component);
58+
component.Visible = false;
59+
}
60+
}
61+
}
62+
}
63+
64+
public override void OnEnter(Player player) {
65+
base.OnEnter(player);
66+
67+
level = SceneAs<Level>();
68+
69+
if (IsPersistent && level.Session.GetFlag("lightsDisabled") == false)
70+
On.Celeste.Level.TransitionTo += TransitionLightSources;
71+
72+
if (IsPersistent)
73+
level.Session.SetFlag("lightsDisabled", true);
74+
75+
DisableAllLights(level);
76+
}
77+
78+
public override void OnLeave(Player player) {
79+
base.OnLeave(player);
80+
81+
if (IsPersistent || level.Session.GetFlag("lightsDisabled") == true)
82+
return;
83+
84+
foreach (Component component in lightSources)
85+
component.Visible = true;
86+
87+
foreach (Component component in bloomSources)
88+
component.Visible = true;
89+
}
90+
91+
private static List<Component> lightSources = new List<Component>();
92+
93+
private static List<Component> bloomSources = new List<Component>();
94+
95+
private Level level;
96+
97+
private bool IsPersistent = true;
98+
}
99+
}

0 commit comments

Comments
 (0)