Merge pull request #46 from Slaith12/main

Implemented Inactive Functions and made OnGameSwitch functional
This commit is contained in:
Jenny Crowe 2022-03-08 17:12:52 -07:00 committed by GitHub
commit 5a56ecf261
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 251 additions and 93 deletions

View file

@ -60,7 +60,7 @@ namespace RhythmHeavenMania
} }
public void CallEvent(Beatmap.Entity entity) public void CallEvent(Beatmap.Entity entity, bool gameActive)
{ {
string[] details = entity.datamodel.Split('/'); string[] details = entity.datamodel.Split('/');
Minigames.Minigame game = minigames.Find(c => c.name == details[0]); Minigames.Minigame game = minigames.Find(c => c.name == details[0]);
@ -71,12 +71,18 @@ namespace RhythmHeavenMania
if (details.Length > 2) currentSwitchGame = details[2]; if (details.Length > 2) currentSwitchGame = details[2];
Minigames.GameAction action = game.actions.Find(c => c.actionName == details[1]); Minigames.GameAction action = game.actions.Find(c => c.actionName == details[1]);
if (gameActive)
{
action.function.Invoke(); action.function.Invoke();
}
else
{
action.inactiveFunction.Invoke();
}
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.LogWarning("Event not found! May be spelled wrong or it is not implemented." + ex); Debug.LogWarning("Event not found! May be spelled wrong or it is not implemented.\n" + ex);
} }
} }

View file

@ -157,25 +157,28 @@ namespace RhythmHeavenMania
if (Conductor.instance.songPositionInBeats >= entities[currentEvent] /*&& SongPosLessThanClipLength(Conductor.instance.songPositionInBeats)*/) if (Conductor.instance.songPositionInBeats >= entities[currentEvent] /*&& SongPosLessThanClipLength(Conductor.instance.songPositionInBeats)*/)
{ {
// allows for multiple events on the same beat to be executed on the same frame, so no more 1-frame delay // allows for multiple events on the same beat to be executed on the same frame, so no more 1-frame delay
var entitesAtSameBeat = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && !EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(c.datamodel.Split('/')[0]))); var entitiesAtSameBeat = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && !EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(c.datamodel.Split('/')[0])));
var fxEntities = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(c.datamodel.Split('/')[0]))); var fxEntities = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(c.datamodel.Split('/')[0])));
// FX entities should ALWAYS execute before gameplay entities // FX entities should ALWAYS execute before gameplay entities
for (int i = 0; i < fxEntities.Count; i++) for (int i = 0; i < fxEntities.Count; i++)
{ {
eventCaller.CallEvent(fxEntities[i]); eventCaller.CallEvent(fxEntities[i], true);
currentEvent++; currentEvent++;
} }
for (int i = 0; i < entitesAtSameBeat.Count; i++) for (int i = 0; i < entitiesAtSameBeat.Count; i++)
{ {
var entity = entitesAtSameBeat[i]; var entity = entitiesAtSameBeat[i];
// if game isn't loaded, preload game so whatever event that would be called will still run outside if needed // if game isn't loaded, preload game so whatever event that would be called will still run outside if needed
if (entitesAtSameBeat[i].datamodel.Split('/')[0] != currentGame && !preloadedGames.Contains(preloadedGames.Find(c => c.name == entitesAtSameBeat[i].datamodel.Split('/')[0]))) if (entitiesAtSameBeat[i].datamodel.Split('/')[0] != currentGame && !preloadedGames.Contains(preloadedGames.Find(c => c.name == entitiesAtSameBeat[i].datamodel.Split('/')[0])))
{ {
PreloadGame(entitesAtSameBeat[i].datamodel.Split('/')[0]); eventCaller.CallEvent(entitiesAtSameBeat[i], false);
}
else
{
eventCaller.CallEvent(entitiesAtSameBeat[i], true);
} }
eventCaller.CallEvent(entitesAtSameBeat[i]);
// Thank you to @shshwdr for bring this to my attention // Thank you to @shshwdr for bring this to my attention
currentEvent++; currentEvent++;
@ -322,22 +325,28 @@ namespace RhythmHeavenMania
#endregion #endregion
public void SwitchGame(string game) public void SwitchGame(string game, float beat)
{ {
if (game != currentGame) if (game != currentGame)
{ {
if (currentGameSwitchIE != null) if (currentGameSwitchIE != null)
StopCoroutine(currentGameSwitchIE); StopCoroutine(currentGameSwitchIE);
currentGameSwitchIE = StartCoroutine(SwitchGameIE(game)); currentGameSwitchIE = StartCoroutine(SwitchGameIE(game, beat));
} }
} }
IEnumerator SwitchGameIE(string game) IEnumerator SwitchGameIE(string game, float beat)
{ {
this.GetComponent<SpriteRenderer>().enabled = true; this.GetComponent<SpriteRenderer>().enabled = true;
SetGame(game); SetGame(game);
yield return new WaitForEndOfFrame(); //this is needed so that the minigame can have Start() called before OnGameSwitch()
Minigame miniGame = currentGameO.GetComponent<Minigame>();
if (miniGame != null)
miniGame.OnGameSwitch(beat);
yield return new WaitForSeconds(0.1f); yield return new WaitForSeconds(0.1f);
this.GetComponent<SpriteRenderer>().enabled = false; this.GetComponent<SpriteRenderer>().enabled = false;
@ -372,7 +381,6 @@ namespace RhythmHeavenMania
currentGameO.transform.parent = eventCaller.GamesHolder.transform; currentGameO.transform.parent = eventCaller.GamesHolder.transform;
currentGameO.name = game; currentGameO.name = game;
} }
/*if (onGameSwitch) /*if (onGameSwitch)
{ {
if (GetGame(currentGame).GetComponent<Minigame>() != null) if (GetGame(currentGame).GetComponent<Minigame>() != null)
@ -421,12 +429,6 @@ namespace RhythmHeavenMania
return EventCaller.instance.minigames.Find(c => c.name == name); return EventCaller.instance.minigames.Find(c => c.name == name);
} }
// never gonna use this
public Minigames.Minigame GetCurrentGame()
{
return eventCaller.minigames.Find(c => c.name == transform.GetComponentsInChildren<Transform>()[1].name);
}
public void SetCurrentGame(string game) public void SetCurrentGame(string game)
{ {
currentGame = game; currentGame = game;

View file

@ -1,11 +1,9 @@
using System.Collections; using DG.Tweening;
using NaughtyBezierCurves;
using RhythmHeavenMania.Util;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using System;
using NaughtyBezierCurves;
using DG.Tweening;
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.CropStomp namespace RhythmHeavenMania.Games.CropStomp
{ {
@ -24,6 +22,7 @@ namespace RhythmHeavenMania.Games.CropStomp
private int currentMarchBeat; private int currentMarchBeat;
private int stepCount; private int stepCount;
private bool isStepping; private bool isStepping;
private static float inactiveStart = -1f;
public bool isMarching => marchStartBeat != -1f; public bool isMarching => marchStartBeat != -1f;
@ -118,6 +117,21 @@ namespace RhythmHeavenMania.Games.CropStomp
} }
} }
public override void OnGameSwitch(float beat)
{
if(inactiveStart != -1f)
{
StartMarching(inactiveStart);
float diff = beat - marchStartBeat;
newBeat = (Mathf.Ceil(diff) + marchStartBeat-1)*Conductor.instance.secPerBeat;
currentMarchBeat = Mathf.CeilToInt(diff);
stepCount = currentMarchBeat / 2;
farmer.nextStompBeat = newBeat/Conductor.instance.secPerBeat;
inactiveStart = -1f;
PlayAnims();
}
}
List<Beatmap.Entity> cuedMoleSounds = new List<Beatmap.Entity>(); List<Beatmap.Entity> cuedMoleSounds = new List<Beatmap.Entity>();
private void Update() private void Update()
{ {
@ -143,38 +157,17 @@ namespace RhythmHeavenMania.Games.CropStomp
if (!isMarching) if (!isMarching)
return; return;
Debug.Log(newBeat);
if (cond.ReportBeat(ref newBeat, marchOffset, true)) if (cond.ReportBeat(ref newBeat, marchOffset, true))
{ {
currentMarchBeat += 1; currentMarchBeat += 1;
// Step. PlayAnims();
if (currentMarchBeat % 2 != 0) if (currentMarchBeat % 2 != 0) //step sound
{ {
// Don't step if already stomped.
if (!isStepping)
{
stepCount += 1;
var stepAnim = (stepCount % 2 != 0 ? "StepFront" : "StepBack");
legsAnim.Play(stepAnim, 0, 0);
isStepping = true;
}
Jukebox.PlayOneShotGame("cropStomp/hmm"); Jukebox.PlayOneShotGame("cropStomp/hmm");
} }
// Lift.
else
{
var liftAnim = (stepCount % 2 != 0 ? "LiftBack" : "LiftFront");
legsAnim.Play(liftAnim, 0, 0);
var farmerPos = farmerTrans.localPosition;
farmerTrans.localPosition = new Vector3(farmerPos.x - stepDistance, farmerPos.y, farmerPos.z);
isStepping = false;
}
} }
// Object scroll. // Object scroll.
@ -214,6 +207,36 @@ namespace RhythmHeavenMania.Games.CropStomp
isFlicking = false; isFlicking = false;
} }
private void PlayAnims()
{
// Step.
if (currentMarchBeat % 2 != 0)
{
// Don't step if already stomped.
if (!isStepping)
{
stepCount += 1;
var stepAnim = (stepCount % 2 != 0 ? "StepFront" : "StepBack");
legsAnim.Play(stepAnim, 0, 0);
isStepping = true;
}
}
// Lift.
else
{
var liftAnim = (stepCount % 2 != 0 ? "LiftBack" : "LiftFront");
legsAnim.Play(liftAnim, 0, 0);
var farmerPos = farmerTrans.localPosition;
farmerTrans.localPosition = new Vector3(farmerPos.x - stepDistance, farmerPos.y, farmerPos.z);
isStepping = false;
}
}
public void StartMarching(float beat) public void StartMarching(float beat)
{ {
marchStartBeat = beat; marchStartBeat = beat;
@ -257,5 +280,24 @@ namespace RhythmHeavenMania.Games.CropStomp
newVeggie.gameObject.SetActive(true); newVeggie.gameObject.SetActive(true);
} }
public static void MarchInactive(float beat)
{
if (GameManager.instance.currentGame == "cropStomp") //this function is only meant for making march sounds while the game is inactive
{
return;
}
inactiveStart = beat;
Beatmap.Entity gameSwitch = GameManager.instance.Beatmap.entities.Find(c => c.beat >= beat && c.datamodel == "gameManager/switchGame/cropStomp");
if (gameSwitch == null)
return;
int length = Mathf.CeilToInt((gameSwitch.beat - beat)/2);
MultiSound.Sound[] sounds = new MultiSound.Sound[length];
for(int i = 0; i < length; i++)
{
sounds[i] = new MultiSound.Sound("cropStomp/hmm", beat + i*2);
}
MultiSound.Play(sounds, forcePlay:true);
}
} }
} }

View file

@ -37,8 +37,9 @@ namespace RhythmHeavenMania.Games.ForkLifter
instance = this; instance = this;
} }
public override void OnGameSwitch() public override void OnGameSwitch(float beat)
{ {
base.OnGameSwitch(beat);
ForkLifterHand.CheckNextFlick(); ForkLifterHand.CheckNextFlick();
} }

View file

@ -120,9 +120,9 @@ namespace RhythmHeavenMania.Games.KarateMan
Shadow = 0; Shadow = 0;
} }
public override void OnGameSwitch() public override void OnGameSwitch(float beat)
{ {
base.OnGameSwitch(); base.OnGameSwitch(beat);
SetBackgroundColor((int)BGType, (int)Shadow, BGColor, ShadowColor); SetBackgroundColor((int)BGType, (int)Shadow, BGColor, ShadowColor);
} }

View file

@ -44,9 +44,20 @@ namespace RhythmHeavenMania.Games
public int firstEnable = 0; public int firstEnable = 0;
public virtual void OnGameSwitch() public virtual void OnGameSwitch(float beat)
{ {
//Below is a template that can be used for handling previous entities.
//section below is if you only want to look at entities that overlap the game switch
/*
List<Beatmap.Entity> prevEntities = GameManager.instance.Beatmap.entities.FindAll(c => c.beat <= beat && c.datamodel.Split(0) == [insert game name]);
foreach(Beatmap.Entity entity in prevEntities)
{
if(entity.beat + entity.length >= beat)
{
EventCaller.instance.CallEvent(entity, true);
}
}
*/
} }
public virtual void OnTimeChange() public virtual void OnTimeChange()

View file

@ -14,6 +14,7 @@ namespace RhythmHeavenMania.Games.MrUpbeat
public GameObject metronome; public GameObject metronome;
public UpbeatMan man; public UpbeatMan man;
public GameObject bt; public GameObject bt;
private static MultiSound beeps; //only used when this game isn't active.
public GameEvent beat = new GameEvent(); public GameEvent beat = new GameEvent();
public bool canGo = false; public bool canGo = false;
@ -70,6 +71,28 @@ namespace RhythmHeavenMania.Games.MrUpbeat
} }
} }
public override void OnGameSwitch(float beat)
{
foreach (Beatmap.Entity entity in GameManager.instance.Beatmap.entities)
{
if (entity.beat > beat) //the list is sorted based on the beat of the entity, so this should work fine.
{
break;
}
if (entity.datamodel != "mrUpbeat/prepare" || entity.beat + entity.length < beat) //check for prepares that happen before the switch
{
continue;
}
SetInterval(entity.beat);
break;
}
if(beeps != null)
{
beeps.Delete(); //the beeps are only for when the game isn't active
beeps = null;
}
}
public void SetInterval(float beat) public void SetInterval(float beat)
{ {
beatCount = 0; beatCount = 0;
@ -105,5 +128,23 @@ namespace RhythmHeavenMania.Games.MrUpbeat
yield return new WaitForSeconds(Conductor.instance.secPerBeat * 0.5f - offset); yield return new WaitForSeconds(Conductor.instance.secPerBeat * 0.5f - offset);
man.Blip(); man.Blip();
} }
public static void Beep(float beat, float length)
{
if(GameManager.instance.currentGame == "mrUpbeat") //this function is only meant for making beeps while the game is inactive
{
return;
}
if (beeps != null)
{
beeps.Delete();
}
MultiSound.Sound[] beepSounds = new MultiSound.Sound[Mathf.CeilToInt(length)];
for(int i = 0; i < beepSounds.Length; i++)
{
beepSounds[i] = new MultiSound.Sound("mrUpbeat/blip", beat + 0.5f + i);
}
beeps = MultiSound.Play(beepSounds, forcePlay:true);
}
} }
} }

View file

@ -44,21 +44,6 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
startBeat = dispensedBeat; startBeat = dispensedBeat;
nextAnimBeat = startBeat + GetAnimLength(State.Dispensing); nextAnimBeat = startBeat + GetAnimLength(State.Dispensing);
kicker.kickTimes = 0; kicker.kickTimes = 0;
if (kicker.player)
{
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound("spaceSoccer/dispenseNoise", dispensedBeat),
new MultiSound.Sound("spaceSoccer/dispenseTumble1", dispensedBeat + 0.25f),
new MultiSound.Sound("spaceSoccer/dispenseTumble2", dispensedBeat + 0.5f),
new MultiSound.Sound("spaceSoccer/dispenseTumble2B",dispensedBeat + 0.5f),
new MultiSound.Sound("spaceSoccer/dispenseTumble3", dispensedBeat + 0.75f),
new MultiSound.Sound("spaceSoccer/dispenseTumble4", dispensedBeat + 1f),
new MultiSound.Sound("spaceSoccer/dispenseTumble5", dispensedBeat + 1.25f),
new MultiSound.Sound("spaceSoccer/dispenseTumble6", dispensedBeat + 1.5f),
new MultiSound.Sound("spaceSoccer/dispenseTumble6B",dispensedBeat + 1.75f),
});
}
return; return;
} }

View file

@ -45,22 +45,59 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
} }
public void Dispense(float beat) public override void OnGameSwitch(float beat)
{ {
foreach(Beatmap.Entity entity in GameManager.instance.Beatmap.entities)
{
if(entity.beat > beat) //the list is sorted based on the beat of the entity, so this should work fine.
{
break;
}
if(entity.datamodel != "spaceSoccer/ball dispense" || entity.beat + entity.length <= beat) //check for dispenses that happen right before the switch
{
continue;
}
Dispense(entity.beat, false);
break;
}
}
public void Dispense(float beat, bool playSound = true)
{
ballDispensed = true;
for (int i = 0; i < kickers.Count; i++) for (int i = 0; i < kickers.Count; i++)
{ {
Kicker kicker = kickers[i]; Kicker kicker = kickers[i];
if (i == 0) kicker.player = true; if (i == 0) kicker.player = true;
if (kicker.ball != null) return; if (kicker.ball != null) return;
ballDispensed = true;
GameObject ball = Instantiate(ballRef, transform); GameObject ball = Instantiate(ballRef, transform);
ball.SetActive(true); ball.SetActive(true);
Ball ball_ = ball.GetComponent<Ball>(); Ball ball_ = ball.GetComponent<Ball>();
ball_.Init(kicker, beat); ball_.Init(kicker, beat);
if (kicker.player && playSound)
{
DispenseSound(beat);
} }
} }
} }
public static void DispenseSound(float beat)
{
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound("spaceSoccer/dispenseNoise", beat),
new MultiSound.Sound("spaceSoccer/dispenseTumble1", beat + 0.25f),
new MultiSound.Sound("spaceSoccer/dispenseTumble2", beat + 0.5f),
new MultiSound.Sound("spaceSoccer/dispenseTumble2B",beat + 0.5f),
new MultiSound.Sound("spaceSoccer/dispenseTumble3", beat + 0.75f),
new MultiSound.Sound("spaceSoccer/dispenseTumble4", beat + 1f),
new MultiSound.Sound("spaceSoccer/dispenseTumble5", beat + 1.25f),
new MultiSound.Sound("spaceSoccer/dispenseTumble6", beat + 1.5f),
new MultiSound.Sound("spaceSoccer/dispenseTumble6B",beat + 1.75f),
}, forcePlay:true);
}
}
} }

View file

@ -37,7 +37,7 @@ namespace RhythmHeavenMania.Games.Spaceball
public static Spaceball instance { get; set; } public static Spaceball instance { get; set; }
public override void OnGameSwitch() public override void OnGameSwitch(float beat)
{ {
for (int i = 1; i < BallsHolder.transform.childCount; i++) for (int i = 1; i < BallsHolder.transform.childCount; i++)
Destroy(BallsHolder.transform.GetChild(i).gameObject); Destroy(BallsHolder.transform.GetChild(i).gameObject);

View file

@ -53,12 +53,21 @@ namespace RhythmHeavenMania
public bool resizable; public bool resizable;
public List<Param> parameters; public List<Param> parameters;
public bool hidden; public bool hidden;
public EventCallback inactiveFunction;
/* If you want to add additional arguments to GameAction, leave `bool hidden = false` as the last parameter /// <summary>
* You can specify an action as hidden by adding `hidden: value` as the final parameter in your call /// <para>Creates a block that can be used in the editor. The block's function and attributes are defined in the parentheses.</para>
* (Even if you haven't used all prior arguments) /// <para>Note: Every parameter after the second one is an optional parameter. You can change optional parameters by adding (name): (value) after the second parameter.</para>
*/ /// </summary>
public GameAction(string actionName, EventCallback function, float defaultLength = 1, bool resizable = false, List<Param> parameters = null, bool hidden = false) /// <param name="actionName">Name of the block</param>
/// <param name="function"><para>What the block does when read during playback</para>
/// <para>Only does this if the game that it is associated with is loaded.</para></param>
/// <param name="defaultLength">How long the block appears in the editor</param>
/// <param name="resizable">Allows the user to resize the block</param>
/// <param name="parameters">Extra parameters for this block that change how it functions.</param>
/// <param name="hidden">Prevents the block from being shown in the game list. Block will still function normally if it is in the timeline.</param>
/// <param name="inactiveFunction">What the block does when read while the game it's associated with isn't loaded.</param>
public GameAction(string actionName, EventCallback function, float defaultLength = 1, bool resizable = false, List<Param> parameters = null, bool hidden = false, EventCallback inactiveFunction = null)
{ {
this.actionName = actionName; this.actionName = actionName;
this.function = function; this.function = function;
@ -66,6 +75,8 @@ namespace RhythmHeavenMania
this.resizable = resizable; this.resizable = resizable;
this.parameters = parameters; this.parameters = parameters;
this.hidden = hidden; this.hidden = hidden;
if(inactiveFunction == null) inactiveFunction = delegate { };
this.inactiveFunction = inactiveFunction;
} }
} }
@ -77,6 +88,12 @@ namespace RhythmHeavenMania
public string propertyCaption; public string propertyCaption;
public string tooltip; public string tooltip;
/// <summary>
/// A parameter that changes the function of a GameAction.
/// </summary>
/// <param name="propertyName">The name of the variable that's being changed. Must be one of the variables in <see cref="Beatmap.Entity"/></param>
/// <param name="parameter">The value of the parameter</param>
/// <param name="propertyCaption">The name shown in the editor. Can be anything you want.</param>
public Param(string propertyName, object parameter, string propertyCaption, string tooltip = "") public Param(string propertyName, object parameter, string propertyCaption, string tooltip = "")
{ {
this.propertyName = propertyName; this.propertyName = propertyName;
@ -94,7 +111,7 @@ namespace RhythmHeavenMania
{ {
new Minigame("gameManager", "Game Manager", "", false, true, new List<GameAction>() new Minigame("gameManager", "Game Manager", "", false, true, new List<GameAction>()
{ {
new GameAction("switchGame", delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame); }, 0.5f), new GameAction("switchGame", delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame, eventCaller.currentEntity.beat); }, 0.5f, inactiveFunction: delegate { GameManager.instance.SwitchGame(eventCaller.currentSwitchGame, eventCaller.currentEntity.beat); }),
new GameAction("end", delegate { Debug.Log("end"); }), new GameAction("end", delegate { Debug.Log("end"); }),
new GameAction("skill star", delegate { }, 1f, true), new GameAction("skill star", delegate { }, 1f, true),
new GameAction("flash", delegate new GameAction("flash", delegate
@ -277,7 +294,8 @@ namespace RhythmHeavenMania
}), }),
new Minigame("spaceSoccer", "Space Soccer", "B888F8", false, false, new List<GameAction>() new Minigame("spaceSoccer", "Space Soccer", "B888F8", false, false, new List<GameAction>()
{ {
new GameAction("ball dispense", delegate { SpaceSoccer.instance.Dispense(eventCaller.currentEntity.beat); }, 2f), new GameAction("ball dispense", delegate { SpaceSoccer.instance.Dispense(eventCaller.currentEntity.beat); }, 2f,
inactiveFunction: delegate { SpaceSoccer.DispenseSound(eventCaller.currentEntity.beat); }),
new GameAction("keep-up", delegate { }, 4f, true), new GameAction("keep-up", delegate { }, 4f, true),
new GameAction("high kick-toe!", delegate { }, 3f, false, new List<Param>() new GameAction("high kick-toe!", delegate { }, 3f, false, new List<Param>()
{ {
@ -370,7 +388,7 @@ namespace RhythmHeavenMania
}), }),
new Minigame("cropStomp", "Crop Stomp", "BFDEA6", false, false, new List<GameAction>() new Minigame("cropStomp", "Crop Stomp", "BFDEA6", false, false, new List<GameAction>()
{ {
new GameAction("start marching", delegate { CropStomp.instance.StartMarching(eventCaller.currentEntity.beat); }, 2f, false), new GameAction("start marching", delegate { CropStomp.instance.StartMarching(eventCaller.currentEntity.beat); }, 2f, false, inactiveFunction: delegate { CropStomp.MarchInactive(eventCaller.currentEntity.beat); }),
new GameAction("veggies", delegate { }, 4f, true), new GameAction("veggies", delegate { }, 4f, true),
new GameAction("mole", delegate { }, 2f, false), new GameAction("mole", delegate { }, 2f, false),
}), }),
@ -381,7 +399,7 @@ namespace RhythmHeavenMania
}), }),
new Minigame("mrUpbeat", "Mr. Upbeat", "FFFFFF", false, false, new List<GameAction>() new Minigame("mrUpbeat", "Mr. Upbeat", "FFFFFF", false, false, new List<GameAction>()
{ {
new GameAction("prepare", delegate { MrUpbeat.instance.SetInterval(eventCaller.currentEntity.beat); }, 0.5f, true), new GameAction("prepare", delegate { MrUpbeat.instance.SetInterval(eventCaller.currentEntity.beat); }, 0.5f, true, inactiveFunction: delegate { MrUpbeat.Beep(eventCaller.currentEntity.beat, eventCaller.currentEntity.length); }),
new GameAction("go", delegate { MrUpbeat.instance.Go(eventCaller.currentEntity.beat); }, 4f, true), new GameAction("go", delegate { MrUpbeat.instance.Go(eventCaller.currentEntity.beat); }, 4f, true),
new GameAction("ding!", delegate { MrUpbeat.instance.Ding(eventCaller.currentEntity.toggle); }, 0.5f, parameters: new List<Param>() new GameAction("ding!", delegate { MrUpbeat.instance.Ding(eventCaller.currentEntity.toggle); }, 0.5f, parameters: new List<Param>()
{ {

View file

@ -87,9 +87,9 @@ namespace RhythmHeavenMania.Util
return audioSource; return audioSource;
} }
public static AudioSource PlayOneShotGame(string name, float beat = -1, float pitch = 1f, float volume = 1f, bool looping = false) public static AudioSource PlayOneShotGame(string name, float beat = -1, float pitch = 1f, float volume = 1f, bool looping = false, bool forcePlay = false)
{ {
if (GameManager.instance.currentGame == name.Split('/')[0]) if (GameManager.instance.currentGame == name.Split('/')[0] || forcePlay)
{ {
return PlayOneShot($"games/{name}", beat, pitch, volume, looping); return PlayOneShot($"games/{name}", beat, pitch, volume, looping);
} }
@ -97,9 +97,9 @@ namespace RhythmHeavenMania.Util
return null; return null;
} }
public static AudioSource PlayOneShotScheduledGame(string name, double targetTime, float pitch = 1f, float volume = 1f, bool looping = false) public static AudioSource PlayOneShotScheduledGame(string name, double targetTime, float pitch = 1f, float volume = 1f, bool looping = false, bool forcePlay = false)
{ {
if (GameManager.instance.currentGame == name.Split('/')[0]) if (GameManager.instance.currentGame == name.Split('/')[0] || forcePlay)
{ {
return PlayOneShotScheduled($"games/{name}", targetTime, pitch, volume, looping); return PlayOneShotScheduled($"games/{name}", targetTime, pitch, volume, looping);
} }

View file

@ -10,6 +10,7 @@ namespace RhythmHeavenMania.Util
private float startBeat; private float startBeat;
private int index; private int index;
private bool game; private bool game;
private bool forcePlay;
public List<Sound> sounds = new List<Sound>(); public List<Sound> sounds = new List<Sound>();
public class Sound public class Sound
@ -25,7 +26,7 @@ namespace RhythmHeavenMania.Util
} }
public static void Play(Sound[] snds, bool game = true) public static MultiSound Play(Sound[] snds, bool game = true, bool forcePlay = false)
{ {
List<Sound> sounds = snds.ToList(); List<Sound> sounds = snds.ToList();
GameObject gameObj = new GameObject(); GameObject gameObj = new GameObject();
@ -33,9 +34,11 @@ namespace RhythmHeavenMania.Util
ms.sounds = sounds; ms.sounds = sounds;
ms.startBeat = sounds[0].beat; ms.startBeat = sounds[0].beat;
ms.game = game; ms.game = game;
ms.forcePlay = forcePlay;
gameObj.name = "MultiSound"; gameObj.name = "MultiSound";
GameManager.instance.SoundObjects.Add(gameObj); GameManager.instance.SoundObjects.Add(gameObj);
return ms;
} }
private void Update() private void Update()
@ -47,7 +50,7 @@ namespace RhythmHeavenMania.Util
if (songPositionInBeats >= sounds[i].beat && index == i) if (songPositionInBeats >= sounds[i].beat && index == i)
{ {
if (game) if (game)
Jukebox.PlayOneShotGame(sounds[i].name); Jukebox.PlayOneShotGame(sounds[i].name, forcePlay:forcePlay);
else else
Jukebox.PlayOneShot(sounds[i].name); Jukebox.PlayOneShot(sounds[i].name);
@ -57,8 +60,14 @@ namespace RhythmHeavenMania.Util
if (songPositionInBeats >= (sounds[sounds.Count - 1].beat)) if (songPositionInBeats >= (sounds[sounds.Count - 1].beat))
{ {
Destroy(this.gameObject); Delete();
} }
} }
public void Delete()
{
GameManager.instance.SoundObjects.Remove(gameObject);
Destroy(gameObject);
}
} }
} }

View file

@ -80,10 +80,16 @@ namespace RhythmHeavenMania.Util
if (!looping) // Looping sounds are destroyed manually. if (!looping) // Looping sounds are destroyed manually.
{ {
yield return new WaitForSeconds(clip.length); yield return new WaitForSeconds(clip.length);
Destroy(this.gameObject); Delete();
} }
} }
public void Delete()
{
GameManager.instance.SoundObjects.Remove(gameObject);
Destroy(gameObject);
}
public void KillLoop(float fadeTime) public void KillLoop(float fadeTime)
{ {
StartCoroutine(FadeLoop(fadeTime)); StartCoroutine(FadeLoop(fadeTime));
@ -101,7 +107,7 @@ namespace RhythmHeavenMania.Util
yield return null; yield return null;
} }
Destroy(this.gameObject); Delete();
} }
} }
} }