11using Celeste . Mod . Entities ;
22using Monocle ;
33using Microsoft . Xna . Framework ;
4- using System . Collections . Generic ;
4+ using System . Reflection ;
55
66namespace Celeste . Mod . SpringCollab2020 . Triggers {
77 [ CustomEntity ( "SpringCollab2020/RemoveLightSourcesTrigger" ) ]
88 [ Tracked ]
99 class RemoveLightSourcesTrigger : Trigger {
1010 public RemoveLightSourcesTrigger ( EntityData data , Vector2 offset ) : base ( data , offset ) {
11- Persistent = data . Bool ( "persistent" , true ) ;
1211 level = SceneAs < Level > ( ) ;
1312 }
1413
@@ -23,75 +22,43 @@ public static void Unload() {
2322 }
2423
2524 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- }
25+ if ( loadedLevel . Session . GetFlag ( "lightsDisabled" ) )
26+ DisableLightRender ( ) ;
3027 }
3128
3229 private static void OnExitHandler ( Level exitLevel , LevelExit exit , LevelExit . Mode mode , Session session , HiresSnow snow ) {
33- On . Celeste . Level . TransitionTo -= TransitionLightSources ;
30+ EnableLightRender ( ) ;
3431 }
3532
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 > ( ) ;
33+ private static void BloomRendererHook ( On . Celeste . BloomRenderer . orig_Apply orig , BloomRenderer self , VirtualRenderTarget target , Scene scene ) { }
3934
40- DisableAllLights ( transitionLevel ) ;
41- orig ( transitionLevel , next , direction ) ;
35+ private static void LightHook ( On . Celeste . VertexLight . orig_Update orig , VertexLight self ) {
36+ if ( self . SceneAs < Level > ( ) . Session . GetFlag ( "lightsDisabled" ) )
37+ self . Alpha = 0f ;
38+ orig ( self ) ;
4239 }
4340
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- }
41+ private static void EnableLightRender ( ) {
42+ On . Celeste . VertexLight . Update -= LightHook ;
43+ On . Celeste . BloomRenderer . Apply -= BloomRendererHook ;
44+ }
5345
54- if ( component is BloomPoint ) {
55- bloomSources . Add ( component ) ;
56- component . Visible = false ;
57- }
58- }
59- }
46+ private static void DisableLightRender ( ) {
47+ On . Celeste . VertexLight . Update += LightHook ;
48+ On . Celeste . BloomRenderer . Apply += BloomRendererHook ;
6049 }
6150
6251 public override void OnEnter ( Player player ) {
6352 base . OnEnter ( player ) ;
6453
6554 level = SceneAs < Level > ( ) ;
6655
67- if ( Persistent && level . Session . GetFlag ( "lightsDisabled" ) == false )
68- On . Celeste . Level . TransitionTo += TransitionLightSources ;
69-
70- if ( Persistent )
56+ if ( level . Session . GetFlag ( "lightsDisabled" ) == false ) {
7157 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 ;
58+ DisableLightRender ( ) ;
59+ }
8760 }
8861
89- private static List < Component > lightSources = new List < Component > ( ) ;
90-
91- private static List < Component > bloomSources = new List < Component > ( ) ;
92-
9362 private Level level ;
94-
95- private bool Persistent = true ;
9663 }
9764}
0 commit comments