ColorEase Class (#735)

* 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

* port karate man, fix NaN bug

goin to bed now!

* km fix, convert all to colorease, multisounds stuff

fix that goddamn ms.startBeat = sounds[0].beat; bug + if it's already converting to a list, why not just define the sounds as a list??????? they're a list most of the time anyways

ive got work ahead of me.

* finish up the code, document it

just a few more fixes and we're good

* revert some fork lifter stuff

as nice as it would be i just don't want things to break

* revert some MORE stuff

* revert even more. bleh

* semtiones lol

also a karate man fix
This commit is contained in:
AstrlJelly
2024-03-03 22:50:46 -05:00
committed by GitHub
parent a1f872ef4f
commit 9866663614
15 changed files with 229 additions and 500 deletions

View File

@ -76,27 +76,10 @@ namespace HeavenStudio.Games
public static CoinToss instance { get; set; }
private static Color _defaultBgColor;
public static Color defaultBgColor
{
get
{
ColorUtility.TryParseHtmlString("#F7F742", out _defaultBgColor);
return _defaultBgColor;
}
}
public static Color defaultBgColor = new Color(0.97f, 0.97f, 0.26f);
public static Color defaultFgColor = new Color(1f, 1f, 0.51f);
private static Color _defaultFgColor;
public static Color defaultFgColor
{
get
{
ColorUtility.TryParseHtmlString("#FFFF83", out _defaultFgColor);
return _defaultFgColor;
}
}
[Header("Backgrounds")]
public SpriteRenderer fg;
public SpriteRenderer bg;
@ -123,10 +106,6 @@ namespace HeavenStudio.Games
coin = null;
colorStart = defaultBgColor;
colorEnd = defaultBgColor;
colorStartF = defaultBgColor;
colorEndF = defaultBgColor;
BackgroundColorUpdate();
}
@ -142,6 +121,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 +158,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 +184,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
// 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 = bgColorEase.GetColor();
fg.color = bgFColorEase.GetColor();
}
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 +212,5 @@ namespace HeavenStudio.Games
}
}
public override void OnPlay(double beat)
{
PersistColor(beat);
}
public override void OnGameSwitch(double beat)
{
PersistColor(beat);
}
}
}