diff --git a/Assets/Scripts/Games/ClappyTrio/ClappyTrio.cs b/Assets/Scripts/Games/ClappyTrio/ClappyTrio.cs index 50f57dc51..162ac47ec 100644 --- a/Assets/Scripts/Games/ClappyTrio/ClappyTrio.cs +++ b/Assets/Scripts/Games/ClappyTrio/ClappyTrio.cs @@ -59,12 +59,6 @@ namespace HeavenStudio.Games.Loaders new Param("valA", new EntityTypes.Integer(3, 8, 3), "Lions", "Set how many lions there will be. The player is always the rightmost lion.") } }, - // This is still here for backwards-compatibility but is hidden in the editor - new GameAction("prepare_alt", "") - { - function = delegate { ClappyTrio.instance.Prepare(3); }, - hidden = true - }, }, new List() {"agb", "normal"}, "agbclap", "en", diff --git a/Assets/Scripts/Games/CoinToss/CoinToss.cs b/Assets/Scripts/Games/CoinToss/CoinToss.cs index c98a61f87..7f14a1565 100644 --- a/Assets/Scripts/Games/CoinToss/CoinToss.cs +++ b/Assets/Scripts/Games/CoinToss/CoinToss.cs @@ -123,10 +123,6 @@ namespace HeavenStudio.Games coin = null; - colorStart = defaultBgColor; - colorEnd = defaultBgColor; - colorStartF = defaultBgColor; - colorEndF = defaultBgColor; BackgroundColorUpdate(); } @@ -142,6 +138,9 @@ namespace HeavenStudio.Games } } + public override void OnPlay(double beat) => PersistColor(beat); + public override void OnGameSwitch(double beat) => PersistColor(beat); + public void TossCoin(double beat, int type, bool audienceReacting) { if (coin != null) return; @@ -176,21 +175,6 @@ namespace HeavenStudio.Games //coin.perfectOnly = true; } - public void TossCoin(double beat) - { - if (coin != null) return; - - //Play sound and animations - SoundByte.PlayOneShotGame("coinToss/throw"); - handAnimator.Play("Throw", 0, 0); - //Game state says the hand is throwing the coin - isThrowing = true; - this.audienceReacting = false; - - coin = ScheduleInput(beat, 6f, InputAction_BasicPress, CatchSuccess, CatchMiss, CatchEmpty); - //coin.perfectOnly = true; - } - public void CatchSuccess(PlayerActionEvent caller, float state) { SoundByte.PlayOneShotGame("coinToss/catch"); @@ -217,43 +201,20 @@ namespace HeavenStudio.Games coin.CanHit(false); } - private double colorStartBeat = -1; - private float colorLength = 0f; - private Color colorStart; //obviously put to the default color of the game - private Color colorEnd; - private Color colorStartF; //obviously put to the default color of the game - private Color colorEndF; - private Util.EasingFunction.Ease colorEase; //putting Util in case this game is using jukebox + private ColorEase bgColorEase = new(defaultBgColor); + private ColorEase bgFColorEase = new(defaultBgColor); //call this in update private void BackgroundColorUpdate() { - float normalizedBeat = Mathf.Clamp01(Conductor.instance.GetPositionFromBeat(colorStartBeat, colorLength)); - - var func = Util.EasingFunction.GetEasingFunction(colorEase); - - float newR = func(colorStart.r, colorEnd.r, normalizedBeat); - float newG = func(colorStart.g, colorEnd.g, normalizedBeat); - float newB = func(colorStart.b, colorEnd.b, normalizedBeat); - - bg.color = new Color(newR, newG, newB); - - float newRF = func(colorStartF.r, colorEndF.r, normalizedBeat); - float newGF = func(colorStartF.g, colorEndF.g, normalizedBeat); - float newBF = func(colorStartF.b, colorEndF.b, normalizedBeat); - - fg.color = new Color(newRF, newGF, newBF); + bg.color = GetNewColor(bgColorEase); + fg.color = GetNewColor(bgFColorEase); } public void BackgroundColor(double beat, float length, Color colorStartSet, Color colorEndSet, Color colorStartSetF, Color colorEndSetF, int ease) { - colorStartBeat = beat; - colorLength = length; - colorStart = colorStartSet; - colorEnd = colorEndSet; - colorStartF = colorStartSetF; - colorEndF = colorEndSetF; - colorEase = (Util.EasingFunction.Ease)ease; + bgColorEase = new ColorEase(beat, length, colorStartSet, colorEndSet, ease); + bgFColorEase = new ColorEase(beat, length, colorStartSetF, colorEndSetF, ease); } //call this in OnPlay(double beat) and OnGameSwitch(double beat) @@ -268,14 +229,5 @@ namespace HeavenStudio.Games } } - public override void OnPlay(double beat) - { - PersistColor(beat); - } - - public override void OnGameSwitch(double beat) - { - PersistColor(beat); - } } } diff --git a/Assets/Scripts/Games/ForkLifter/ForkLifter.cs b/Assets/Scripts/Games/ForkLifter/ForkLifter.cs index 559ad8bb5..9c156376a 100644 --- a/Assets/Scripts/Games/ForkLifter/ForkLifter.cs +++ b/Assets/Scripts/Games/ForkLifter/ForkLifter.cs @@ -178,61 +178,48 @@ namespace HeavenStudio.Games fo.SetActive(true); } - private double colorStartBeat = -1; - private float colorLength = 0f; - private Color colorStart = Color.white; //obviously put to the default color of the game - private Color colorEnd = Color.white; - private Util.EasingFunction.Ease colorEase; //putting Util in case this game is using jukebox - - private double colorStartBeatGrad = -1; - private float colorLengthGrad = 0f; - private Color colorStartGrad = Color.white; //obviously put to the default color of the game - private Color colorEndGrad = Color.white; - private Util.EasingFunction.Ease colorEaseGrad; //putting Util in case this game is using jukebox + private ColorEase bgColorEase = new(); + private ColorEase gradColorEase = new(); //call this in update private void BackgroundColorUpdate() { - float normalizedBeat = Mathf.Clamp01(Conductor.instance.GetPositionFromBeat(colorStartBeat, colorLength)); + bg.color = + viewerCircle.color = + handShadow.color = GetNewColor(bgColorEase); - var func = Util.EasingFunction.GetEasingFunction(colorEase); - - float newR = func(colorStart.r, colorEnd.r, normalizedBeat); - float newG = func(colorStart.g, colorEnd.g, normalizedBeat); - float newB = func(colorStart.b, colorEnd.b, normalizedBeat); - - bg.color = new Color(newR, newG, newB); - viewerCircle.color = new Color(newR, newG, newB); - handShadow.color = new Color(newR, newG, newB); - - float normalizedBeatGrad = Mathf.Clamp01(Conductor.instance.GetPositionFromBeat(colorStartBeatGrad, colorLengthGrad)); - - var funcGrad = Util.EasingFunction.GetEasingFunction(colorEaseGrad); - - float newRGrad = funcGrad(colorStartGrad.r, colorEndGrad.r, normalizedBeatGrad); - float newGGrad = funcGrad(colorStartGrad.g, colorEndGrad.g, normalizedBeatGrad); - float newBGrad = funcGrad(colorStartGrad.b, colorEndGrad.b, normalizedBeatGrad); - - bgGradient.color = new Color(newRGrad, newGGrad, newBGrad); - playerShadow.color = new Color(newRGrad, newGGrad, newBGrad); + bgGradient.color = + playerShadow.color = GetNewColor(gradColorEase); } - public void BackgroundColor(double beat, float length, Color colorStartSet, Color colorEndSet, int ease) + public void BackgroundColor(double beat, float length, Color startColor, Color endColor, int ease) { - colorStartBeat = beat; - colorLength = length; - colorStart = colorStartSet; - colorEnd = colorEndSet; - colorEase = (Util.EasingFunction.Ease)ease; + bgColorEase = new ColorEase(beat, length, startColor, endColor, ease); } - public void BackgroundColorGrad(double beat, float length, Color colorStartSet, Color colorEndSet, int ease) + public void BackgroundColorGrad(double beat, float length, Color startColor, Color endColor, int ease) { - colorStartBeatGrad = beat; - colorLengthGrad = length; - colorStartGrad = colorStartSet; - colorEndGrad = colorEndSet; - colorEaseGrad = (Util.EasingFunction.Ease)ease; + gradColorEase = new ColorEase(beat, length, startColor, endColor, ease); + } + + //call this in OnPlay(double beat) and OnGameSwitch(double beat) + private void PersistColor(double beat) + { + var allEventsBeforeBeat = EventCaller.GetAllInGameManagerList("forkLifter", new string[] { "color" }).FindAll(x => x.beat < beat); + if (allEventsBeforeBeat.Count > 0) + { + allEventsBeforeBeat.Sort((x, y) => x.beat.CompareTo(y.beat)); //just in case + var lastEvent = allEventsBeforeBeat[^1]; + BackgroundColor(lastEvent.beat, lastEvent.length, lastEvent["start"], lastEvent["end"], lastEvent["ease"]); + } + + var allEventsBeforeBeatGrad = EventCaller.GetAllInGameManagerList("forkLifter", new string[] { "colorGrad" }).FindAll(x => x.beat < beat); + if (allEventsBeforeBeatGrad.Count > 0) + { + allEventsBeforeBeatGrad.Sort((x, y) => x.beat.CompareTo(y.beat)); //just in case + var lastEventGrad = allEventsBeforeBeatGrad[^1]; + BackgroundColorGrad(lastEventGrad.beat, lastEventGrad.length, lastEventGrad["start"], lastEventGrad["end"], lastEventGrad["ease"]); + } } } } \ No newline at end of file diff --git a/Assets/Scripts/Games/Minigame.cs b/Assets/Scripts/Games/Minigame.cs index eafdc64ba..02470481a 100644 --- a/Assets/Scripts/Games/Minigame.cs +++ b/Assets/Scripts/Games/Minigame.cs @@ -428,6 +428,48 @@ namespace HeavenStudio.Games #endregion + #region Color + public struct ColorEase + { + public double startBeat; + public float length; + public Color startColor, endColor; + public Util.EasingFunction.Ease ease; + public readonly Util.EasingFunction.Function easeFunc; + + public ColorEase(double startBeat, float length, Color startColor, Color endColor, int ease) { + this.startBeat = startBeat; + this.length = length; + (this.startColor, this.endColor) = (startColor, endColor); + this.ease = (Util.EasingFunction.Ease)ease; + this.easeFunc = Util.EasingFunction.GetEasingFunction(this.ease); + } + public ColorEase(Color? tempColor = null) { + startBeat = length = 0; + startColor = endColor = (tempColor ?? Color.white); + ease = Util.EasingFunction.Ease.Instant; + easeFunc = Util.EasingFunction.GetEasingFunction(ease); + } + } + + public Color GetNewColor(ColorEase ce) => GetNewColor(ce.startBeat, ce.length, ce.startColor, ce.endColor, ce.easeFunc); + public Color GetNewColor(double beat, float length, Color start, Color end, Util.EasingFunction.Function func) + { + float normalizedBeat = Mathf.Clamp01(Conductor.instance.GetPositionFromBeat(beat, length)); + + float newR = func(start.r, end.r, normalizedBeat); + float newG = func(start.g, end.g, normalizedBeat); + float newB = func(start.b, end.b, normalizedBeat); + + return new Color(newR, newG, newB); + } + + // public RiqEntity PersistColor(double beat) + // { + // + // } + #endregion + private void OnDestroy() { foreach (var evt in scheduledInputs)