ColorEase stuff

why didn't we do this earlier!! this is so much common code cut down and makes things a LOT easier to type
This commit is contained in:
AstrlJelly 2024-02-04 03:43:35 -05:00
parent 35136c1826
commit 8dca64d523
4 changed files with 82 additions and 107 deletions

View file

@ -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.") 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<string>() {"agb", "normal"}, new List<string>() {"agb", "normal"},
"agbclap", "en", "agbclap", "en",

View file

@ -123,10 +123,6 @@ namespace HeavenStudio.Games
coin = null; coin = null;
colorStart = defaultBgColor;
colorEnd = defaultBgColor;
colorStartF = defaultBgColor;
colorEndF = defaultBgColor;
BackgroundColorUpdate(); 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) public void TossCoin(double beat, int type, bool audienceReacting)
{ {
if (coin != null) return; if (coin != null) return;
@ -176,21 +175,6 @@ namespace HeavenStudio.Games
//coin.perfectOnly = true; //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) public void CatchSuccess(PlayerActionEvent caller, float state)
{ {
SoundByte.PlayOneShotGame("coinToss/catch"); SoundByte.PlayOneShotGame("coinToss/catch");
@ -217,43 +201,20 @@ namespace HeavenStudio.Games
coin.CanHit(false); coin.CanHit(false);
} }
private double colorStartBeat = -1; private ColorEase bgColorEase = new(defaultBgColor);
private float colorLength = 0f; private ColorEase bgFColorEase = new(defaultBgColor);
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
//call this in update //call this in update
private void BackgroundColorUpdate() private void BackgroundColorUpdate()
{ {
float normalizedBeat = Mathf.Clamp01(Conductor.instance.GetPositionFromBeat(colorStartBeat, colorLength)); bg.color = GetNewColor(bgColorEase);
fg.color = GetNewColor(bgFColorEase);
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);
} }
public void BackgroundColor(double beat, float length, Color colorStartSet, Color colorEndSet, Color colorStartSetF, Color colorEndSetF, int ease) public void BackgroundColor(double beat, float length, Color colorStartSet, Color colorEndSet, Color colorStartSetF, Color colorEndSetF, int ease)
{ {
colorStartBeat = beat; bgColorEase = new ColorEase(beat, length, colorStartSet, colorEndSet, ease);
colorLength = length; bgFColorEase = new ColorEase(beat, length, colorStartSetF, colorEndSetF, ease);
colorStart = colorStartSet;
colorEnd = colorEndSet;
colorStartF = colorStartSetF;
colorEndF = colorEndSetF;
colorEase = (Util.EasingFunction.Ease)ease;
} }
//call this in OnPlay(double beat) and OnGameSwitch(double beat) //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);
}
} }
} }

View file

@ -178,61 +178,48 @@ namespace HeavenStudio.Games
fo.SetActive(true); fo.SetActive(true);
} }
private double colorStartBeat = -1; private ColorEase bgColorEase = new();
private float colorLength = 0f; private ColorEase gradColorEase = new();
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
//call this in update //call this in update
private void BackgroundColorUpdate() 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); bgGradient.color =
playerShadow.color = GetNewColor(gradColorEase);
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);
} }
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; bgColorEase = new ColorEase(beat, length, startColor, endColor, ease);
colorLength = length;
colorStart = colorStartSet;
colorEnd = colorEndSet;
colorEase = (Util.EasingFunction.Ease)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; gradColorEase = new ColorEase(beat, length, startColor, endColor, ease);
colorLengthGrad = length; }
colorStartGrad = colorStartSet;
colorEndGrad = colorEndSet; //call this in OnPlay(double beat) and OnGameSwitch(double beat)
colorEaseGrad = (Util.EasingFunction.Ease)ease; 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"]);
}
} }
} }
} }

View file

@ -428,6 +428,48 @@ namespace HeavenStudio.Games
#endregion #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() private void OnDestroy()
{ {
foreach (var evt in scheduledInputs) foreach (var evt in scheduledInputs)