diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 673a98f32..e630566e3 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -371,7 +371,7 @@ namespace HeavenStudio List entitiesAtSameBeat = ListPool.Get(); Minigames.Minigame inf; - //seek ahead to preload games that have assetbundles + // seek ahead to preload games that have assetbundles if (currentPreSwitch < allGameSwitches.Count && currentPreSwitch >= 0) { if (start + seekTime >= allGameSwitches[currentPreSwitch].beat) @@ -722,7 +722,7 @@ namespace HeavenStudio conductor.SetVolume(Beatmap.VolumeChanges[0]["volume"]); conductor.firstBeatOffset = Beatmap.data.offset; conductor.PlaySetup(beat); - SetCurrentEventToClosest(beat); + SetCurrentEventToClosest(beat, true); Debug.Log("Playing at " + beat); KillAllSounds(); @@ -844,7 +844,7 @@ namespace HeavenStudio WaitUntil yieldBeatmap = new WaitUntil(() => Beatmap != null && BeatmapEntities() > 0); WaitUntil yieldAudio = new WaitUntil(() => AudioLoadDone || (ChartLoadError && !GlobalGameManager.IsShowingDialog)); WaitUntil yieldGame = null; - List gamesToPreload = SeekAheadAndPreload(beat, 4f); + List gamesToPreload = SetCurrentEventToClosest(beat, true); Debug.Log($"Preloading {gamesToPreload.Count} games"); if (gamesToPreload.Count > 0) { @@ -973,9 +973,10 @@ namespace HeavenStudio return 0; } - public void SetCurrentEventToClosest(double beat, bool canPreload = false) + public List SetCurrentEventToClosest(double beat, bool canPreload = false) { SortEventsList(); + List preload = new(); onBeatChanged?.Invoke(beat); if (Beatmap.Entities.Count > 0) { @@ -983,15 +984,13 @@ namespace HeavenStudio currentPreEvent = GetIndexAfter(eventBeats, beat); currentPreSequence = GetIndexAfter(eventBeats, beat); - var gameSwitchs = Beatmap.Entities.FindAll(c => c.datamodel.Split("/")[1] == "switchGame"); - string newGame = Beatmap.Entities[Math.Min(currentEvent, eventBeats.Count - 1)].datamodel.Split(0); - if (gameSwitchs.Count > 0) + if (allGameSwitches.Count > 0) { - int index = GetIndexBefore(gameSwitchs.Select(c => c.beat).ToList(), beat); + int index = GetIndexBefore(allGameSwitches.Select(c => c.beat).ToList(), beat); currentPreSwitch = index; - var closestGameSwitch = gameSwitchs[index]; + var closestGameSwitch = allGameSwitches[index]; if (closestGameSwitch.beat <= beat) { newGame = closestGameSwitch.datamodel.Split(2); @@ -1006,7 +1005,7 @@ namespace HeavenStudio { if (index - 1 >= 0) { - newGame = gameSwitchs[index - 1].datamodel.Split(2); + newGame = allGameSwitches[index - 1].datamodel.Split(2); } else { @@ -1014,13 +1013,17 @@ namespace HeavenStudio } } } - // newGame = gameSwitchs[gameSwitchs.IndexOf(gameSwitchs.Find(c => c.beat == MathUtils.GetClosestInList(gameSwitchs.Select(c => c.beat).ToList(), beat)))].datamodel.Split(2); } if (!GetGameInfo(newGame).fxOnly) { if (canPreload) { + Minigames.Minigame inf = GetGameInfo(newGame); + if (inf != null) + { + preload.Add(inf); + } StartCoroutine(WaitAndSetGame(newGame)); } else @@ -1090,7 +1093,8 @@ namespace HeavenStudio } onSectionChange?.Invoke(currentSection, lastSection); - SeekAheadAndPreload(beat); + preload.AddRange(SeekAheadAndPreload(beat)); + return preload; } #endregion diff --git a/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs b/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs index 0e1c6f5de..2053c659a 100644 --- a/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs +++ b/Assets/Scripts/Games/MrUpbeat/MrUpbeat.cs @@ -10,7 +10,8 @@ namespace HeavenStudio.Games.Loaders using static Minigames; public static class AgbUpbeatLoader { - public static Minigame AddGame(EventCaller eventCaller) { + public static Minigame AddGame(EventCaller eventCaller) + { RiqEntity BackgroundUpdater(string datamodel, RiqEntity e) { if (datamodel == "mrUpbeat/changeBG" && e.dynamicData.ContainsKey("toggle") && !e.dynamicData.ContainsKey("ease")) @@ -133,9 +134,9 @@ namespace HeavenStudio.Games.Loaders resizable = true, }, }, - new List() {"agb", "keep"}, + new List() { "agb", "keep" }, "agboffbeat", "en", - new List() {}, + new List() { }, chronologicalSortKey: 101 ); } @@ -197,7 +198,8 @@ namespace HeavenStudio.Games { List prevEntities = GameManager.instance.Beatmap.Entities.FindAll(c => c.beat <= beat && c.datamodel.Split(0) == "mrUpbeat"); - if (beat >= startBlippingBeat) { + if (beat >= startBlippingBeat) + { double tempBeat = ((beat % 1 == 0.5) ? Mathf.Floor((float)beat) : Mathf.Round((float)beat)) + (startBlippingBeat % 1); BeatAction.New(instance, new List() { new BeatAction.Action(tempBeat, delegate { man.RecursiveBlipping(tempBeat); }) @@ -209,17 +211,22 @@ namespace HeavenStudio.Games var bgColorEntity = prevEntities.FindLast(x => x.datamodel.Split(1) == "changeBG" && x.beat <= beat); var upbeatColorEntity = prevEntities.FindLast(x => x.datamodel.Split(1) == "upbeatColors" && x.beat <= beat); - if (bgColorEntity != null) { + if (bgColorEntity != null) + { bg.color = bgColorEntity["end"]; } - - if (upbeatColorEntity != null) { + + if (upbeatColorEntity != null) + { blipMaterial.SetColor("_ColorBravo", upbeatColorEntity["blipColor"]); Color shadowColor = upbeatColorEntity["shadowColor"]; - if (upbeatColorEntity["setShadow"]) foreach (var shadow in shadowSr) { - shadow.color = new Color(shadowColor.r, shadowColor.g, shadowColor.b, 1); - } - } else { + if (upbeatColorEntity["setShadow"]) foreach (var shadow in shadowSr) + { + shadow.color = new Color(shadowColor.r, shadowColor.g, shadowColor.b, 1); + } + } + else + { blipMaterial.SetColor("_ColorBravo", new Color(0, 1f, 0)); } } @@ -227,31 +234,33 @@ namespace HeavenStudio.Games public void Update() { bg.color = bgColorEase.GetColor(); - if (conductor.isPlaying && !conductor.isPaused) { - var songPos = conductor.songPositionInBeatsAsDouble; + if (conductor.isPlaying && !conductor.isPaused) + { + double songPos = conductor.songPositionInBeatsAsDouble; - if (songPos >= startSteppingBeat - 2) { + if (songPos >= startSteppingBeat - 2) + { man.canStep = true; } - if (songPos >= startSteppingBeat) { + if (songPos >= startSteppingBeat) + { RecursiveStepping(startSteppingBeat); startSteppingBeat = double.MaxValue; } - if (songPos >= startBlippingBeat) { + if (songPos >= startBlippingBeat) + { man.RecursiveBlipping(startBlippingBeat); startBlippingBeat = double.MaxValue; } - if (songPos > metronomeBeat + 1) + if (metronomeBeat != double.MaxValue) { - metronomeAnim.Play("MetronomeGo" + currentMetronomeDir, -1, 1); - metronomeAnim.speed = 0; - } - else if (songPos >= metronomeBeat) - { - metronomeAnim.DoScaledAnimation("MetronomeGo" + currentMetronomeDir, metronomeBeat, 1, ignoreSwing: false); + currentMetronomeDir = songPos >= metronomeBeat && songPos <= metronomeBeat + 1 + ? (stepIterate % 2 == 0) ? "Right" : "Left" + : (stepIterate % 2 == 1) ? "Right" : "Left"; + metronomeAnim.DoScaledAnimation("MetronomeGo" + currentMetronomeDir, metronomeBeat, 1, clamp: true, ignoreSwing: false); } } } @@ -282,7 +291,8 @@ namespace HeavenStudio.Games public static void PrePrepare(double beat, float length, bool mrDownbeat) { bool isGame = GameManager.instance.currentGame == "mrUpbeat"; - if (!mrDownbeat) { + if (!mrDownbeat) + { beat = Mathf.Floor((float)beat) + 0.5; length = Mathf.Round(length); } @@ -299,12 +309,12 @@ namespace HeavenStudio.Games private void RecursiveStepping(double beat) { - if (stopStepping) { + if (stopStepping) + { stopStepping = false; return; } - currentMetronomeDir = (stepIterate % 2 == 1) ? "Right" : "Left"; - SoundByte.PlayOneShotGame($"mrUpbeat/metronome{currentMetronomeDir}"); + SoundByte.PlayOneShotGame($"mrUpbeat/metronome{((stepIterate % 2 == 1) ? "Right" : "Left")}"); metronomeBeat = beat; ScheduleStep(beat); BeatAction.New(this, new List() { @@ -319,9 +329,9 @@ namespace HeavenStudio.Games for (int i = 0; i < length; i++) { ScheduleStep(beat + i); - actions.Add(new BeatAction.Action(beat + i, delegate { - currentMetronomeDir = (stepIterate % 2 == 1) ? "Right" : "Left"; - SoundByte.PlayOneShotGame($"mrUpbeat/metronome{currentMetronomeDir}"); + actions.Add(new BeatAction.Action(beat + i, delegate + { + SoundByte.PlayOneShotGame($"mrUpbeat/metronome{((stepIterate % 2 == 1) ? "Right" : "Left")}"); metronomeBeat = beat + i; stepIterate++; })); @@ -335,7 +345,8 @@ namespace HeavenStudio.Games if (gameSwitch.beat <= beat || gameSwitch.beat >= beat + length + 1) return; List inactiveBlips = new(); - for (int i = 0; i < gameSwitch.beat - beat; i++) { + for (int i = 0; i < gameSwitch.beat - beat; i++) + { inactiveBlips.Add(new MultiSound.Sound("mrUpbeat/blip", beat + i)); } @@ -362,9 +373,10 @@ namespace HeavenStudio.Games { blipMaterial.SetColor("_ColorBravo", blipColor); - if (setShadow) foreach (var shadow in shadowSr) { - shadow.color = new Color(shadowColor.r, shadowColor.g, shadowColor.b, 1); - } + if (setShadow) foreach (var shadow in shadowSr) + { + shadow.color = new Color(shadowColor.r, shadowColor.g, shadowColor.b, 1); + } } public void BlipEvents(string inputLetter, bool shouldGrow, bool resetBlip, bool shouldBlip, int blipLength) @@ -384,11 +396,12 @@ namespace HeavenStudio.Games public static void CountIn(double beat, float length, bool a) { var sound = new List(); - if (a) sound.Add(new MultiSound.Sound("mrUpbeat/a", beat - (0.5f * (length/4)))); - for (int i = 0; i < 4; i++) { + if (a) sound.Add(new MultiSound.Sound("mrUpbeat/a", beat - (0.5f * (length / 4)))); + for (int i = 0; i < 4; i++) + { sound.Add(new MultiSound.Sound("mrUpbeat/" + (i + 1), beat + (i * (length / 4)), offset: (i == 3) ? 0.05 : 0)); } - + MultiSound.Play(sound.ToArray(), forcePlay: true); }