Collapsing Properties Update + Animation From Beat Method (#575)

* add entity to collapse function, start on new animation thingy

im gonna use fork lifter to demonstrate DoScaledAnimationFromBeatAsync() cuz it uses animations to cue the peas

also i fixed that months old bug where the fork lifter sfx wasn't playing correctly :/

* animation from beat functional, octo machine converted

this looks fantastic i can't wait to implement this into more things

* better anim function

this is more efficient AND it'll produce more consistent results when starting an animation between tempo changes :D
(it no longer iterates through a list twice)
This commit is contained in:
AstrlJelly
2023-10-27 16:19:11 -04:00
committed by GitHub
parent 7624ea6e88
commit b22de5abdb
28 changed files with 624 additions and 622 deletions

View File

@ -15,7 +15,7 @@ namespace HeavenStudio.Games.Scripts_OctopusMachine
public bool cantBop;
public bool isSqueezed;
public bool isPreparing;
public bool queuePrepare;
public double queuePrepare;
public double lastReportedBeat = 0f;
double lastSqueezeBeat;
bool isActive = true;
@ -25,16 +25,17 @@ namespace HeavenStudio.Games.Scripts_OctopusMachine
void Awake()
{
game = OctopusMachine.instance;
queuePrepare = double.MaxValue;
}
void Update()
{
if (queuePrepare && Conductor.instance.NotStopped()) {
if (queuePrepare <= Conductor.instance.songPositionInBeatsAsDouble && Conductor.instance.NotStopped()) {
if (!(isPreparing || isSqueezed || anim.IsPlayingAnimationName("Release") || anim.IsPlayingAnimationName("Pop")))
{
anim.DoScaledAnimationAsync("Prepare", 0.5f);
anim.DoScaledAnimationFromBeatAsync("Prepare", 0.5f, queuePrepare);
isPreparing = true;
queuePrepare = false;
queuePrepare = double.MaxValue;
}
}
@ -98,15 +99,15 @@ namespace HeavenStudio.Games.Scripts_OctopusMachine
isActive = enable;
}
public void OctoAction(string action)
public void OctoAction(string action)
{
if (action != "Release" || (Conductor.instance.songPositionInBeatsAsDouble - lastSqueezeBeat) > 0.15f) SoundByte.PlayOneShotGame($"octopusMachine/{action.ToLower()}");
if (action == "Squeeze") lastSqueezeBeat = Conductor.instance.songPositionInBeatsAsDouble;
anim.DoScaledAnimationAsync(action, 0.5f);
isSqueezed = (action == "Squeeze");
isPreparing =
queuePrepare = false;
isSqueezed = action == "Squeeze";
isPreparing = false;
queuePrepare = double.MaxValue;
}
public void AnimationColor(int poppingColor)

View File

@ -44,14 +44,14 @@ namespace HeavenStudio.Games.Loaders
parameters = new List<Param>() {
new Param("shouldPrep", true, "Prepare?", "Plays a prepare animation before the cue.", new List<Param.CollapseParam>()
{
new Param.CollapseParam(x => (bool)x, new string[] { "prepBeats" })
new Param.CollapseParam((x, _) => (bool)x, new string[] { "prepBeats" })
}),
new Param("prepBeats", new EntityTypes.Float(0, 4, 1), "Prepare Beats", "How many beats before the cue does the octopus prepare?"),
},
preFunctionLength = 4f,
preFunction = delegate {
var e = eventCaller.currentEntity;
if (e["shouldPrep"]) OctopusMachine.Prepare(e.beat, e["prepBeats"]);
if (e["shouldPrep"]) OctopusMachine.queuePrepare = e.beat - e["prepBeats"];
},
priority = 1,
},
@ -84,7 +84,7 @@ namespace HeavenStudio.Games.Loaders
new Param("autoBop", true, "Hit/Miss Bop", "Plays a bop depending on if you hit or missed the cues."),
new Param("autoText", true, "Display Text", "Displays text depending on if you hit or missed the cues.", new List<Param.CollapseParam>()
{
new Param.CollapseParam(x => (bool)x, new string[] { "hitText", "missText" })
new Param.CollapseParam((x, _) => (bool)x, new string[] { "hitText", "missText" })
}),
new Param("hitText", "Good!", "Hit Text", "The text to display if you hit the cues."),
new Param("missText", "Wrong! Try again!", "Miss Text", "The text to display if you missed the cues."),
@ -96,7 +96,7 @@ namespace HeavenStudio.Games.Loaders
},
new GameAction("prepare", "Prepare")
{
function = delegate { OctopusMachine.queuePrepare = true; },
function = delegate { OctopusMachine.queuePrepare = eventCaller.currentEntity.beat; },
defaultLength = 0.5f,
},
new GameAction("bubbles", "Bubbles")
@ -109,7 +109,7 @@ namespace HeavenStudio.Games.Loaders
new Param("isInstant", true, "Instant", "Will the bubbles disappear appear?"),
new Param("setActive", OctopusMachine.Actives.Activate, "Activate or Deactivate", "Will the bubbles disappear or appear?", new List<Param.CollapseParam>()
{
new Param.CollapseParam(x => (int)x == (int)OctopusMachine.Actives.Activate, new string[] { "particleStrength" })
new Param.CollapseParam((x, _) => (int)x == (int)OctopusMachine.Actives.Activate, new string[] { "particleStrength" })
}),
new Param("particleStrength", new EntityTypes.Float(0, 25, 3), "Bubble Intensity", "The amount of bubbles"),
new Param("particleSpeed", new EntityTypes.Float(0, 25, 5), "Bubble Speed", "The speed of the bubbles"),
@ -150,19 +150,19 @@ namespace HeavenStudio.Games.Loaders
parameters = new List<Param>() {
new Param("oct1", true, "Show Octopus 1", "Should the first octopus be enabled?", new List<Param.CollapseParam>()
{
new Param.CollapseParam(x => (bool)x, new string[] { "oct1x", "oct1y" })
new Param.CollapseParam((x, _) => (bool)x, new string[] { "oct1x", "oct1y" })
}),
new Param("oct1x", new EntityTypes.Float(-10, 10, -4.64f), "X Octopus 1", "Change Octopus 1's X"),
new Param("oct1y", new EntityTypes.Float(-10, 10, 2.5f), "Y Octopus 1", "Change Octopus 1's Y"),
new Param("oct2", true, "Show Octopus 2", "Should the second octopus be enabled?", new List<Param.CollapseParam>()
{
new Param.CollapseParam(x => (bool)x, new string[] { "oct2x", "oct2y" })
new Param.CollapseParam((x, _) => (bool)x, new string[] { "oct2x", "oct2y" })
}),
new Param("oct2x", new EntityTypes.Float(-10, 10, -0.637f), "X Octopus 2", "Change Octopus 2's X"),
new Param("oct2y", new EntityTypes.Float(-10, 10, 0f), "Y Octopus 2", "Change Octopus 2's Y"),
new Param("oct3", true, "Show Octopus 3", "Should the third octopus be enabled?", new List<Param.CollapseParam>()
{
new Param.CollapseParam(x => (bool)x, new string[] { "oct3x", "oct3y" })
new Param.CollapseParam((x, _) => (bool)x, new string[] { "oct3x", "oct3y" })
}),
new Param("oct3x", new EntityTypes.Float(-10, 10, 3.363f), "X Octopus 3", "Change Octopus 3's X"),
new Param("oct3y", new EntityTypes.Float(-10, 10, -2.5f), "Y Octopus 3", "Change Octopus 3's Y"),
@ -196,7 +196,7 @@ namespace HeavenStudio.Games
static Color backgroundColor = new Color(1, 0.87f, 0.24f);
public static Color octopodesColor = new Color(0.97f, 0.235f, 0.54f);
public static Color octopodesSqueezedColor = new Color(1f, 0f, 0f);
public static bool queuePrepare;
public static double queuePrepare = double.MaxValue;
[Header("Variables")]
public bool hasMissed;
@ -243,6 +243,7 @@ namespace HeavenStudio.Games
if (queuedSqueezes.Count > 0) queuedSqueezes.Clear();
if (queuedReleases.Count > 0) queuedReleases.Clear();
if (queuedPops.Count > 0) queuedPops.Clear();
queuePrepare = double.MaxValue;
mat.SetColor("_ColorAlpha", new Color(0.97f, 0.235f, 0.54f));
@ -255,10 +256,10 @@ namespace HeavenStudio.Games
private void Update()
{
BackgroundColorUpdate();
if (queuePrepare) {
foreach (var octo in octopodes) octo.queuePrepare = true;
if (queuePrepare <= Conductor.instance.songPositionInBeatsAsDouble) {
foreach (var octo in octopodes) octo.queuePrepare = queuePrepare;
if (Text.text is "Wrong! Try Again!" or "Good!") Text.text = "";
queuePrepare = false;
queuePrepare = double.MaxValue;
}
if (Conductor.instance.ReportBeat(ref lastReportedBeat))
@ -273,19 +274,6 @@ namespace HeavenStudio.Games
}
}
public static void Prepare(double beat, float prepBeats)
{
if (GameManager.instance.currentGame != "octopusMachine") {
OctopusMachine.queuePrepare = true;
} else {
BeatAction.New(instance, new List<BeatAction.Action>() {
new BeatAction.Action(beat - prepBeats, delegate {
OctopusMachine.queuePrepare = true;
})
});
}
}
public void ChangeText(string text, string youText)
{
Text.text = text;
@ -312,7 +300,7 @@ namespace HeavenStudio.Games
var main = bubble.main;
main.prewarm = isInstant;
main.simulationSpeed = particleSpeed/10;
main.simulationSpeed = particleSpeed / 10;
var emm = bubble.emission;
emm.rateOverTime = particleStrength;
@ -328,9 +316,15 @@ namespace HeavenStudio.Games
if (!intervalStarted) StartInterval(beat, length);
octopodes[0].OctoAction(action);
var queuedList = queuedSqueezes;
if (action == "Release") queuedList = queuedReleases;
else if (action == "Pop") queuedList = queuedPops;
// var queuedList = queuedSqueezes;
// if (action == "Release") queuedList = queuedReleases;
// else if (action == "Pop") queuedList = queuedPops;
var queuedList = action switch {
"Release" => queuedReleases,
"Pop" => queuedPops,
_ => queuedSqueezes,
};
queuedList.Add(beat - intervalStartBeat);
}
@ -379,12 +373,9 @@ namespace HeavenStudio.Games
//call this in OnPlay(double beat) and OnGameSwitch(double beat)
private void PersistColor(double beat)
{
var allEventsBeforeBeat = EventCaller.GetAllInGameManagerList("octopusMachine", new string[] { "changeColor" }).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["color1"], lastEvent["color2"], lastEvent["octoColor"], lastEvent["squeezedColor"], lastEvent["ease"]);
var bgColor = GameManager.instance.Beatmap.Entities.FindLast(c => c.datamodel == "octopusMachine/changeColor" && c.beat < beat);
if (bgColor != null) {
BackgroundColor(bgColor.beat, bgColor.length, bgColor["color1"], bgColor["color2"], bgColor["octoColor"], bgColor["squeezedColor"], bgColor["ease"]);
}
}