Skip to content

Commit

Permalink
(Hopefully) fix crashes with reloads and flag rainbow spinner control…
Browse files Browse the repository at this point in the history
…lers
  • Loading branch information
maddie480 committed Dec 2, 2023
1 parent 5b8e132 commit 75a6856
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Entities/RainbowSpinnerColorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ internal void ApplyToSession() {
public override void Awake(Scene scene) {
base.Awake(scene);

flagLatestState = !string.IsNullOrEmpty(flag) && SceneAs<Level>().Session.GetFlag(flag);
flagLatestState = isFlagActive();

// this is the controller for the next screen.
nextSpinnerController = this;
Expand Down Expand Up @@ -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<Level>().Session.GetFlag(flag);
bool flagState = isFlagActive();
if (flagState != flagLatestState) {
flagLatestState = flagState;

Expand All @@ -239,7 +239,7 @@ public override void Update() {
}

private T selectFromFlag<T>(Tuple<T, T> setting) {
if (string.IsNullOrEmpty(flag) || !SceneAs<Level>().Session.GetFlag(flag)) {
if (!isFlagActive()) {
return setting.Item1;
}
return setting.Item2;
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 75a6856

Please sign in to comment.