Skip to content

Commit 2e9fce5

Browse files
authored
Merge pull request #28 from EverestAPI/remove_light_sources
Add Remove Light Source Trigger
2 parents 19c40dc + 0e39e9d commit 2e9fce5

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

Ahorn/lang/en_gb.lang

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

35+
# Remove Light Sources Trigger
36+
placements.triggers.SpringCollab2020/RemoveLightSourcesTrigger.tooltips.persistent=If checked, all light sources will stay disabled even after leaving the trigger.
37+
3538
# Dash Spring
3639
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, persistent::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: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
[CustomEntity("SpringCollab2020/RemoveLightSourcesTrigger")]
8+
[Tracked]
9+
class RemoveLightSourcesTrigger : Trigger {
10+
public RemoveLightSourcesTrigger(EntityData data, Vector2 offset) : base(data, offset) {
11+
Persistent = data.Bool("persistent", true);
12+
level = SceneAs<Level>();
13+
}
14+
15+
public static void Load() {
16+
Everest.Events.Level.OnLoadLevel += LevelLoadHandler;
17+
Everest.Events.Level.OnExit += OnExitHandler;
18+
}
19+
20+
public static void Unload() {
21+
Everest.Events.Level.OnLoadLevel -= LevelLoadHandler;
22+
Everest.Events.Level.OnExit -= OnExitHandler;
23+
}
24+
25+
private static void LevelLoadHandler(Level loadedLevel, Player.IntroTypes playerIntro, bool isFromLoader) {
26+
if (loadedLevel.Session.GetFlag("lightsDisabled")) {
27+
DisableAllLights(loadedLevel);
28+
On.Celeste.Level.TransitionTo += TransitionLightSources;
29+
}
30+
}
31+
32+
private static void OnExitHandler(Level exitLevel, LevelExit exit, LevelExit.Mode mode, Session session, HiresSnow snow) {
33+
On.Celeste.Level.TransitionTo -= TransitionLightSources;
34+
}
35+
36+
private static void TransitionLightSources(On.Celeste.Level.orig_TransitionTo orig, Level transitionLevel, LevelData next, Vector2 direction) {
37+
lightSources = new List<Component>();
38+
bloomSources = new List<Component>();
39+
40+
DisableAllLights(transitionLevel);
41+
orig(transitionLevel, next, direction);
42+
}
43+
44+
private static void DisableAllLights(Level disableLevel) {
45+
EntityList entities = disableLevel.Entities;
46+
47+
foreach (Entity entity in entities) {
48+
foreach (Component component in entity.Components.ToArray()) {
49+
if (component is VertexLight) {
50+
lightSources.Add(component);
51+
component.Visible = false;
52+
}
53+
54+
if (component is BloomPoint) {
55+
bloomSources.Add(component);
56+
component.Visible = false;
57+
}
58+
}
59+
}
60+
}
61+
62+
public override void OnEnter(Player player) {
63+
base.OnEnter(player);
64+
65+
level = SceneAs<Level>();
66+
67+
if (Persistent && level.Session.GetFlag("lightsDisabled") == false)
68+
On.Celeste.Level.TransitionTo += TransitionLightSources;
69+
70+
if (Persistent)
71+
level.Session.SetFlag("lightsDisabled", true);
72+
73+
DisableAllLights(level);
74+
}
75+
76+
public override void OnLeave(Player player) {
77+
base.OnLeave(player);
78+
79+
if (Persistent || level.Session.GetFlag("lightsDisabled") == true)
80+
return;
81+
82+
foreach (Component component in lightSources)
83+
component.Visible = true;
84+
85+
foreach (Component component in bloomSources)
86+
component.Visible = true;
87+
}
88+
89+
private static List<Component> lightSources = new List<Component>();
90+
91+
private static List<Component> bloomSources = new List<Component>();
92+
93+
private Level level;
94+
95+
private bool Persistent = true;
96+
}
97+
}

0 commit comments

Comments
 (0)