From 75a6856542d9712d2e4ddba388ac7a235a5fe7b6 Mon Sep 17 00:00:00 2001 From: maddie480 <52103563+maddie480@users.noreply.github.com> Date: Sat, 2 Dec 2023 18:51:08 +0100 Subject: [PATCH] (Hopefully) fix crashes with reloads and flag rainbow spinner controllers --- Entities/RainbowSpinnerColorController.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Entities/RainbowSpinnerColorController.cs b/Entities/RainbowSpinnerColorController.cs index 9d476f6..11d6dcc 100644 --- a/Entities/RainbowSpinnerColorController.cs +++ b/Entities/RainbowSpinnerColorController.cs @@ -175,7 +175,7 @@ internal void ApplyToSession() { public override void Awake(Scene scene) { base.Awake(scene); - flagLatestState = !string.IsNullOrEmpty(flag) && SceneAs().Session.GetFlag(flag); + flagLatestState = isFlagActive(); // this is the controller for the next screen. nextSpinnerController = this; @@ -224,7 +224,7 @@ public override void Update() { // all spinners have the cycle randomly offset, so they don't get the new colors at the same time, // making for a weird visual effect. // so we want to update the hue of **all** spinners forcibly when the flag is toggled. - bool flagState = !string.IsNullOrEmpty(flag) && SceneAs().Session.GetFlag(flag); + bool flagState = isFlagActive(); if (flagState != flagLatestState) { flagLatestState = flagState; @@ -239,7 +239,7 @@ public override void Update() { } private T selectFromFlag(Tuple setting) { - if (string.IsNullOrEmpty(flag) || !SceneAs().Session.GetFlag(flag)) { + if (!isFlagActive()) { return setting.Item1; } return setting.Item2; @@ -332,5 +332,9 @@ internal static Color getModHue(Color[] colors, float gradientSize, Scene scene, float progressInIndex = globalProgress - colorIndex; return Color.Lerp(colors[colorIndex], colors[colorIndex + 1], progressInIndex); } + + private bool isFlagActive() { + return !string.IsNullOrEmpty(flag) && Scene is Level level && level.Session.GetFlag(flag); + } } }