示例#1
0
        private void NextSong()
        {
            if (songPreloaded)
            {
                Plugin.log.Info("Loading next level");
                if (nextLevel != null)
                {
                    float duration = nextLevel.levelResult.beatmapLevel.songDuration;

                    if (duration < 1f)
                    {
                        var c = nextLevel.levelResult.beatmapLevel.beatmapLevelData.audioClip;
                        duration = c.length;
                    }

                    Plugin.log.Info($"Next level song duration: {duration}");

                    // We have to account for speed also.
                    TrackSong(duration / nextLevel.speed);
                    LevelLoader.SwitchLevel(nextLevel);
                    songPreloaded     = false;
                    nextLevel         = null;
                    nextSongTextShown = false;
                    Plugin.log.Info("Level switched.");
                }
            }
            else
            {
                // No more songs in the queue. Leave?
                Plugin.log.Info("Queue empty. Leaving session.");
                Client.Disconnect();
            }
        }
示例#2
0
        private void PreloadSong()
        {
            var song = SongQueue.Dequeue();

            Plugin.log.Info($"Preloading song {song.LevelID}");

            songPreloaded = true;

            var characteristic = LevelLoader.Characteristics.First(c => c.serializedName == song.Characteristic);
            var gameplay       = GameplayModifiers.defaultModifiers;

            // Level IDs prefixed with 'bsaber.com/' are custom songs.
            if (song.LevelID.StartsWith("bsaber.com/"))
            {
                var split = song.LevelID.Split('/');
                CustomSongInjector.StartSongDownload("https://beatsaver.com/api/download/key/" + split[1],
                                                     (level) =>
                {
                    LevelLoader.PreloadBeatmapLevelAsync(
                        characteristic,
                        level,
                        song.Difficulty,
                        gameplay,
                        (preloadedLevel) =>
                    {
                        if (preloadedLevel == null)
                        {
                            Plugin.log.Info("Level did not preload correctly..");
                            return;
                        }

                        nextLevel       = preloadedLevel;
                        nextLevel.speed = (float)song.Speed;

                        Plugin.log.Info($"Song {song.LevelID} has been preloaded!");
                    }
                        );
                },
                                                     () =>
                {
                    // Download fail, wat do?
                    Plugin.log.Error("Download failed. Leaving session...");
                    Client.Disconnect();
                });
            }
            else
            {
                var level = LevelLoader.AllLevels.First(l => l.levelID == song.LevelID);
                LevelLoader.PreloadBeatmapLevelAsync(
                    characteristic,
                    level,
                    song.Difficulty,
                    gameplay,
                    (preloadedLevel) =>
                {
                    nextLevel = preloadedLevel;

                    nextLevel.speed = (float)song.Speed;
                    Plugin.log.Info($"Song {song.LevelID} has been preloaded!");
                }
                    );
            }
        }