Example #1
0
 public Song(CustomSongInfo _song)
 {
     songName         = _song.songName;
     songSubName      = _song.songSubName;
     authorName       = _song.authorName;
     difficultyLevels = ConvertDifficultyLevels(_song.difficultyLevels);
 }
 public Song(CustomSongInfo _song)
 {
     songName         = _song.songName;
     songSubName      = _song.songSubName;
     authorName       = _song.songAuthorName;
     difficultyLevels = ConvertDifficultyLevels(_song.difficultyLevels);
     path             = _song.path;
     hash             = _song.levelId.Substring(0, 32);
 }
Example #3
0
 public void Init(CustomSongInfo newCustomSongInfo)
 {
     customSongInfo        = newCustomSongInfo;
     _levelID              = customSongInfo.GetIdentifier();
     _songName             = customSongInfo.songName;
     _songSubName          = customSongInfo.songSubName;
     _songAuthorName       = customSongInfo.GetSongAuthor();
     _beatsPerMinute       = customSongInfo.beatsPerMinute;
     _songTimeOffset       = customSongInfo.songTimeOffset;
     _shuffle              = customSongInfo.shuffle;
     _shufflePeriod        = customSongInfo.shufflePeriod;
     _previewStartTime     = customSongInfo.previewStartTime;
     _previewDuration      = customSongInfo.previewDuration;
     _environmentSceneInfo = LoadSceneInfo(customSongInfo.environmentName);
 }
Example #4
0
 public void Init(CustomSongInfo newCustomSongInfo)
 {
     customSongInfo        = newCustomSongInfo;
     _levelID              = customSongInfo.GetIdentifier();
     _songName             = customSongInfo.songName;
     _songSubName          = customSongInfo.songSubName;
     _songAuthorName       = customSongInfo.GetSongAuthor();
     _beatsPerMinute       = customSongInfo.beatsPerMinute;
     _songTimeOffset       = customSongInfo.songTimeOffset;
     _shuffle              = customSongInfo.shuffle;
     _shufflePeriod        = customSongInfo.shufflePeriod;
     _previewStartTime     = customSongInfo.previewStartTime;
     _previewDuration      = customSongInfo.previewDuration;
     _environmentSceneInfo = EnvironmentsLoader.GetSceneInfo(customSongInfo.environmentName);
     _coverImage           = SongLoader.CustomSongsIcon;
     string _customEnvironment     = customSongInfo.customEnvironment;
     string _customEnvironmentHash = customSongInfo.customEnvironmentHash;
 }
Example #5
0
        private void DataReceived(string[] _data)
        {
            if (_data != null && _data.Length > 0)
            {
                foreach (string data in _data)
                {
                    ServerCommand command = null;

                    try
                    {
                        command = JsonUtility.FromJson <ServerCommand>(data);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Can't parse received JSON! Exception: " + e);
                    }

                    try
                    {
                        if (command != null)
                        {
                            switch (command.commandType)
                            {
                            case ServerCommandType.UpdateRequired:
                            {
                                _selectText.text = "Plugin version mismatch:\nServer: " + command.version + "\nClient: " + BSMultiplayerClient.version;
                                BSMultiplayerClient._instance.DisconnectFromServer();
                                _loading = false;
                            }; break;

                            case ServerCommandType.SetServerState:
                            {
                                if (command.serverState == ServerState.Playing)
                                {
                                    _loading = false;
                                    TimeSpan timeRemaining = TimeSpan.FromSeconds(command.selectedSongDuration - command.selectedSongPlayTime);

                                    _timerText.text = timeRemaining.Minutes.ToString("00") + ":" + timeRemaining.Seconds.ToString("00");

                                    _selectedSong = SongLoader.CustomSongInfos.First(x => x.levelId == command.selectedLevelID);

                                    _selectedSongCell.gameObject.SetActive(true);
                                    (_selectedSongCell.transform as RectTransform).anchoredPosition = new Vector2(14f, 39f);
                                    _selectedSongCell.songName = _selectedSong.songName + "\n<size=80%>" + _selectedSong.songSubName + "</size>";
                                    _selectedSongCell.author   = _selectedSong.authorName;


                                    CustomLevelStaticData _songData = SongLoader.CustomLevelStaticDatas.First(x => x.levelId == _selectedSong.levelId);

                                    _selectedSongCell.coverImage = _songData.coverImage;

                                    _songPreviewPlayer.CrossfadeTo(_songData.previewAudioClip, (float)command.selectedSongPlayTime, (float)(command.selectedSongDuration - command.selectedSongPlayTime - 5f), 1f);
                                }
                            }; break;

                            case ServerCommandType.SetLobbyTimer:
                            {
                                _loading = false;
                                Console.WriteLine("Set timer text to " + command.lobbyTimer);
                                _timerText.text = command.lobbyTimer.ToString();
                                if (_multiplayerLeaderboard != null && _viewControllers.IndexOf(_multiplayerLeaderboard) >= 0)
                                {
                                    _viewControllers.Remove(_multiplayerLeaderboard);
                                    Destroy(_multiplayerLeaderboard.gameObject);
                                    _songPreviewPlayer.CrossfadeToDefault();
                                    _selectedSongCell.gameObject.SetActive(false);
                                }
                            }; break;

                            case ServerCommandType.SetSelectedSong:
                            {
                                Console.WriteLine("Set selected song " + command.selectedLevelID);

                                _loading = false;

                                if (_selectedSong == null)
                                {
                                    try
                                    {
                                        _selectedSongDifficulty = command.selectedSongDifficlty;
                                        _selectedSong           = SongLoader.CustomSongInfos.First(x => x.levelId == command.selectedLevelID);

                                        _selectText.text = "Next song:";

                                        _selectedSongCell.gameObject.SetActive(true);
                                        (_selectedSongCell.transform as RectTransform).anchoredPosition = new Vector2(-25f, 0);
                                        _selectedSongCell.songName = _selectedSong.songName + "\n<size=80%>" + _selectedSong.songSubName + "</size>";
                                        _selectedSongCell.author   = _selectedSong.authorName;


                                        CustomLevelStaticData _songData = SongLoader.CustomLevelStaticDatas.First(x => x.levelId == _selectedSong.levelId);

                                        _selectedSongCell.coverImage = _songData.coverImage;

                                        PlayPreview(_songData);
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine("EXCEPTION: " + e);
                                    }
                                }

                                Console.WriteLine("Done");
                            }; break;

                            case ServerCommandType.StartSelectedSongLevel:
                            {
                                Console.WriteLine("Starting selected song! Song: " + _selectedSong.songName + ", Diff: " + ((LevelStaticData.Difficulty)_selectedSongDifficulty).ToString());

                                BSMultiplayerClient._instance.DataReceived -= DataReceived;
                                GameplayOptions gameplayOptions = new GameplayOptions();
                                gameplayOptions.noEnergy = true;
                                gameplayOptions.mirror   = false;

                                if (BSMultiplayerClient._instance._mainGameSceneSetupData != null)
                                {
                                    BSMultiplayerClient._instance._mainGameSceneSetupData.SetData(_selectedSong.levelId, (LevelStaticData.Difficulty)_selectedSongDifficulty, null, null, 0f, gameplayOptions, GameplayMode.SoloStandard, null);
                                    BSMultiplayerClient._instance._mainGameSceneSetupData.TransitionToScene(0.7f);
                                    _selectedSong = null;
                                    return;
                                }
                                else
                                {
                                    Console.WriteLine("SceneSetupData is null!");
                                }
                            }; break;

                            case ServerCommandType.DownloadSongs: {
                                if (!AllSongsDownloaded(command.songsToDownload))
                                {
                                    StartCoroutine(DownloadSongs(command.songsToDownload));
                                    BSMultiplayerClient._instance.DisconnectFromServer();
                                }
                            }; break;

                            case ServerCommandType.SetPlayerInfos: {
                                if (command.serverState == ServerState.Playing)
                                {
                                    if (_multiplayerLeaderboard != null)
                                    {
                                        TimeSpan timeRemaining = TimeSpan.FromSeconds(command.selectedSongDuration - command.selectedSongPlayTime);

                                        _timerText.text = timeRemaining.Minutes.ToString("00") + ":" + timeRemaining.Seconds.ToString("00");
                                        try
                                        {
                                            _multiplayerLeaderboard.SetLeaderboard(command.playerInfos.Select(x => JsonUtility.FromJson <PlayerInfo>(x)).ToArray());
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine("Leaderboard exception: " + e);
                                        }
                                    }
                                }
                                else
                                {
                                    _playerInfos.Clear();
                                    foreach (string playerStr in command.playerInfos)
                                    {
                                        PlayerInfo player = JsonUtility.FromJson <PlayerInfo>(playerStr);
                                        if (!String.IsNullOrEmpty(player.playerAvatar))
                                        {
                                            byte[] avatar = Convert.FromBase64String(player.playerAvatar);

                                            player.rightHandPos = Serialization.ToVector3(avatar.Take(12).ToArray());
                                            player.leftHandPos  = Serialization.ToVector3(avatar.Skip(12).Take(12).ToArray());
                                            player.headPos      = Serialization.ToVector3(avatar.Skip(24).Take(12).ToArray());

                                            player.rightHandRot = Serialization.ToQuaternion(avatar.Skip(36).Take(16).ToArray());
                                            player.leftHandRot  = Serialization.ToQuaternion(avatar.Skip(52).Take(16).ToArray());
                                            player.headRot      = Serialization.ToQuaternion(avatar.Skip(68).Take(16).ToArray());
                                        }
                                        _playerInfos.Add(player);
                                    }

                                    try
                                    {
                                        if (_avatars.Count > _playerInfos.Count)
                                        {
                                            List <AvatarController> avatarsToRemove = new List <AvatarController>();
                                            for (int i = _playerInfos.Count; i < _avatars.Count; i++)
                                            {
                                                avatarsToRemove.Add(_avatars[i]);
                                            }
                                            foreach (AvatarController avatar in avatarsToRemove)
                                            {
                                                _avatars.Remove(avatar);
                                                Destroy(avatar.gameObject);
                                            }
                                        }
                                        else if (_avatars.Count < _playerInfos.Count)
                                        {
                                            for (int i = 0; i < (_playerInfos.Count - _avatars.Count); i++)
                                            {
                                                _avatars.Add(new GameObject("Avatar").AddComponent <AvatarController>());
                                            }
                                        }

                                        for (int i = 0; i < _playerInfos.Count; i++)
                                        {
                                            _avatars[i].SetPlayerInfo(_playerInfos[i], 0f, localPlayerInfo.Equals(_playerInfos[i]));
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine($"AVATARS EXCEPTION: {e}");
                                    }
                                }
                            }; break;
                            }
                            _serverState = command.serverState;
                        }
                        else
                        {
                            Console.WriteLine("Server Command is null!");
                        }
                    }catch (Exception e)
                    {
                        Console.WriteLine("Exception (parse switch): " + e);
                    }
                }
            }


            StartCoroutine(BSMultiplayerClient._instance.ReceiveFromServerCoroutine());
        }
Example #6
0
        public IEnumerator DownloadSongCoroutine(Song songInfo, int row)
        {
            _loading = true;
            ui.SetButtonText(ref _downloadButton, "Downloading...");
            _downloadButton.interactable = false;
            if (_deleteButton != null)
            {
                _deleteButton.interactable = false;
            }

            string downloadedSongPath = "";

            UnityWebRequest www = UnityWebRequest.Get(songInfo.downloadUrl);

            www.timeout = 10;
            yield return(www.SendWebRequest());

            log.Log("Received response from BeatSaver.com...");

            if (www.isNetworkError || www.isHttpError)
            {
                log.Error(www.error);
                TextMeshProUGUI _errorText = ui.CreateText(_songDetailViewController.rectTransform, String.Format(www.error), new Vector2(18f, -64f));
                Destroy(_errorText.gameObject, 2f);
            }
            else
            {
                string zipPath         = "";
                string docPath         = "";
                string customSongsPath = "";
                try
                {
                    byte[] data = www.downloadHandler.data;

                    docPath         = Application.dataPath;
                    docPath         = docPath.Substring(0, docPath.Length - 5);
                    docPath         = docPath.Substring(0, docPath.LastIndexOf("/"));
                    customSongsPath = docPath + "/CustomSongs/" + songInfo.id + "/";
                    zipPath         = customSongsPath + songInfo.beatname + ".zip";
                    if (!Directory.Exists(customSongsPath))
                    {
                        Directory.CreateDirectory(customSongsPath);
                    }
                    File.WriteAllBytes(zipPath, data);
                    log.Log("Downloaded zip file!");
                }catch (Exception e)
                {
                    log.Exception("EXCEPTION: " + e);

                    _songListViewController._songsTableView.SelectRow(row);
                    RefreshDetails(row);
                    _loading = false;
                    if (_deleteButton != null)
                    {
                        _downloadButton.interactable = true;
                    }
                    yield break;
                }


                bool isOverwriting = false;
                using (var zf = new ZipFile(zipPath))
                {
                    foreach (ZipEntry ze in zf)
                    {
                        if (ze.IsFile)
                        {
                            if (string.IsNullOrEmpty(downloadedSongPath) && ze.Name.IndexOf('/') != -1)
                            {
                                downloadedSongPath = customSongsPath + ze.Name.Substring(0, ze.Name.IndexOf('/'));
                            }
                            if (Directory.Exists(customSongsPath + ze.Name.Substring(0, ze.Name.IndexOf('/'))))
                            {
                                yield return(PromptOverwriteFiles(ze.Name.Substring(0, ze.Name.IndexOf('/'))));

                                break;
                            }
                            else
                            {
                                isOverwriting = true;
                            }
                        }
                        else if (ze.IsDirectory)
                        {
                            downloadedSongPath = customSongsPath + ze.Name;
                            if (Directory.Exists(customSongsPath + ze.Name))
                            {
                                yield return(PromptOverwriteFiles(ze.Name.Trim('\\', '/')));

                                break;
                            }
                            else
                            {
                                isOverwriting = true;
                            }
                        }
                    }
                }



                if (_confirmOverwriteState == Prompt.Yes || isOverwriting)
                {
                    FastZip zip = new FastZip();

                    log.Log("Extractibg...");
                    zip.ExtractZip(zipPath, customSongsPath, null);


                    try
                    {
                        CustomSongInfo downloadedSong = GetCustomSongInfo(downloadedSongPath);

                        CustomLevelStaticData newLevel = null;
                        try
                        {
                            newLevel = ScriptableObject.CreateInstance <CustomLevelStaticData>();
                        }
                        catch (Exception e)
                        {
                            //LevelStaticData.OnEnable throws null reference exception because we don't have time to set _difficultyLevels
                        }

                        ReflectionUtil.SetPrivateField(newLevel, "_levelId", downloadedSong.GetIdentifier());
                        ReflectionUtil.SetPrivateField(newLevel, "_authorName", downloadedSong.authorName);
                        ReflectionUtil.SetPrivateField(newLevel, "_songName", downloadedSong.songName);
                        ReflectionUtil.SetPrivateField(newLevel, "_songSubName", downloadedSong.songSubName);
                        ReflectionUtil.SetPrivateField(newLevel, "_previewStartTime", downloadedSong.previewStartTime);
                        ReflectionUtil.SetPrivateField(newLevel, "_previewDuration", downloadedSong.previewDuration);
                        ReflectionUtil.SetPrivateField(newLevel, "_beatsPerMinute", downloadedSong.beatsPerMinute);

                        List <LevelStaticData.DifficultyLevel> difficultyLevels = new List <LevelStaticData.DifficultyLevel>();

                        LevelStaticData.DifficultyLevel newDiffLevel = new LevelStaticData.DifficultyLevel();

                        StartCoroutine(LoadAudio("file://" + downloadedSong.path + "/" + downloadedSong.difficultyLevels[0].audioPath, newDiffLevel, "_audioClip"));
                        difficultyLevels.Add(newDiffLevel);

                        ReflectionUtil.SetPrivateField(newLevel, "_difficultyLevels", difficultyLevels.ToArray());

                        newLevel.OnEnable();
                        _notUpdatedSongs.Add(newLevel);
                    }catch (Exception e)
                    {
                        log.Exception("Can't play preview! Exception: " + e);
                    }

                    UpdateAlreadyDownloadedSongs();
                    _songListViewController.RefreshScreen();

                    log.Log("Downloaded!");
                }
                _confirmOverwriteState = Prompt.NotSelected;
                File.Delete(zipPath);
            }
            try
            {
                _songListViewController._songsTableView.SelectRow(row);
                RefreshDetails(row);
            }
            catch (Exception e)
            {
                log.Exception(e.ToString());
            }
            _loading = false;
            if (_deleteButton != null)
            {
                _downloadButton.interactable = true;
            }
        }
        private void DataReceived(string[] _data)
        {
            if (_data != null && _data.Length > 0)
            {
                foreach (string data in _data)
                {
                    ServerCommand command = null;

                    try
                    {
                        command = JsonUtility.FromJson <ServerCommand>(data);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Can't parse received JSON! Exception: " + e);
                    }

                    try
                    {
                        if (command != null)
                        {
                            switch (command.commandType)
                            {
                            case ServerCommandType.UpdateRequired:
                            {
                                _selectText.text = "Plugin version mismatch:\nServer: " + command.version + "\nClient: " + BSMultiplayerMain.version;
                                BSMultiplayerMain._instance.DisconnectFromServer();
                                _loading = false;
                            }; break;

                            case ServerCommandType.SetServerState:
                            {
                                if (command.serverState == ServerState.Playing)
                                {
                                    _loading = false;
                                    TimeSpan timeRemaining = TimeSpan.FromSeconds(command.selectedSongDuration - command.selectedSongPlayTime);

                                    _timerText.text = timeRemaining.Minutes.ToString("00") + ":" + timeRemaining.Seconds.ToString("00");

                                    _selectedSong = SongLoader.CustomSongInfos.First(x => x.levelId == command.selectedLevelID);

                                    _selectedSongCell.gameObject.SetActive(true);
                                    (_selectedSongCell.transform as RectTransform).anchoredPosition = new Vector2(14f, 39f);
                                    _selectedSongCell.songName = _selectedSong.songName + "\n<size=80%>" + _selectedSong.songSubName + "</size>";
                                    _selectedSongCell.author   = _selectedSong.authorName;


                                    CustomLevelStaticData _songData = SongLoader.CustomLevelStaticDatas.First(x => x.levelId == _selectedSong.levelId);

                                    _selectedSongCell.coverImage = _songData.coverImage;

                                    _songPreviewPlayer.CrossfadeTo(_songData.previewAudioClip, (float)command.selectedSongPlayTime, (float)(command.selectedSongDuration - command.selectedSongPlayTime - 5f), 1f);
                                }
                            }; break;

                            case ServerCommandType.SetLobbyTimer:
                            {
                                _loading = false;
                                Console.WriteLine("Set timer text to " + command.lobbyTimer);
                                _timerText.text = command.lobbyTimer.ToString();
                                if (_multiplayerLeaderboard != null && _viewControllers.IndexOf(_multiplayerLeaderboard) >= 0)
                                {
                                    _viewControllers.Remove(_multiplayerLeaderboard);
                                    Destroy(_multiplayerLeaderboard.gameObject);
                                    _songPreviewPlayer.CrossfadeToDefault();
                                    _selectedSongCell.gameObject.SetActive(false);
                                }
                            }; break;

                            case ServerCommandType.SetSelectedSong:
                            {
                                Console.WriteLine("Set selected song " + command.selectedLevelID);

                                _loading = false;

                                if (_selectedSong == null)
                                {
                                    try
                                    {
                                        _selectedSongDifficulty = command.selectedSongDifficlty;
                                        _selectedSong           = SongLoader.CustomSongInfos.First(x => x.levelId == command.selectedLevelID);

                                        _selectText.text = "Next song:";

                                        _selectedSongCell.gameObject.SetActive(true);
                                        (_selectedSongCell.transform as RectTransform).anchoredPosition = new Vector2(-25f, 0);
                                        _selectedSongCell.songName = _selectedSong.songName + "\n<size=80%>" + _selectedSong.songSubName + "</size>";
                                        _selectedSongCell.author   = _selectedSong.authorName;


                                        CustomLevelStaticData _songData = SongLoader.CustomLevelStaticDatas.First(x => x.levelId == _selectedSong.levelId);

                                        _selectedSongCell.coverImage = _songData.coverImage;

                                        PlayPreview(_songData);
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine("EXCEPTION: " + e);
                                    }
                                }

                                Console.WriteLine("Done");
                            }; break;

                            case ServerCommandType.StartSelectedSongLevel:
                            {
                                Console.WriteLine("Starting selected song! Song: " + _selectedSong.songName + ", Diff: " + ((LevelStaticData.Difficulty)_selectedSongDifficulty).ToString());

                                BSMultiplayerMain._instance.DataReceived -= DataReceived;
                                GameplayOptions gameplayOptions = new GameplayOptions();
                                gameplayOptions.noEnergy = true;
                                gameplayOptions.mirror   = false;

                                if (BSMultiplayerMain._instance._mainGameSceneSetupData != null)
                                {
                                    BSMultiplayerMain._instance._mainGameSceneSetupData.SetData(_selectedSong.levelId, (LevelStaticData.Difficulty)_selectedSongDifficulty, null, null, 0f, gameplayOptions, GameplayMode.SoloStandard, null);
                                    BSMultiplayerMain._instance._mainGameSceneSetupData.TransitionToScene(0.7f);
                                    _selectedSong = null;
                                    return;
                                }
                                else
                                {
                                    Console.WriteLine("SceneSetupData is null!");
                                }
                            }; break;

                            case ServerCommandType.DownloadSongs:
                            {
                                if (!AllSongsDownloaded(command.songsToDownload))
                                {
                                    StartCoroutine(DownloadSongs(command.songsToDownload));
                                    BSMultiplayerMain._instance.DisconnectFromServer();
                                }
                            }; break;

                            case ServerCommandType.SetPlayerInfos:
                            {
                                if (_multiplayerLeaderboard != null)
                                {
                                    TimeSpan timeRemaining = TimeSpan.FromSeconds(command.selectedSongDuration - command.selectedSongPlayTime);

                                    _timerText.text = timeRemaining.Minutes.ToString("00") + ":" + timeRemaining.Seconds.ToString("00");
                                    try
                                    {
                                        _multiplayerLeaderboard.SetLeaderboard(command.playerInfos.Select(x => JsonUtility.FromJson <PlayerInfo>(x)).ToArray());
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine("Leaderboard exception: " + e);
                                    }
                                }
                            }; break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Server Command is null!");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Exception (parse switch): " + e);
                    }
                }
            }


            StartCoroutine(BSMultiplayerMain._instance.ReceiveFromServerCoroutine());
        }
        /// <summary>
        /// Add a song to directory tree.  Determine its place in the tree by walking the split directory path.
        /// </summary>
        /// <param name="customSongDirUri"></param>
        /// <param name="level"></param>
        private void AddItemToDirectoryTree(Uri customSongDirUri, LevelSO level)
        {
            //Logger.Debug("Processing item into directory tree: {0}", level.levelID);
            DirectoryNode currentNode = _directoryTree[CUSTOM_SONGS_DIR];

            // Just add original songs to root and bail
            if (level.levelID.Length < 32)
            {
                currentNode.Levels.Add(level);
                return;
            }

            CustomSongInfo songInfo      = _levelIdToCustomLevel[level.levelID].customSongInfo;
            Uri            customSongUri = new Uri(songInfo.path);
            Uri            pathDiff      = customSongDirUri.MakeRelativeUri(customSongUri);
            string         relPath       = Uri.UnescapeDataString(pathDiff.OriginalString);

            string[] paths      = relPath.Split('/');
            Sprite   folderIcon = Base64Sprites.FolderIcon;

            // Prevent cache directory from building into the tree, will add all its leafs to root.
            bool forceIntoRoot = false;

            //Logger.Debug("Processing path: {0}", songInfo.path);
            if (paths.Length > 2)
            {
                forceIntoRoot = paths[1].Contains(".cache");
                Regex r = new Regex(@"^\d{1,}-\d{1,}");
                if (r.Match(paths[1]).Success)
                {
                    forceIntoRoot = true;
                }
            }

            for (int i = 1; i < paths.Length; i++)
            {
                string path = paths[i];

                if (path == Path.GetFileName(songInfo.path))
                {
                    //Logger.Debug("\tLevel Found Adding {0}->{1}", currentNode.Key, level.levelID);
                    currentNode.Levels.Add(level);
                    break;
                }
                else if (currentNode.Nodes.ContainsKey(path))
                {
                    currentNode = currentNode.Nodes[path];
                }
                else if (!forceIntoRoot)
                {
                    currentNode.Nodes[path] = new DirectoryNode(path);
                    FolderLevel folderLevel = new FolderLevel();
                    folderLevel.Init(relPath, path, folderIcon);

                    //Logger.Debug("\tAdding folder level {0}->{1}", currentNode.Key, path);
                    currentNode.Levels.Add(folderLevel);

                    _cachedLastWriteTimes[folderLevel.levelID] = (File.GetLastWriteTimeUtc(relPath) - EPOCH).TotalMilliseconds;

                    currentNode = currentNode.Nodes[path];
                }
            }
        }
Example #9
0
        private void DataReceived(string[] _data)
        {
            if (_data != null && _data.Length > 0)
            {
                foreach (string data in _data)
                {
                    ServerCommand command = null;

                    try
                    {
                        command = JsonUtility.FromJson <ServerCommand>(data);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Can't parse received JSON! Exception: " + e);
                    }

                    try
                    {
                        if (command != null)
                        {
                            switch (command.commandType)
                            {
                            case ServerCommandType.SetServerState:
                            {
                                if (command.serverState == ServerState.Playing)
                                {
                                    BSMultiplayerMain._instance.DataReceived -= DataReceived;
                                    BSMultiplayerMain._instance.DisconnectFromServer();
                                    TimeSpan timeRemaining = TimeSpan.FromSeconds(command.selectedSongDuration - command.selectedSongPlayTime);

                                    TextMeshProUGUI _errorText = ui.CreateText(rectTransform, "Game in progress, " + timeRemaining.Minutes.ToString("00") + ":" + timeRemaining.Seconds.ToString("00") + " remaining", new Vector2(0f, -48f));
                                    _errorText.alignment = TextAlignmentOptions.Center;
                                    Destroy(_errorText.gameObject, 3f);
                                }
                            }; break;

                            case ServerCommandType.SetLobbyTimer:
                            {
                                Console.WriteLine("Set timer text to " + command.lobbyTimer);
                                _timerText.text = command.lobbyTimer.ToString();
                            }; break;

                            case ServerCommandType.SetSelectedSong:
                            {
                                Console.WriteLine("Set selected song " + command.selectedLevelID);

                                _loading = false;

                                if (_selectedSong == null)
                                {
                                    try
                                    {
                                        _selectedSongDifficulty = command.selectedSongDifficlty;
                                        _selectedSong           = SongLoader.CustomSongInfos.First(x => x.levelId == command.selectedLevelID);

                                        _selectText.text = "Next song:";

                                        _selectedSongCell.gameObject.SetActive(true);
                                        _selectedSongCell.songName = _selectedSong.songName + "\n<size=80%>" + _selectedSong.songSubName + "</size>";
                                        _selectedSongCell.author   = _selectedSong.authorName;


                                        CustomLevelStaticData _songData = SongLoader.CustomLevelStaticDatas.First(x => x.levelId == _selectedSong.levelId);

                                        _selectedSongCell.coverImage = _songData.coverImage;

                                        PlayPreview(_songData);
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine("EXCEPTION: " + e);
                                    }
                                }

                                Console.WriteLine("Done");
                            }; break;

                            case ServerCommandType.StartSelectedSongLevel:
                            {
                                Console.WriteLine("Starting selected song! Song: " + _selectedSong.songName + ", Diff: " + ((LevelStaticData.Difficulty)_selectedSongDifficulty).ToString());

                                BSMultiplayerMain._instance.DataReceived -= DataReceived;
                                GameplayOptions gameplayOptions = new GameplayOptions();
                                gameplayOptions.noEnergy = true;
                                gameplayOptions.mirror   = false;

                                if (BSMultiplayerMain._instance._mainGameSceneSetupData != null)
                                {
                                    BSMultiplayerMain._instance._mainGameSceneSetupData.SetData(_selectedSong.levelId, (LevelStaticData.Difficulty)_selectedSongDifficulty, null, null, 0f, gameplayOptions, GameplayMode.SoloStandard, null);
                                    BSMultiplayerMain._instance._mainGameSceneSetupData.TransitionToScene(0.7f);
                                    _selectedSong = null;
                                    return;
                                }
                                else
                                {
                                    Console.WriteLine("SceneSetupData is null!");
                                }
                            }; break;

                            case ServerCommandType.DownloadSongs: {
                                StartCoroutine(DownloadSongs(command.songsToDownload));
                                BSMultiplayerMain._instance.DisconnectFromServer();
                            }; break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Server Command is null!");
                        }
                    }catch (Exception e)
                    {
                        Console.WriteLine("Exception (parse switch): " + e);
                    }
                }
            }


            StartCoroutine(BSMultiplayerMain._instance.ReceiveFromServerCoroutine());
        }
Example #10
0
 public bool CompareSongs(CustomSongInfo song)
 {
     return(SongName == song.songName && AuthName == song.songAuthorName && Bpm == song.beatsPerMinute);
 }