Beispiel #1
0
        public void Update()
        {
            if (gamePauseManager.pause)
            {
                return;                         //Don't do anything if we're paused
            }
            //if (audioTimeSyncController.songTime > 10f && playlist.Count > 0 && !_loadingSong)
            if (audioTimeSyncController.songTime >= audioTimeSyncController.songLength - 0.3f && playlist.Count > 0 && !_loadingSong)
            {
                Logger.Debug("Switching song...");

                audioTimeSyncController.StopSong(); //If we don't, there's a chance the song would progress to `songLength - 0.2f` and the base game would finish the game scene

                Logger.Debug($"Current song: {gameplayCoreSceneSetupData.difficultyBeatmap.level.songName}");

                //Clear out old data from objects that would have ideally been recreated
                ClearOldData();

                //Set up new song
                var   gameplayModifiers      = gameplayCoreSceneSetupData.gameplayModifiers;
                var   playerSpecificSettings = gameplayCoreSceneSetupData.playerSpecificSettings;
                float songSpeedMul           = gameplayModifiers.songSpeedMul;

                var level = playlist.Dequeue();

                //Load song if it's a custom level
                if (level is CustomPreviewBeatmapLevel)
                {
                    var task = Task.Run(async() => await SongHelpers.GetLevelFromPreview(level));
                    task.Wait();

                    var result = task.Result;

                    if (result != null && !(result?.isError == true))
                    {
                        level = result?.beatmapLevel;
                    }
                }

                Logger.Debug($"New song: {level.songName}");

                var oldMap = gameplayCoreSceneSetupData.difficultyBeatmap;

                Logger.Debug($"Getting closest difficulty to {gameplayCoreSceneSetupData.difficultyBeatmap.difficulty} with characteristic {gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic}...");
                IDifficultyBeatmap map = SongHelpers.GetClosestDifficultyPreferLower(level as IBeatmapLevel, (BeatmapDifficulty)preferredDifficulty, gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic);

                Logger.Debug($"Got: {map.difficulty} ({map.parentDifficultyBeatmapSet.beatmapCharacteristic})");

                gameplayCoreSceneSetupData.SetField("_difficultyBeatmap", map);
                BeatmapData beatmapData = BeatDataTransformHelper.CreateTransformedBeatmapData(map.beatmapData, gameplayModifiers, gameplayCoreSceneSetupData.practiceSettings, gameplayCoreSceneSetupData.playerSpecificSettings);
                beatmapDataModel.beatmapData = beatmapData;

                //If this is the last song, set up the viewcontrollers in a way that the proper data is displayed after the song
                var currentPack            = levelDetailViewController.GetField <IBeatmapLevelPack>("_pack");
                var currentPlayer          = levelDetailViewController.GetField <PlayerData>("_playerData");
                var currentShowPlayerStats = levelDetailViewController.GetField <bool>("_showPlayerStats");
                levelDetailViewController.SetData(currentPack, map.level, currentPlayer, currentShowPlayerStats);

                audioTimeSyncController.Init(map.level.beatmapLevelData.audioClip, 0f, map.level.songTimeOffset, songSpeedMul);
                beatmapObjectSpawnController.Init(level.beatsPerMinute, beatmapData.beatmapLinesData.Length, gameplayModifiers.fastNotes ? 20f : (map.noteJumpMovementSpeed == 0 ? map.difficulty.NoteJumpMovementSpeed() : map.noteJumpMovementSpeed), map.noteJumpStartBeatOffset, gameplayModifiers.disappearingArrows, gameplayModifiers.ghostNotes);
                pauseMenuManager.Init(map.level.songName, map.level.songSubName, map.difficulty.Name());

                //Deal with characteristic issues
                Saber.SaberType saberType;
                if (gameplayCoreSceneSetup.UseOneSaberOnly(map.parentDifficultyBeatmapSet.beatmapCharacteristic, playerSpecificSettings, out saberType))
                {
                    gameplayCoreSceneSetup.GetField <PlayerController>("_playerController").AllowOnlyOneSaber(saberType);
                }
                else
                {
                    gameplayCoreSceneSetup
                    .GetField <PlayerController>("_playerController")
                    .GetField <SaberManager>("_saberManager")
                    .SetField("_allowOnlyOneSaber", false);
                }

                Logger.Debug("Starting new song...");
                audioTimeSyncController.StartSong();
                Logger.Debug("Song started!");

                songSwitched?.Invoke(oldMap, map);

                _loadingSong = false;
            }
            //else if (audioTimeSyncController.songTime > 10f && (playlist == null || playlist.Count <= 0) && !_loadingSong)
            else if (audioTimeSyncController.songTime >= audioTimeSyncController.songLength - 0.3f && (playlist == null || playlist.Count <= 0))
            {
                _loadingSong = true; //Only show the following log message once
                Logger.Debug($"Would have switched songs, but playlist was null ({playlist == null}) or empty ({playlist?.Count <= 0})");
            }
        }