HeavenStudio/Assets/Scripts/Games/MeatGrinder/MeatGrinder.cs
minenice55 81384fe7fb
Update from release 1 branch (#472)
* Integration of Jukebox Library (#451)

* add Jukebox library

todo:
- saving / loading of new format
- inferrence of unknown data like past versions
- move the temporary float casts to proper use of double
- make sound related functions take double for timing
- inform people that the Jukebox sound player was renamed to SoundByte lol

* make sound, input scheduling, and super curve use double precision

* successfully load charts

* editor works again

v1 riqs can be saved and loaded

* first tempo and volume markers are unmovable

fix loading of charts' easing values

* use gsync / freesync

* update Jukebox refs to SoundByte

* game events use double part 1

Air Rally - Glee Club converted

* don't load song if chart load fails

* finish conversion of all minigames

* remove editor waveform toggle

* timeline now respects added song offset length

clear cache files on app close
prepped notes for dsp sync

* update timeline length when offset changed

* update to latest Jukebox

* make error panel object in global game manager

* improve conductor music scheduling

* added error message box

fix first game events sometimes not playing

* a lot

* munchy monk input + mustache fixes
* fork lifter and pajama party bopping
* meat grinder miss bop fix
* cloud monkey Real
* marching orders Go! was broken
* force march doesn't break when it's too early from a game switch
* you can use the March! block without the marching now

* convert float to double and all that

* editor fixes (#459)

* ditch loading dialog

doesn't show up when it's supposed to

* format song offset in editor

* remove VorbisPlugin

* Update Editor.cs

* add updater for marching orders turn

* make base datamodels for special entity reading (#463)

* make base datamodels for special entity reading

* fix crop stomp breaking when no game switch or remix end is set

* fix save shortcut

fix loading charts with no music

* don't infer track when importing a v0 riq from another program

* You can now place inputs on top of pass turn for rhythm tweezers

* Rockers can do it too now

* Some new curves

* Converted everything to new curves and made playerballs handle themselves input-wise

* working dough converted, need to fix eveerything though

* ball transporter anims for pass turn

* update Jukebox to latest version

fixes for inferred entity loading

* new sounds

* OnSpawnBall reimplemented

* Proper inactive handling now

* gandw on balls has been added

* Rhythm tweezers pass turn now works like working dough

* modernised rockers pass turn

* Fixed small balls not working in working dough

* Fixed weird curve stuff on game switch in working dough

* let play mode start if no song file is loaded

fix issue with loading large audio files

* add "updater" for the old marching entity

---------

Co-authored-by: AstrlJelly <bdlawson115@gmail.com>
Co-authored-by: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com>
2023-06-13 18:47:52 -04:00

243 lines
8.4 KiB
C#

using HeavenStudio.Util;
using System;
using System.Collections.Generic;
using UnityEngine;
using NaughtyBezierCurves;
namespace HeavenStudio.Games.Loaders
{
using static Minigames;
public static class pcoMeatLoader
{
public static Minigame AddGame(EventCaller eventCaller) {
return new Minigame("meatGrinder", "Meat Grinder", "501d18", false, false, new List<GameAction>()
{
new GameAction("MeatToss", "Meat Toss")
{
function = delegate {
var e = eventCaller.currentEntity;
MeatGrinder.instance.MeatToss(e.beat);
},
defaultLength = 2f,
priority = 2,
},
new GameAction("MeatCall", "Meat Call")
{
function = delegate {
var e = eventCaller.currentEntity;
MeatGrinder.instance.MeatCall(e.beat);
},
defaultLength = 0.5f,
priority = 2,
preFunctionLength = 1f,
preFunction = delegate {
var e = eventCaller.currentEntity;
MeatGrinder.PreInterval(e.beat, 4f);
},
},
new GameAction("StartInterval", "Start Interval")
{
defaultLength = 4f,
resizable = true,
priority = 5,
preFunction = delegate {
var e = eventCaller.currentEntity;
MeatGrinder.PreInterval(e.beat, e.length);
},
},
new GameAction("bop", "Bop")
{
function = delegate {
var e = eventCaller.currentEntity;
MeatGrinder.instance.Bop(e.beat, e.length, e["bop"], e["bossBop"]);
},
parameters = new List<Param>()
{
new Param("bop", true, "Boss Bops?", "Does Boss bop?"),
new Param("bossBop", false, "Boss Bops? (Auto)", "Does Boss Auto bop?"),
},
resizable = true,
priority = 1,
},
},
new List<string>() {"pco", "normal", "repeat"},
"pcomeat", "en",
new List<string>() {}
);
}
}
}
namespace HeavenStudio.Games
{
using Scripts_MeatGrinder;
public class MeatGrinder : Minigame
{
static List<double> queuedInputs = new();
static List<QueuedInterval> queuedIntervals = new List<QueuedInterval>();
struct QueuedInterval
{
public double beat;
public double length;
}
[Header("Objects")]
public GameObject MeatBase;
[Header("Animators")]
public Animator BossAnim;
public Animator TackAnim;
[Header("Variables")]
bool intervalStarted;
double intervalStartBeat;
bool bossBop = true;
public double beatInterval = 4f;
public bool bossAnnoyed = false;
private double lastReportedBeat = 0f;
const string sfxName = "meatGrinder/";
public static MeatGrinder instance;
public enum MeatType
{
Dark,
Light,
}
private void Awake()
{
instance = this;
}
void OnDestroy()
{
if (!Conductor.instance.isPlaying || Conductor.instance.isPaused) {
if (queuedInputs.Count > 0) queuedInputs.Clear();
if (queuedIntervals.Count > 0) queuedIntervals.Clear();
intervalStarted = false;
beatInterval = 4f;
}
foreach (var evt in scheduledInputs) evt.Disable();
}
private void Update()
{
if (PlayerInput.Pressed(true) && (!IsExpectingInputNow(InputType.STANDARD_DOWN) || !IsExpectingInputNow(InputType.DIRECTION_DOWN))) {
TackAnim.DoScaledAnimationAsync("TackEmptyHit", 0.5f);
TackAnim.SetBool("tackMeated", false);
SoundByte.PlayOneShotGame(sfxName+"whiff");
bossAnnoyed = false;
}
if (bossAnnoyed) BossAnim.SetBool("bossAnnoyed", true);
if (queuedIntervals.Count > 0) {
foreach (var interval in queuedIntervals) StartInterval(interval.beat, interval.length);
queuedIntervals.Clear();
}
}
private void LateUpdate()
{
if (Conductor.instance.ReportBeat(ref lastReportedBeat)
&& !BossAnim.IsPlayingAnimationName("BossCall")
&& !BossAnim.IsPlayingAnimationName("BossSignal")
&& bossBop)
{
BossAnim.DoScaledAnimationAsync(bossAnnoyed ? "BossMiss" : "Bop", 0.5f);
}
}
public void Bop(double beat, double length, bool doesBop, bool autoBop)
{
bossBop = autoBop;
if (doesBop) {
for (int i = 0; i < length; i++) {
BeatAction.New(instance.gameObject, new List<BeatAction.Action>() {
new BeatAction.Action(beat + i, delegate {
if (!BossAnim.IsPlayingAnimationName("BossCall") && !BossAnim.IsPlayingAnimationName("BossSignal")) {
BossAnim.DoScaledAnimationAsync(bossAnnoyed ? "BossMiss" : "Bop", 0.5f);
}
})
});
}
}
}
public static void PreInterval(double beat, double length)
{
if (MeatGrinder.instance.intervalStarted || MeatGrinder.queuedIntervals.Count > 0) return;
MeatGrinder.queuedIntervals.Add(new QueuedInterval() {
beat = beat,
length = length,
});
SoundByte.PlayOneShotGame("meatGrinder/startSignal", beat - 1, forcePlay: true);
if (GameManager.instance.currentGame == "meatGrinder") {
BeatAction.New(MeatGrinder.instance.gameObject, new List<BeatAction.Action>() {
new BeatAction.Action(beat - 1, delegate {
MeatGrinder.instance.BossAnim.DoScaledAnimationAsync("BossSignal", 0.5f);
}),
});
}
}
public void StartInterval(double beat, double length)
{
if (MeatGrinder.instance.intervalStarted) return;
intervalStartBeat = beat;
intervalStarted = true;
beatInterval = length;
BeatAction.New(gameObject, new List<BeatAction.Action>() {
new BeatAction.Action(beat + length - 0.33f, delegate { PassTurn(beat); }),
});
}
public void MeatToss(double beat)
{
SoundByte.PlayOneShotGame(sfxName+"toss");
MeatToss Meat = Instantiate(MeatBase, gameObject.transform).GetComponent<MeatToss>();
Meat.startBeat = beat;
Meat.cueLength = 1f;
Meat.cueBased = true;
Meat.meatType = "DarkMeat";
}
public void MeatCall(double beat)
{
BossAnim.DoScaledAnimationAsync("BossCall", 0.5f);
SoundByte.PlayOneShotGame(sfxName+"signal");
StartInterval(beat, beatInterval);
queuedInputs.Add(beat - intervalStartBeat);
}
public void PassTurn(double beat)
{
intervalStarted = false;
foreach (var input in queuedInputs)
{
BeatAction.New(instance.gameObject, new List<BeatAction.Action>()
{
new BeatAction.Action(input + beatInterval , delegate {
MeatToss Meat = Instantiate(MeatBase, gameObject.transform).GetComponent<MeatToss>();
Meat.startBeat = beat;
Meat.cueLength = beatInterval + input;
Meat.cueBased = false;
Meat.meatType = "LightMeat";
}),
});
}
queuedInputs.Clear();
}
}
}