Skip to content

Commit

Permalink
ignoreSwing parameter for Multisound and BeatAction
Browse files Browse the repository at this point in the history
Adds a new optional parameter to Multisounds, Soundbytes, and BeatActions, allowing them to ignore swing.
Currently the only game to use these new parameters is Launch Party, but whoever codes Donk-Donk in the future will have a small bit of the weight taken off their shoulders.
  • Loading branch information
wookywok authored and minenice55 committed May 14, 2024
1 parent d5179ce commit 4313e35
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 50 deletions.
62 changes: 31 additions & 31 deletions Assets/Scripts/Games/LaunchParty/LaunchPartyRocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public void InitPartyCracker(double beat)
{
new MultiSound.Sound("launchParty/rocket_prepare", beat),
new MultiSound.Sound("launchParty/popper_note", beat, pitches[0]),
new MultiSound.Sound("launchParty/popper_note", beat + 0.66f, pitches[1]),
new MultiSound.Sound("launchParty/popper_note", beat + 1, pitches[2]),
new MultiSound.Sound("launchParty/popper_note", beat + 1.33f, pitches[3]),
new MultiSound.Sound("launchParty/popper_note", beat + 1.66f, pitches[4]),
new MultiSound.Sound("launchParty/popper_note", beat + 0.66f, pitches[1], ignoreSwing: true),
new MultiSound.Sound("launchParty/popper_note", beat + 1, pitches[2], ignoreSwing: true),
new MultiSound.Sound("launchParty/popper_note", beat + 1.33f, pitches[3], ignoreSwing: true),
new MultiSound.Sound("launchParty/popper_note", beat + 1.66f, pitches[4], ignoreSwing: true),
}, forcePlay: true);

BeatAction.New(this, new List<BeatAction.Action>()
Expand All @@ -86,10 +86,10 @@ public void InitPartyCracker(double beat)
number.SetActive(true);
numberAnim.Play("CountFive", 0, 0);
}),
new BeatAction.Action(beat + 0.66f, delegate { numberAnim.Play("CountFour", 0, 0); }),
new BeatAction.Action(beat + 1, delegate { numberAnim.Play("CountThree", 0, 0); }),
new BeatAction.Action(beat + 1.33f, delegate { numberAnim.Play("CountTwo", 0, 0); }),
new BeatAction.Action(beat + 1.66f, delegate { numberAnim.Play("CountOne", 0, 0); }),
new BeatAction.Action(beat + 0.66f, delegate { numberAnim.Play("CountFour", 0, 0); }, ignoreSwing: true),
new BeatAction.Action(beat + 1, delegate { numberAnim.Play("CountThree", 0, 0); }, ignoreSwing: true),
new BeatAction.Action(beat + 1.33f, delegate { numberAnim.Play("CountTwo", 0, 0); }, ignoreSwing: true),
new BeatAction.Action(beat + 1.66f, delegate { numberAnim.Play("CountOne", 0, 0); }, ignoreSwing: true),
});
}

Expand All @@ -101,12 +101,12 @@ public void InitBell(double beat)
{
new MultiSound.Sound("launchParty/rocket_prepare", beat),
new MultiSound.Sound("launchParty/bell_note", beat, pitches[0]),
new MultiSound.Sound("launchParty/bell_short", beat + 1f, pitches[1]),
new MultiSound.Sound("launchParty/bell_short", beat + 1.16f, pitches[2]),
new MultiSound.Sound("launchParty/bell_short", beat + 1.33f, pitches[3]),
new MultiSound.Sound("launchParty/bell_short", beat + 1.5f, pitches[4]),
new MultiSound.Sound("launchParty/bell_short", beat + 1.66f, pitches[5]),
new MultiSound.Sound("launchParty/bell_short", beat + 1.83f, pitches[6]),
new MultiSound.Sound("launchParty/bell_short", beat + 1f, pitches[1], ignoreSwing: true),
new MultiSound.Sound("launchParty/bell_short", beat + 1.16f, pitches[2], ignoreSwing: true),
new MultiSound.Sound("launchParty/bell_short", beat + 1.33f, pitches[3], ignoreSwing: true),
new MultiSound.Sound("launchParty/bell_short", beat + 1.5f, pitches[4], ignoreSwing: true),
new MultiSound.Sound("launchParty/bell_short", beat + 1.66f, pitches[5], ignoreSwing: true),
new MultiSound.Sound("launchParty/bell_short", beat + 1.83f, pitches[6], ignoreSwing: true),
}, forcePlay: true);

BeatAction.New(this, new List<BeatAction.Action>()
Expand All @@ -117,11 +117,11 @@ public void InitBell(double beat)
numberAnim.Play("CountSeven", 0, 0);
}),
new BeatAction.Action(beat + 1f, delegate { numberAnim.Play("CountSix", 0, 0); }),
new BeatAction.Action(beat + 1.16f, delegate { numberAnim.Play("CountFive", 0, 0); }),
new BeatAction.Action(beat + 1.33f, delegate { numberAnim.Play("CountFour", 0, 0); }),
new BeatAction.Action(beat + 1.5f, delegate { numberAnim.Play("CountThree", 0, 0); }),
new BeatAction.Action(beat + 1.66f, delegate { numberAnim.Play("CountTwo", 0, 0); }),
new BeatAction.Action(beat + 1.83f, delegate { numberAnim.Play("CountOne", 0, 0); }),
new BeatAction.Action(beat + 1.16f, delegate { numberAnim.Play("CountFive", 0, 0); }, ignoreSwing: true),
new BeatAction.Action(beat + 1.33f, delegate { numberAnim.Play("CountFour", 0, 0); }, ignoreSwing: true),
new BeatAction.Action(beat + 1.5f, delegate { numberAnim.Play("CountThree", 0, 0); }, ignoreSwing: true),
new BeatAction.Action(beat + 1.66f, delegate { numberAnim.Play("CountTwo", 0, 0); }, ignoreSwing: true),
new BeatAction.Action(beat + 1.83f, delegate { numberAnim.Play("CountOne", 0, 0); }, ignoreSwing: true),
});
}

Expand All @@ -133,18 +133,18 @@ public void InitBowlingPin(double beat)
{
new MultiSound.Sound("launchParty/rocket_pin_prepare", beat),
new MultiSound.Sound("launchParty/pin", beat, pitches[0]),
new MultiSound.Sound("launchParty/flute", beat, pitches[1], 0.02f),
new MultiSound.Sound("launchParty/flute", beat + 0.16f, pitches[2], 0.02f),
new MultiSound.Sound("launchParty/flute", beat + 0.33f, pitches[3], 0.06f),
new MultiSound.Sound("launchParty/flute", beat + 0.5f, pitches[4], 0.1f),
new MultiSound.Sound("launchParty/flute", beat + 0.66f, pitches[5], 0.16f),
new MultiSound.Sound("launchParty/flute", beat + 0.83f, pitches[6], 0.22f),
new MultiSound.Sound("launchParty/flute", beat + 1f, pitches[7], 0.3f),
new MultiSound.Sound("launchParty/flute", beat + 1.16f, pitches[8], 0.4f),
new MultiSound.Sound("launchParty/flute", beat + 1.33f, pitches[9], 0.6f),
new MultiSound.Sound("launchParty/flute", beat + 1.5f, pitches[10], 0.75f),
new MultiSound.Sound("launchParty/flute", beat + 1.66f, pitches[11], 0.89f),
new MultiSound.Sound("launchParty/flute", beat + 1.83f, pitches[12]),
new MultiSound.Sound("launchParty/flute", beat, pitches[1], 0.02f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 0.16f, pitches[2], 0.02f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 0.33f, pitches[3], 0.06f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 0.5f, pitches[4], 0.1f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 0.66f, pitches[5], 0.16f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 0.83f, pitches[6], 0.22f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 1f, pitches[7], 0.3f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 1.16f, pitches[8], 0.4f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 1.33f, pitches[9], 0.6f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 1.5f, pitches[10], 0.75f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 1.66f, pitches[11], 0.89f, ignoreSwing: true),
new MultiSound.Sound("launchParty/flute", beat + 1.83f, pitches[12], ignoreSwing: true),
}, forcePlay: true);

BeatAction.New(this, new List<BeatAction.Action>()
Expand Down
7 changes: 5 additions & 2 deletions Assets/Scripts/Games/Minigame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ protected static bool IA_TouchFlick(out double dt)
/// <param name="OnHit">Method to run if the Input has been Hit</param>
/// <param name="OnMiss">Method to run if the Input has been Missed</param>
/// <param name="OnBlank">Method to run whenever there's an Input while this is Scheduled (Shouldn't be used too much)</param>
/// <param name="ignoreSwing">Pretty much what it says on the tin, ignores swing when active. This'll probably end up being used for a whole one game lmao</param>
/// <returns></returns>
public PlayerActionEvent ScheduleInput(
double startBeat,
Expand All @@ -132,7 +133,8 @@ protected static bool IA_TouchFlick(out double dt)
PlayerActionEvent.ActionEventCallbackState OnHit,
PlayerActionEvent.ActionEventCallback OnMiss,
PlayerActionEvent.ActionEventCallback OnBlank,
PlayerActionEvent.ActionEventHittableQuery HittableQuery = null
PlayerActionEvent.ActionEventHittableQuery HittableQuery = null,
bool ignoreSwing = false
)
{
// List<RiqEntity> gameSwitches = GameManager.instance.Beatmap.Entities.FindAll(c => c.beat <= startBeat + timer && c.datamodel.Split("/")[0] == "switchGame");
Expand All @@ -145,7 +147,8 @@ protected static bool IA_TouchFlick(out double dt)

PlayerActionEvent evt = evtObj.AddComponent<PlayerActionEvent>();

evt.startBeat = startBeat;
if (ignoreSwing) evt.startBeat = Conductor.instance.GetSwungBeat(startBeat);
else evt.startBeat = startBeat;
evt.timer = timer;
evt.InputAction = inputAction;
evt.OnHit = OnHit;
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scripts/Util/BeatAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public class Action
public double beat { get; set; }
public EventCallback function { get; set; }

public Action(double beat, EventCallback function)
public Action(double beat, EventCallback function, bool ignoreSwing = false)
{
this.beat = beat;
if (ignoreSwing) this.beat = Conductor.instance.GetSwungBeat(beat);
else this.beat = beat;
this.function = function;
}
}
Expand Down
17 changes: 11 additions & 6 deletions Assets/Scripts/Util/MultiSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,40 @@ public class Sound
public float volume { get; set; }
public bool looping { get; set; }
public double offset { get; set; }
public bool ignoreSwing {get; set; }

public Sound(string name, double beat, float pitch = 1f, float volume = 1f, bool looping = false, double offset = 0f)
public Sound(string name, double beat, float pitch = 1f, float volume = 1f, bool looping = false, double offset = 0f, bool ignoreSwing = false)
{
this.name = name;
this.beat = beat;

this.pitch = pitch;
this.volume = volume;
this.looping = looping;
this.offset = offset;
if (ignoreSwing) this.beat = Conductor.instance.GetSwungBeat(beat);
else this.beat = beat;
}
}

public static MultiSound Play(Sound[] sounds, bool game = true, bool forcePlay = false)
public static MultiSound Play(Sound[] sounds, bool game = true, bool forcePlay = false, bool ignoreSwing = false)
{
return Play(sounds.ToList(), game, forcePlay);
return Play(sounds.ToList(), game, forcePlay, ignoreSwing);
}

public static MultiSound Play(List<Sound> sounds, bool game = true, bool forcePlay = false)
public static MultiSound Play(List<Sound> sounds, bool game = true, bool forcePlay = false, bool ignoreSwing = false)
{
if (Conductor.instance == null || sounds.Count < 1) return null;

GameObject go = new GameObject("MultiSound");
MultiSound ms = go.AddComponent<MultiSound>();

ms.sounds = sounds;
ms.startBeat = sounds[0].beat;

ms.game = game;
ms.forcePlay = forcePlay;
ms.commited = false;
if (ignoreSwing) ms.startBeat = Conductor.instance.GetSwungBeat(sounds[0].beat);
else ms.startBeat = sounds[0].beat;

if (Conductor.instance.WaitingForDsp)
{
Expand Down
20 changes: 11 additions & 9 deletions Assets/Scripts/Util/SoundByte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public static double GetClipLengthGame(string name, float pitch = 1f)
/// Unpitched, non-scheduled, non-looping sounds are played using a global One-Shot audio source that doesn't create a Sound object.
/// Looped sounds return their created Sound object so they can be canceled after creation.
/// </summary>
public static Sound PlayOneShot(string name, double beat = -1, float pitch = 1f, float volume = 1f, bool looping = false, string game = null, double offset = 0f, bool ignoreConductorPause = false)
public static Sound PlayOneShot(string name, double beat = -1, float pitch = 1f, float volume = 1f, bool looping = false, string game = null, double offset = 0f, bool ignoreConductorPause = false, bool ignoreSwing = false)
{
AudioClip clip = null;
string soundName = name.Split('/')[^1];
Expand Down Expand Up @@ -329,13 +329,14 @@ public static Sound PlayOneShot(string name, double beat = -1, float pitch = 1f,
{
Sound snd = GetAvailableScheduledSound();

snd.clip = clip;
snd.beat = beat;
snd.clip = clip;
snd.pitch = pitch;
snd.volume = volume;
snd.looping = looping;
snd.offset = offset;
snd.ignoreConductorPause = ignoreConductorPause;
if (ignoreSwing) snd.beat = Conductor.instance.GetSwungBeat(beat);
else snd.beat = beat;
snd.Play();

return snd;
Expand All @@ -357,7 +358,7 @@ public static Sound PlayOneShot(string name, double beat = -1, float pitch = 1f,
/// <summary>
/// Schedules a sound to be played at a specific time in seconds.
/// </summary>
public static Sound PlayOneShotScheduled(string name, double targetTime, float pitch = 1f, float volume = 1f, bool looping = false, string game = null, bool ignoreConductorPause = false)
public static Sound PlayOneShotScheduled(string name, double targetTime, float pitch = 1f, float volume = 1f, bool looping = false, string game = null, bool ignoreConductorPause = false, bool ignoreSwing = false)
{
Sound snd = GetAvailableScheduledSound();
AudioClip clip = null;
Expand Down Expand Up @@ -406,7 +407,8 @@ public static Sound PlayOneShotScheduled(string name, double targetTime, float p
snd.looping = looping;

snd.scheduled = true;
snd.scheduledTime = targetTime;
if (ignoreSwing) snd.scheduledTime = Conductor.instance.GetSwungBeat(targetTime);
else snd.scheduledTime = targetTime;
snd.ignoreConductorPause = ignoreConductorPause;
snd.Play();

Expand All @@ -418,13 +420,13 @@ public static Sound PlayOneShotScheduled(string name, double targetTime, float p
/// Unpitched, non-scheduled, non-looping sounds are played using a global One-Shot audio source that doesn't create a Sound object.
/// Looped sounds return their created Sound object so they can be canceled after creation.
/// </summary>
public static Sound PlayOneShotGame(string name, double beat = -1, float pitch = 1f, float volume = 1f, bool looping = false, bool forcePlay = false, double offset = 0f, bool ignoreConductorPause = false)
public static Sound PlayOneShotGame(string name, double beat = -1, float pitch = 1f, float volume = 1f, bool looping = false, bool forcePlay = false, double offset = 0f, bool ignoreConductorPause = false, bool ignoreSwing = false)
{
string gameName = name.Split('/')[0];
var inf = GameManager.instance.GetGameInfo(gameName);
if (GameManager.instance.currentGame == gameName || forcePlay)
{
return PlayOneShot($"games/{name}", beat, pitch, volume, looping, inf.UsesAssetBundle ? gameName : null, offset, ignoreConductorPause);
return PlayOneShot($"games/{name}", beat, pitch, volume, looping, inf.UsesAssetBundle ? gameName : null, offset, ignoreConductorPause, ignoreSwing);
}

return null;
Expand All @@ -434,13 +436,13 @@ public static Sound PlayOneShotGame(string name, double beat = -1, float pitch =
/// Schedules a sound to be played at a specific time in seconds.
/// Audio clip is fetched from minigame resources
/// </summary>
public static Sound PlayOneShotScheduledGame(string name, double targetTime, float pitch = 1f, float volume = 1f, bool looping = false, bool forcePlay = false, bool ignoreConductorPause = false)
public static Sound PlayOneShotScheduledGame(string name, double targetTime, float pitch = 1f, float volume = 1f, bool looping = false, bool forcePlay = false, bool ignoreConductorPause = false, bool ignoreSwing = false)
{
string gameName = name.Split('/')[0];
var inf = GameManager.instance.GetGameInfo(gameName);
if (GameManager.instance.currentGame == gameName || forcePlay)
{
return PlayOneShotScheduled($"games/{name}", targetTime, pitch, volume, looping, inf.UsesAssetBundle ? gameName : null, ignoreConductorPause);
return PlayOneShotScheduled($"games/{name}", targetTime, pitch, volume, looping, inf.UsesAssetBundle ? gameName : null, ignoreConductorPause, ignoreSwing);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,11 @@ MonoBehaviour:
- Assets/Scripts/Games/Fireworks/Fireworks.cs
- Assets/X-PostProcessing/Effects/ColorAdjustmentHue/Editor/ColorAdjustmentHueEditor.cs
- Assets/Scripts/Games/FlipperFlop/FlipperFlop.cs
- Assets/Scripts/Games/LoveLab/LoveLabHearts.cs
- Assets/Scripts/Games/LoveLab/LoveLab.cs
- Assets/Scripts/Games/LoveLab/LoveLabFlask.cs
- Assets/Scripts/Games/LoveLab/LoveLabHeartMisc.cs
- Assets/Scripts/Games/LaunchParty/LaunchPartyRocket.cs
- Assets/Scripts/Util/BeatAction.cs
PathsToSkipImportEvent: []
PathsToIgnoreOverwriteSettingOnAttribute: []

0 comments on commit 4313e35

Please sign in to comment.