Beispiel #1
0
        IEnumerator PlayPreviewCoroutine(LevelStaticData _songData)
        {
            yield return(new WaitWhile(delegate() { return _songData.previewAudioClip != null; }));

            if (_songPreviewPlayer != null && _songData != null && _songData.previewAudioClip != null)
            {
                try
                {
                    _songPreviewPlayer.CrossfadeTo(_songData.previewAudioClip, _songData.previewStartTime, _songData.previewDuration, 1f);
                }
                catch (Exception e)
                {
                    log.Error("Can't play preview! Exception: " + e);
                }
            }
        }
Beispiel #2
0
        public void Start()
        {
            // The goal now is to find the clip this scene will be playing.
            // For this, we find the single root gameObject (which is the gameObject
            // to which we are attached),
            // then we get its GameSongController to find the audio clip,
            // and its FlyingTextSpawner to display the lyrics.

            textSpawner    = gameObject.GetComponentInChildren <FlyingTextSpawner>();
            songController = gameObject.GetComponentInChildren <GameSongController>();

            if (textSpawner == null || songController == null)
            {
                return;
            }


            audioClip = (AudioClip)SongFileField.GetValue(songController);

            // Clip found, now select the first song that has the same clip (using reference comparison).
            levelData = (from world in PersistentSingleton <GameDataModel> .instance.gameStaticData.worldsData
                         from levelStaticData in world.levelsData
                         from difficultyLevel in levelStaticData.difficultyLevels
                         where ReferenceEquals(difficultyLevel.audioClip, audioClip)
                         select levelStaticData).FirstOrDefault();

            if (levelData == null)
            {
                Debug.Log("Corresponding song not found.");

                return;
            }

            // We found the matching song, we can get started.
            Debug.Log($"Corresponding song data found: {levelData.songName} by {levelData.authorName}.");

            // When this coroutine ends, it will call the given callback with a list
            // of all the subtitles we found, and allow us to react.
            // If no subs are found, the callback is not called.
            StartCoroutine(LyricsFetcher.GetLyrics(levelData.songName, levelData.authorName, subs =>
            {
                SpawnText("Lyrics found", 3f);
                StartCoroutine(DisplayLyrics(subs));
            }));
        }
Beispiel #3
0
 void PlayPreview(LevelStaticData _songData)
 {
     Console.WriteLine("Playing preview for " + _songData.songName);
     if (_songData.previewAudioClip != null)
     {
         if (_songPreviewPlayer != null && _songData != null)
         {
             try
             {
                 _songPreviewPlayer.CrossfadeTo(_songData.previewAudioClip, _songData.previewStartTime, _songData.previewDuration, 1f);
             }
             catch (Exception e)
             {
                 Console.WriteLine("Can't play preview! Exception: " + e);
             }
         }
     }
 }
Beispiel #4
0
 void PlayPreview(LevelStaticData _songData)
 {
     log.Log("Playing preview for " + _songData.songName);
     if (_songData.previewAudioClip != null)
     {
         if (_songPreviewPlayer != null && _songData != null)
         {
             try
             {
                 _songPreviewPlayer.CrossfadeTo(_songData.previewAudioClip, _songData.previewStartTime, _songData.previewDuration, 1f);
             }
             catch (Exception e)
             {
                 log.Error("Can't play preview! Exception: " + e);
             }
         }
     }
     else
     {
         StartCoroutine(PlayPreviewCoroutine(_songData));
     }
 }
 public DifficultyLevel(LevelStaticData.DifficultyLevel difficultyLevel)
 {
     difficulty     = LevelStaticData.GetDifficultyName(difficultyLevel.difficulty);
     difficultyRank = difficultyLevel.difficultyRank;
 }
Beispiel #6
0
        private void RefreshDetails(int row)
        {
            if (_songs.Count <= row)
            {
                return;
            }

            RectTransform _levelDetails = _songDetailViewController.GetComponentsInChildren <RectTransform>().First(x => x.name == "LevelDetails");

            _levelDetails.sizeDelta = new Vector2(44f, 20f);
            RectTransform _yourStats = _songDetailViewController.GetComponentsInChildren <RectTransform>().First(x => x.name == "YourStats");

            _yourStats.sizeDelta = new Vector2(44f, 18f);


            TextMeshProUGUI[] _textComponents = _songDetailViewController.GetComponentsInChildren <TextMeshProUGUI>();

            try
            {
                _textComponents.First(x => x.name == "SongNameText").text      = string.Format("{0}\n<size=80%>{1}</size>", HTML5Decode.HtmlDecode(_songs[row].songName), HTML5Decode.HtmlDecode(_songs[row].songSubName));
                _textComponents.First(x => x.name == "DurationValueText").text = HTML5Decode.HtmlDecode(_songs[row].downloads);
                _textComponents.First(x => x.name == "DurationText").text      = "Downloads";

                _textComponents.First(x => x.name == "BPMText").text      = "Plays";
                _textComponents.First(x => x.name == "BPMValueText").text = HTML5Decode.HtmlDecode(_songs[row].plays);

                _textComponents.First(x => x.name == "NotesCountText").text      = "Author";
                _textComponents.First(x => x.name == "NotesCountValueText").text = HTML5Decode.HtmlDecode(_songs[row].authorName);

                _textComponents.First(x => x.name == "NotesCountValueText").rectTransform.sizeDelta = new Vector2(16f, 3f);
                _textComponents.First(x => x.name == "NotesCountValueText").alignment = TextAlignmentOptions.CaplineRight;

                _textComponents.First(x => x.name == "Title").text = "Difficulties";

                _textComponents.First(x => x.name == "HighScoreText").text      = "Expert/+";
                _textComponents.First(x => x.name == "HighScoreValueText").text = (_songs[row].difficultyLevels.Where(x => (x.difficulty == "Expert" || x.difficulty == "ExpertPlus")).Count() > 0) ? "Yes" : "No";

                _textComponents.First(x => x.name == "MaxComboText").text      = "Hard";
                _textComponents.First(x => x.name == "MaxComboValueText").text = (_songs[row].difficultyLevels.Where(x => x.difficulty == "Hard").Count() > 0) ? "Yes" : "No";

                _textComponents.First(x => x.name == "MaxRankText").text = "Easy/Normal";
                _textComponents.First(x => x.name == "MaxRankText").rectTransform.sizeDelta = new Vector2(18f, 3f);
                _textComponents.First(x => x.name == "MaxRankValueText").text = (_songs[row].difficultyLevels.Where(x => (x.difficulty == "Easy" || x.difficulty == "Normal")).Count() > 0) ? "Yes" : "No";

                if (_textComponents.Where(x => x.name == "ObstaclesCountText").Count() != 0)
                {
                    Destroy(_textComponents.First(x => x.name == "ObstaclesCountText").gameObject);
                    Destroy(_textComponents.First(x => x.name == "ObstaclesCountValueText").gameObject);
                }
            }catch (Exception e)
            {
                log.Exception("EXCEPTION: " + e);
            }

            if (_downloadButton == null)
            {
                _downloadButton = _songDetailViewController.GetComponentInChildren <Button>();
                (_downloadButton.transform as RectTransform).sizeDelta        = new Vector2(30f, 10f);
                (_downloadButton.transform as RectTransform).anchoredPosition = new Vector2(2f, 6f);
            }
            _downloadButton.onClick.RemoveAllListeners();

            _downloadButton.onClick.AddListener(delegate()
            {
                if (!_loading)
                {
                    DownloadSong(row);
                }
            });

            if (_deleteButton != null)
            {
                Destroy(_deleteButton.gameObject);
            }

            if (IsSongAlreadyDownloaded(_songs[row]))
            {
                ui.SetButtonText(ref _downloadButton, "Redownload");

                _deleteButton = ui.CreateUIButton(_songDetailViewController.GetComponent <RectTransform>(), "ApplyButton");
                ui.SetButtonText(ref _deleteButton, "Delete");
                (_deleteButton.transform as RectTransform).sizeDelta        = new Vector2(18f, 10f);
                (_deleteButton.transform as RectTransform).anchoredPosition = new Vector2(18f, 6f);


                _deleteButton.onClick.RemoveAllListeners();

                _deleteButton.onClick.AddListener(delegate()
                {
                    if (!_loading)
                    {
                        StartCoroutine(DeleteSong(row));
                    }
                });

                LevelStaticData _songData = GetLevelStaticDataForSong(_songs[row]);

                PlayPreview(_songData);


                string _songPath = GetDownloadedSongPath(_songs[row]);

                if (!string.IsNullOrEmpty(_songPath) && _songPath.Contains("/.cache/"))
                {
                    _downloadButton.interactable = false;
                }
                else
                {
                    _downloadButton.interactable = true;
                }
            }
            else
            {
                ui.SetButtonText(ref _downloadButton, "Download");
                _downloadButton.interactable = true;
                if (_songPreviewPlayer != null)
                {
                    _songPreviewPlayer.CrossfadeToDefault();
                }
            }
        }
        private void SceneManagerOnActiveSceneChanged(Scene oldScene, Scene newScene)
        {
            if (newScene.buildIndex == 1)
            {
                // Loaded menu scene
                System.Net.WebClient client = new System.Net.WebClient();

                var menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuSceneSetupData>().FirstOrDefault();

                if (menuSceneSetupData.sceneState == MenuSceneSetupData.SceneState.Results)
                {
                    // Send result data
                    var twitchResults = new TwitchSongResults
                    {
                        Action    = "SongResults",
                        Results   = menuSceneSetupData.levelCompletionResults,
                        Timestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
                    };

                    var p = new NameValueCollection();
                    p.Add("Action", "SongResults");
                    p.Add("Data", JsonConvert.SerializeObject(twitchResults));
                    p.Add("Timestamp", twitchResults.Timestamp.ToString());

                    client.UploadValuesAsync(new System.Uri("http://localhost:3000/gamedata"), "POST", p);
                }
                else
                {
                    var twitchData = new TwitchSceneUpdate
                    {
                        Action    = "Menu",
                        Scene     = menuSceneSetupData.sceneState,
                        Timestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
                    };

                    var p = new NameValueCollection();
                    p.Add("Action", "SongResults");
                    p.Add("Data", JsonConvert.SerializeObject(twitchData));
                    p.Add("Timestamp", twitchData.Timestamp.ToString());

                    client.UploadValuesAsync(new System.Uri("http://localhost:3000/gamedata"), "POST", p);
                }
            }
            else if (newScene.buildIndex == 4)
            {
                // Loaded game playing scene
                _mainSetupData   = Resources.FindObjectsOfTypeAll <MainGameSceneSetupData>().FirstOrDefault();
                _gameStaticData  = Resources.FindObjectsOfTypeAll <GameStaticData>().FirstOrDefault();
                _scoreController = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault();

                if (_mainSetupData == null || _gameStaticData == null || _scoreController == null)
                {
                    Console.WriteLine("Twitch Overlay: Cannot load game data.");
                    return;
                }

                // Attach note event handlers
                _scoreController.noteWasCutEvent    += HandleNoteWasCutEvent;
                _scoreController.noteWasMissedEvent += HandleNoteWasMissedEvent;

                var song     = _gameStaticData.GetLevelData(_mainSetupData.levelId);
                var songData = song.GetDifficultyLevel(_mainSetupData.difficulty).songLevelData.songData;

                var twitchSongUpdate = new TwitchSongUpdate
                {
                    Action         = "PlayingSong",
                    SongId         = song.levelId,
                    SongName       = song.songName,
                    SongSubName    = song.songSubName,
                    AuthorName     = song.authorName,
                    Difficulty     = LevelStaticData.GetDifficultyName(_mainSetupData.difficulty),
                    SongLength     = song.GetDifficultyLevel(_mainSetupData.difficulty).audioClip.length,
                    GameMode       = GetGameplayModeName(_mainSetupData.gameplayMode),
                    IsCustomSong   = song.levelId.Contains('∎'),
                    IsNoFail       = _mainSetupData.gameplayOptions.noEnergy,
                    IsMirror       = _mainSetupData.gameplayOptions.mirror,
                    NotesCount     = songData.notesCount,
                    ObstaclesCount = songData.obstaclesCount,
                    BPM            = songData.BeatsPerMinute,
                    SongData       = songData.SongLinesData,
                    Timestamp      = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
                };

                try
                {
                    var p = new NameValueCollection();
                    p.Add("Action", "PlayingSong");
                    p.Add("Data", JsonConvert.SerializeObject(twitchSongUpdate));
                    p.Add("Timestamp", twitchSongUpdate.Timestamp.ToString());

                    System.Net.WebClient client = new System.Net.WebClient();
                    client.UploadValuesAsync(new System.Uri("http://localhost:3000/gamedata"), "POST", p);
                } catch (Exception e)
                {
                    var p = new NameValueCollection();
                    p.Add("state", "Error");
                    p.Add("Exception", e.ToString());
                    System.Net.WebClient client = new System.Net.WebClient();
                    client.UploadValuesAsync(new System.Uri("http://localhost:3000/gamedata"), "POST", p);
                }
            }
        }
Beispiel #8
0
        private void Awake()
        {
            var songs = RetrieveSongs();

            var gameScenesManager = Resources.FindObjectsOfTypeAll <GameScenesManager>().FirstOrDefault();

            var levelsData = new List <LevelStaticData>();

            foreach (var song in songs)
            {
                LevelStaticData newLevel = null;
                try
                {
                    newLevel = ScriptableObject.CreateInstance <LevelStaticData>();
                }
                catch (Exception e)
                {
                    //LevelStaticData.OnEnable throws null reference exception because we don't have time to set _difficultyLevels
                }
                ReflectionUtil.SetPrivateField(newLevel, "_authorName", song.authorName);
                ReflectionUtil.SetPrivateField(newLevel, "_songName", song.songName);
                ReflectionUtil.SetPrivateField(newLevel, "_songSubName", song.songSubName);
                ReflectionUtil.SetPrivateField(newLevel, "_previewStartTime", song.previewStartTime);
                ReflectionUtil.SetPrivateField(newLevel, "_previewDuration", song.previewDuration);
                ReflectionUtil.SetPrivateField(newLevel, "_beatsPerMinute", song.beatsPerMinute);
                StartCoroutine(LoadSprite("file://" + song.path + "/" + song.coverImagePath, newLevel, "_coverImage"));

                var newSceneInfo = ScriptableObject.CreateInstance <SceneInfo>();
                ReflectionUtil.SetPrivateField(newSceneInfo, "_gameScenesManager", gameScenesManager);
                ReflectionUtil.SetPrivateField(newSceneInfo, "_sceneName", song.environmentName);

                ReflectionUtil.SetPrivateField(newLevel, "_environmetSceneInfo", newSceneInfo);

                var difficultyLevels = new List <LevelStaticData.DifficultyLevel>();
                foreach (var diffLevel in song.difficultyLevels)
                {
                    var newDiffLevel = new LevelStaticData.DifficultyLevel();
                    ReflectionUtil.SetPrivateField(newDiffLevel, "_difficulty", Enum.Parse(typeof(LevelStaticData.Difficulty), diffLevel.difficulty));
                    ReflectionUtil.SetPrivateField(newDiffLevel, "_difficultyRank", diffLevel.difficultyRank);

                    if (!File.Exists(song.path + "/" + diffLevel.jsonPath))
                    {
                        Debug.LogError("Couldn't find " + diffLevel.jsonPath + " in path " + song.path);
                        continue;
                    }

                    var newSongLevelData = ScriptableObject.CreateInstance <SongLevelData>();
                    var json             = File.ReadAllText(song.path + "/" + diffLevel.jsonPath);

                    newSongLevelData.LoadFromJson(json);
                    ReflectionUtil.SetPrivateField(newDiffLevel, "_songLevelData", newSongLevelData);
                    StartCoroutine(LoadAudio("file://" + song.path + "/" + diffLevel.audioPath, newDiffLevel, "_audioClip"));
                    difficultyLevels.Add(newDiffLevel);
                }

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

                ReflectionUtil.SetPrivateField(newLevel, "_levelId", newLevel.GetHashCode().ToString());

                levelsData.Add(newLevel);
            }

            var gameDataModel = PersistentSingleton <GameDataModel> .instance;
            var oldData       = gameDataModel.gameStaticData.worldsData[0].levelsData.ToList();

            oldData.AddRange(levelsData);
            ReflectionUtil.SetPrivateField(gameDataModel.gameStaticData.worldsData[0], "_levelsData", oldData.ToArray());

            DontDestroyOnLoad(gameObject);
        }