@@ -15,11 +15,13 @@ public class ColorSwitch : Solid
1515
1616 private readonly MTexture [ , ] edges = new MTexture [ 3 , 3 ] ;
1717
18- private static readonly Color defaultBackgroundColor = Calc . HexToColor ( "191919" ) ;
19- private static readonly Color defaultEdgeColor = Calc . HexToColor ( "646464" ) ;
18+ public static readonly Color DefaultBackgroundColor = Calc . HexToColor ( "191919" ) ;
19+ public static readonly Color DefaultEdgeColor = Calc . HexToColor ( "646464" ) ;
20+ private static Color RoomDefaultBackgroundColor ( Level level ) => level . Tracker . GetEntity < SwitchBlockColorController > ( ) ? . SwitchBackgroundColor ?? DefaultBackgroundColor ;
21+ private static Color RoomDefaultEdgeColor ( Level level ) => level . Tracker . GetEntity < SwitchBlockColorController > ( ) ? . SwitchEdgeColor ?? DefaultEdgeColor ;
2022
21- private Color BackgroundColor = defaultBackgroundColor ;
22- private Color EdgeColor = defaultEdgeColor ;
23+ private Color BackgroundColor ;
24+ private Color EdgeColor ;
2325 private Color currentEdgeColor , currentBackgroundColor ;
2426
2527 private Vector2 scale = Vector2 . One ;
@@ -31,10 +33,10 @@ public class ColorSwitch : Solid
3133
3234 public ColorSwitch ( EntityData data , Vector2 offset )
3335 : this ( data . Position + offset , data . Width , data . Height ,
34- data . Bool ( "blue" ) , data . Bool ( "rose" ) , data . Bool ( "orange" ) , data . Bool ( "lime" ) , data . Bool ( "random" ) )
36+ data . Bool ( "blue" ) , data . Bool ( "rose" ) , data . Bool ( "orange" ) , data . Bool ( "lime" ) , data . Bool ( "random" ) , data . Attr ( "spriteDir" , "" ) . Trim ( ) . TrimEnd ( '/' ) )
3537 { }
3638
37- public ColorSwitch ( Vector2 position , int width , int height , bool blue , bool rose , bool orange , bool lime , bool random )
39+ public ColorSwitch ( Vector2 position , int width , int height , bool blue , bool rose , bool orange , bool lime , bool random , string spriteDir )
3840 : base ( position , width , height , true )
3941 {
4042 this . SurfaceSoundIndex = SurfaceIndex . ZipMover ;
@@ -43,7 +45,7 @@ public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose
4345 if ( ! blue && ! rose && ! orange && ! lime )
4446 blue = rose = orange = lime = true ;
4547
46- string block = "objects/VortexHelper/onoff/switch" ;
48+ string block = string . IsNullOrEmpty ( spriteDir ) ? "objects/VortexHelper/onoff/switch" : spriteDir + " /switch";
4749 for ( int i = 0 ; i < 3 ; i ++ )
4850 for ( int j = 0 ; j < 3 ; j ++ )
4951 this . edges [ i , j ] = GFX . Game [ block ] . GetSubtexture ( i * 8 , j * 8 , 8 , 8 ) ;
@@ -61,8 +63,6 @@ public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose
6163 if ( colorBools [ i ] )
6264 this . colors [ arrIdx ++ ] = ( VortexHelperSession . SwitchBlockColor ) i ;
6365
64- NextColor ( this . colors [ this . nextColorIndex ] , true ) ;
65-
6666 Add ( new LightOcclude ( ) ) ;
6767 Add ( new SoundSource ( SFX . game_01_console_static_loop )
6868 {
@@ -74,13 +74,23 @@ public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose
7474 if ( height > 32 )
7575 this . scaleStrength . Y = height / 32f ;
7676
77- Color col = this . colors [ this . nextColorIndex ] . IsActive ( ) ? defaultBackgroundColor : this . colors [ this . nextColorIndex ] . GetColor ( ) ;
78- SetEdgeColor ( this . EdgeColor , this . EdgeColor ) ;
79- SetBackgroundColor ( col , col ) ;
80-
8177 this . OnDashCollide = Dashed ;
8278 }
8379
80+ public override void Awake ( Scene scene )
81+ {
82+ base . Awake ( scene ) ;
83+
84+ Level level = SceneAs < Level > ( ) ;
85+
86+ Color bgCol = this . colors [ this . nextColorIndex ] . IsActive ( ) ? RoomDefaultBackgroundColor ( level ) : this . colors [ this . nextColorIndex ] . GetColor ( level ) ;
87+ Color edgeCol = RoomDefaultEdgeColor ( level ) ;
88+ SetBackgroundColor ( bgCol , bgCol ) ;
89+ SetEdgeColor ( edgeCol , edgeCol ) ;
90+
91+ NextColor ( this . colors [ this . nextColorIndex ] , true ) ;
92+ }
93+
8494 public override void Render ( )
8595 {
8696 Vector2 position = this . Position ;
@@ -92,9 +102,10 @@ public override void Render()
92102 int rectH = ( int ) ( ( this . Height - 2 ) * this . scale . Y ) ;
93103 var rect = new Rectangle ( x , y , rectW , rectH ) ;
94104
105+ Color defaultCol = RoomDefaultBackgroundColor ( SceneAs < Level > ( ) ) ;
95106 Color col = this . random
96- ? Color . Lerp ( defaultBackgroundColor , Color . White , ( float ) ( 0.05f * Math . Sin ( this . Scene . TimeActive * 5f ) ) + 0.05f )
97- : this . BackgroundColor != defaultBackgroundColor
107+ ? Color . Lerp ( defaultCol , Color . White , ( float ) ( 0.05f * Math . Sin ( this . Scene . TimeActive * 5f ) ) + 0.05f )
108+ : this . BackgroundColor != defaultCol
98109 ? Color . Lerp ( this . currentBackgroundColor , Color . Black , 0.2f )
99110 : this . currentBackgroundColor ;
100111
@@ -176,6 +187,8 @@ private DashCollisionResults Dashed(Player player, Vector2 direction)
176187
177188 public void Switch ( Vector2 direction )
178189 {
190+ Level level = SceneAs < Level > ( ) ;
191+
179192 this . scale = new Vector2 (
180193 1f + ( Math . Abs ( direction . Y ) * 0.5f - Math . Abs ( direction . X ) * 0.5f ) / this . scaleStrength . X ,
181194 1f + ( Math . Abs ( direction . X ) * 0.5f - Math . Abs ( direction . Y ) * 0.5f ) / this . scaleStrength . Y
@@ -185,18 +198,18 @@ public void Switch(Vector2 direction)
185198 this . nextColorIndex = Calc . Random . Next ( 0 , this . colors . Length ) ;
186199
187200 VortexHelperModule . SessionProperties . SessionSwitchBlockColor = this . colors [ this . nextColorIndex ] ;
188- Color col = VortexHelperModule . SessionProperties . SessionSwitchBlockColor . GetColor ( ) ;
201+ Color col = VortexHelperModule . SessionProperties . SessionSwitchBlockColor . GetColor ( level ) ;
189202
190203 UpdateColorSwitches ( this . Scene , this . colors [ this . nextColorIndex ] ) ;
191- SetEdgeColor ( defaultEdgeColor , col ) ;
204+ SetEdgeColor ( RoomDefaultEdgeColor ( level ) , col ) ;
192205 this . currentBackgroundColor = Color . White ;
193206
194207 Audio . Play ( CustomSFX . game_colorSwitch_hit , this . Center ) ;
195208 if ( SwitchBlock . RoomHasSwitchBlock ( this . Scene , VortexHelperModule . SessionProperties . SessionSwitchBlockColor ) )
196209 Audio . Play ( CustomSFX . game_switchBlock_switch , "tone" , VortexHelperModule . SessionProperties . SessionSwitchBlockColor . GetSoundParam ( ) ) ;
197210
198211 Input . Rumble ( RumbleStrength . Strong , RumbleLength . Long ) ;
199- SceneAs < Level > ( ) . DirectionalShake ( direction , 0.25f ) ;
212+ level . DirectionalShake ( direction , 0.25f ) ;
200213 StartShaking ( 0.25f ) ;
201214
202215 ParticleType p = LightningBreakerBox . P_Smash ;
@@ -213,6 +226,8 @@ public static void UpdateColorSwitches(Scene scene, VortexHelperSession.SwitchBl
213226
214227 private void NextColor ( VortexHelperSession . SwitchBlockColor colorNext , bool start )
215228 {
229+ Level level = SceneAs < Level > ( ) ;
230+
216231 if ( colorNext == this . colors [ this . nextColorIndex ] && ! this . singleColor )
217232 {
218233 if ( ! start )
@@ -224,8 +239,8 @@ private void NextColor(VortexHelperSession.SwitchBlockColor colorNext, bool star
224239 if ( this . colors [ this . nextColorIndex ] . IsActive ( ) )
225240 this . nextColorIndex ++ ;
226241 }
227-
228- this . BackgroundColor = this . colors [ this . nextColorIndex ] . IsActive ( ) ? defaultBackgroundColor : this . colors [ this . nextColorIndex ] . GetColor ( ) ;
242+
243+ this . BackgroundColor = this . colors [ this . nextColorIndex ] . IsActive ( ) ? RoomDefaultBackgroundColor ( level ) : this . colors [ this . nextColorIndex ] . GetColor ( level ) ;
229244 }
230245
231246 private void SmashParticles ( Vector2 dir , ParticleType smashParticle )
0 commit comments