예제 #1
0
        private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene)
        {
            SongListUtils.Initialize();

            if (scene.name == "GameCore")
            {
                _isInGame = true;
            }
            if (scene.name != "Menu")
            {
                return;
            }
            _isInGame = false;

            _standardLevelSelectionFlowCoordinator = Resources.FindObjectsOfTypeAll <SoloFreePlayFlowCoordinator>().First();
            if (!_standardLevelSelectionFlowCoordinator)
            {
                return;
            }

            _standardLevelListViewController = ReflectionUtil.GetPrivateField <LevelListViewController>(_standardLevelSelectionFlowCoordinator, "_levelListViewController");
            if (!_standardLevelListViewController)
            {
                return;
            }

            _standardLevelListViewController.didSelectLevelEvent += standardLevelListViewController_didSelectLevelEvent;
        }
예제 #2
0
        private IEnumerator DelayedActiveSceneChanged(Scene scene)
        {
            yield return(new WaitForSeconds(0.1f));

            SongListUtils.Initialize();

            if (scene.name == "GameCore")
            {
                _isInGame = true;
            }
            if (scene.name != "MenuCore")
            {
                yield break;
            }
            _isInGame = false;

            _standardLevelSelectionFlowCoordinator = Resources.FindObjectsOfTypeAll <SoloFreePlayFlowCoordinator>().First();
            if (!_standardLevelSelectionFlowCoordinator)
            {
                yield break;
            }

            _standardLevelListViewController = ReflectionUtil.GetPrivateField <LevelPackLevelsViewController>(_standardLevelSelectionFlowCoordinator, "_levelPackLevelsViewController");
            if (!_standardLevelListViewController)
            {
                yield break;
            }

            _standardLevelListViewController.didSelectLevelEvent -= standardLevelListViewController_didSelectLevelEvent;
            _standardLevelListViewController.didSelectLevelEvent += standardLevelListViewController_didSelectLevelEvent;
        }
예제 #3
0
        private void FixedUpdate()
        {
            if (!_initialized)
            {
                return;
            }

            if (!_downloaderRunning)
            {
                if (_updateQueue.Count > 0)
                {
                    if (_updateQueue.TryPop(out var songUpdateInfo))
                    {
                        //Plugin.Log($"Updating {songUpdateInfo.Key}");
                        StartCoroutine(UpdateSong(songUpdateInfo));
                    }
                }
                else if (_authorDownloadQueue.Count > 0)
                {
                    StartCoroutine(DownloadAllSongsByAuthor(_authorDownloadQueue.Pop()));
                }
                else if (Config.BeastSaberUsername != "" && _beastSaberFeedIndex < _beastSaberFeeds.Count)
                {
                    StartCoroutine(DownloadBeastSaberFeeds(_beastSaberFeedIndex));
                    _beastSaberFeedIndex++;
                }
                else if (_authorDownloadQueue.Count == 0 && !_downloaderComplete)
                {
                    if (!SongLoader.AreSongsLoading)
                    {
                        if (_didDownloadAnySong)
                        {
                            StartCoroutine(SongListUtils.RefreshSongs(false, false));
                        }
                        Plugin.Log("Finished checking for updates!");
                        DisplayNotification("Finished checking for new songs!");
                        _downloaderComplete = true;
                    }
                }
            }

            if (_uiResetTime <= DateTime.Now && _notificationText.text != String.Empty)
            {
                _notificationText.text = String.Empty;
            }
        }
예제 #4
0
        public static IEnumerator ScrollToLevel(string levelID, Action <bool> callback, bool animated, bool isRetry = false)
        {
            if (_standardLevelListViewController)
            {
                // Make sure our custom songpack is selected
                SelectCustomSongPack();

                TableView tableView = _standardLevelListViewController.GetComponentInChildren <TableView>();
                tableView.ReloadData();

                var levels = _standardLevelListViewController.levelPack.beatmapLevelCollection.beatmapLevels.Where(l => l.levelID == levelID).ToArray();

                if (levels.Length > 0)
                {
                    int row = GetLevelIndex(_standardLevelListViewController, levelID);
                    if (row != -1)
                    {
                        tableView.SelectCellWithIdx(row, true);
                        tableView.ScrollToCellWithIdx(row, TableView.ScrollPositionType.Beginning, animated);
                        callback?.Invoke(true);
                        yield break;
                    }
                }
            }

            if (!isRetry)
            {
                yield return(SongListUtils.RefreshSongs(false, false));

                yield return(ScrollToLevel(levelID, callback, animated, true));

                yield break;
            }

            var tempLevels = SongLoader.CustomLevels.Where(l => l.levelID == levelID).ToArray();

            foreach (CustomLevel l in tempLevels)
            {
                SongLoader.CustomLevels.Remove(l);
            }

            Plugin.Log($"Failed to scroll to {levelID}!");
            callback?.Invoke(false);
        }
예제 #5
0
        private IEnumerator UpdateSong(KeyValuePair <JSONObject, CustomLevel> songUpdateInfo)
        {
            _downloaderRunning = true;
            JSONObject  song      = songUpdateInfo.Key;
            CustomLevel oldLevel  = songUpdateInfo.Value;
            string      songIndex = song["version"];
            string      songHash  = ((string)song["hashMd5"]).ToUpper();

            Utilities.EmptyDirectory(".songcache", false);

            var table = ReflectionUtil.GetPrivateField <LevelListTableView>(_standardLevelListViewController, "_levelListTableView");

            if (Config.DeleteOldVersions)
            {
                string        songPath = oldLevel.customSongInfo.path;
                DirectoryInfo parent   = Directory.GetParent(songPath);
                while (parent.Name != "CustomSongs")
                {
                    songPath = parent.FullName;
                    parent   = parent.Parent;
                }

                // Only delete the old song after the new one is downloaded and extracted
                Utilities.EmptyDirectory(songPath, true);
                SongLoader.Instance.RemoveSongWithLevelID(oldLevel.levelID);
            }

            string currentSongDirectory = $"{Environment.CurrentDirectory}\\CustomSongs\\{songIndex}";

            if (Directory.Exists(currentSongDirectory))
            {
                Utilities.EmptyDirectory(currentSongDirectory, true);
            }

            // Download and extract the update
            string localPath = $"{Environment.CurrentDirectory}\\.songcache\\{songIndex}.zip";

            yield return(Utilities.DownloadFile(song["downloadUrl"], localPath));

            yield return(Utilities.ExtractZip(localPath, currentSongDirectory));

            _standardLevelListViewController.didSelectLevelEvent -= standardLevelListViewController_didSelectLevelEvent;
            yield return(SongListUtils.RefreshSongs(false, false));

            _standardLevelListViewController.didSelectLevelEvent += standardLevelListViewController_didSelectLevelEvent;

            Plugin.Log("Finished refreshing songs!");
            // Try to scroll to the newly updated level, if it exists in the list
            var levels = SongLoader.CustomLevels.Where(l => l.levelID.StartsWith(songHash)).ToArray();

            if (levels.Length > 0)
            {
                Plugin.Log($"Scrolling to level {levels[0].levelID}");
                if (!SongListUtils.ScrollToLevel(levels[0].levelID))
                {
                    if (table)
                    {
                        var lvls = CurrentLevels;
                        lvls.Add(levels[0]);
                        table.SetLevels(lvls.ToArray());
                    }
                    SongListUtils.ScrollToLevel(levels[0].levelID);
                }
            }

            // Write our download history to file
            if (!_songDownloadHistory.Contains(songIndex))
            {
                _songDownloadHistory.Add(songIndex);
            }
            Utilities.WriteStringListSafe(_historyPath, _songDownloadHistory.Distinct().ToList());

            DisplayNotification("Song update complete!");
            Plugin.Log($"Success updating song {songIndex}");
            _downloaderRunning = false;
        }
예제 #6
0
        private IEnumerator UpdateSong(KeyValuePair <JSONObject, CustomLevel> songUpdateInfo)
        {
            _downloaderRunning = true;
            JSONObject  song      = songUpdateInfo.Key;
            CustomLevel oldLevel  = songUpdateInfo.Value;
            string      songIndex = song["version"].Value;
            string      songHash  = (song["hashMd5"].Value).ToUpper();

            if (Config.DeleteOldVersions)
            {
                string        songPath = oldLevel.customSongInfo.path;
                DirectoryInfo parent   = Directory.GetParent(songPath);
                while (parent.Name != "CustomSongs")
                {
                    songPath = parent.FullName;
                    parent   = parent.Parent;
                }

                // Only delete the old song after the new one is downloaded and extracted
                Utilities.EmptyDirectory(songPath, true);
                SongLoader.Instance.RemoveSongWithLevelID(oldLevel.levelID);
            }

            string currentSongDirectory = Path.Combine(Environment.CurrentDirectory, "CustomSongs", songIndex);
            string localPath            = Path.Combine(Path.GetTempPath(), $"{songIndex}.zip");

            // Download and extract the update
            yield return(Utilities.DownloadFile(song["downloadUrl"].Value, localPath));

            yield return(Utilities.ExtractZip(localPath, currentSongDirectory));

            yield return(new WaitUntil(() => SongLoader.AreSongsLoaded && !SongLoader.AreSongsLoading));

            yield return(SongListUtils.RetrieveNewSong(songIndex, true));

            yield return(new WaitForSeconds(0.5f));

            bool success = false;
            // Try to scroll to the newly updated level, if it exists in the list
            var levels = SongLoader.CustomLevels.Where(l => l.levelID.StartsWith(songHash)).ToArray();

            if (levels.Length > 0)
            {
                Plugin.Log($"Scrolling to level {levels[0].levelID}");
                yield return(SongListUtils.ScrollToLevel(levels[0].levelID, (s) => success = s, false));
            }

            if (!success)
            {
                Plugin.Log("Failed to find new level!");
                DisplayNotification("Song update failed.");
                _downloaderRunning = false;
                yield break;
            }

            // Write our download history to file
            if (!_songDownloadHistory.Contains(songIndex))
            {
                _songDownloadHistory.Add(songIndex);
            }
            Utilities.WriteStringListSafe(_historyPath, _songDownloadHistory.Distinct().ToList());

            DisplayNotification("Song update complete!");
            Plugin.Log($"Success updating song {songIndex}");
            _downloaderRunning = false;
        }