public bool LoadIfNotLoaded(CustomLevelStaticData song)
        {
            string newId     = CustomSongInfo.FromPath(song.jsonPath).GetIdentifier();
            bool   idMatched = newId == song.levelId;

            if (!idMatched)
            {
                Logger.Log("Song has been modified, old ID was " + song.levelId + " updating song content and ID");
                song.wasLoaded = false;
                _database.UpdateSongID(song.levelId, newId);
                ReflectionUtil.SetPrivateField(song, "_levelId", newId);
            }

            if (!song.wasLoaded)
            {
                foreach (CustomLevelStaticData.CustomDifficultyLevel difficultyLevel in song.difficultyLevels)
                {
                    StartCoroutine(LoadAudio("file://" + difficultyLevel.audioPath, difficultyLevel,
                                             "_audioClip"));
                    ReflectionUtil.SetPrivateField(difficultyLevel, "_songLevelData",
                                                   ParseDifficulty(difficultyLevel.jsonPath));
                }
                song.wasLoaded = true;
            }
            return(idMatched);
        }
        private CustomLevel LoadSong(CustomSongInfo song)
        {
            try
            {
                var newLevel = _customLevelPool.Get();
                newLevel.Init(song);
                newLevel.SetAudioClip(TemporaryAudioClip);

                var difficultyBeatmaps = new List <LevelSO.DifficultyBeatmap>();
                foreach (var diffBeatmap in song.difficultyLevels)
                {
                    try
                    {
                        var difficulty = diffBeatmap.difficulty.ToEnum(BeatmapDifficulty.Normal);

                        if (string.IsNullOrEmpty(diffBeatmap.json))
                        {
                            Log("Couldn't find or parse difficulty json " + song.path + "/" + diffBeatmap.jsonPath, LogSeverity.Warn);
                            continue;
                        }

                        var newBeatmapData = _beatmapDataPool.Get();
                        newBeatmapData.SetJsonData(diffBeatmap.json);

                        var newDiffBeatmap = new CustomLevel.CustomDifficultyBeatmap(newLevel, difficulty,
                                                                                     diffBeatmap.difficultyRank, diffBeatmap.noteJumpMovementSpeed, diffBeatmap.noteJumpStartBeatOffset, newBeatmapData);
                        difficultyBeatmaps.Add(newDiffBeatmap);
                    }
                    catch (Exception e)
                    {
                        Log("Error parsing difficulty level in song: " + song.path, LogSeverity.Warn);
                        Log(e.Message, LogSeverity.Warn);
                    }
                }

                if (difficultyBeatmaps.Count == 0)
                {
                    return(null);
                }

                newLevel.SetDifficultyBeatmaps(difficultyBeatmaps.ToArray());
                newLevel.InitData();

                LoadSprite(song.path + "/" + song.coverImagePath, newLevel);
                return(newLevel);
            }
            catch (Exception e)
            {
                Log("Failed to load song: " + song.path, LogSeverity.Warn);
                Log(e.ToString(), LogSeverity.Warn);
            }

            return(null);
        }
Beispiel #3
0
        private void AddSong(string folder, xxHash.Hash64 hasher, List <ulong> scannedHashes, bool forceAdd)
        {
            // Hash info.json file to use as a key in the db
            hasher.Write(File.ReadAllText(folder + "/info.json"));
            ulong currentHash = hasher.Compute();

            hasher.Reset(0);

            // Ignore duplicates
            if (scannedHashes.Contains(currentHash))
            {
                Logger.Log("The song in directory " + folder + " has a duplicate hash " + currentHash +
                           " and was ignored");
                return;
            }
            scannedHashes.Add(currentHash);

            directoryParam.Value = folder;
            hashParam.Value      = currentHash;

            if (forceAdd || (Int64)checkCommand.ExecuteScalar() == 0)
            {
                Logger.Log("Song is not in DB or has changed, adding or updating");

                // We need to update the database entry for the current song
                CustomSongInfo songInfo = CustomSongInfo.FromPath(folder);
                beatsaveridParam.Value      = 0; //TODO
                leaderboardidParam.Value    = songInfo.GetIdentifier();
                bpmParam.Value              = songInfo.beatsPerMinute;
                previewStartTimeParam.Value = songInfo.previewStartTime;
                previewDurationParam.Value  = songInfo.previewDuration;
                authorNameParam.Value       = songInfo.authorName ?? "";
                songNameParam.Value         = songInfo.songName ?? "";
                songSubnameParam.Value      = songInfo.songSubName ?? "";
                coverImagePathParam.Value   = songInfo.coverImagePath ?? "";
                environmentNameParam.Value  = songInfo.environmentName ?? "";

                updateCommand.ExecuteNonQuery();

                // And add all the difficulties into the database
                foreach (CustomSongInfo.DifficultyLevel diff in songInfo.difficultyLevels)
                {
                    difficultyNameParam.Value = diff.difficulty;
                    difficultyRankParam.Value = diff.difficultyRank;
                    audioPathParam.Value      = diff.audioPath;
                    fileNameParam.Value       = diff.jsonPath;

                    updateDiffCommand.ExecuteNonQuery();
                }
            }
        }
Beispiel #4
0
        public List <CustomSongInfo> GetSongs(string filter)
        {
            List <CustomSongInfo> ret = new List <CustomSongInfo>();

            using (DbTransaction tx = conn.BeginTransaction())
            {
                Logger.Log("Getting songs");
                DbCommand getSongs = conn.CreateCommand();
                getSongs.CommandText = "SELECT * FROM songs " + filter;
                DbDataReader reader = getSongs.ExecuteReader();
                while (reader.Read())
                {
                    Logger.Log(reader.GetString(6));
                    CustomSongInfo info = new CustomSongInfo()
                    {
                        difficultyLevels = GetDiffs((ulong)reader.GetInt64(0)).ToArray(),
                        levelId          = reader.GetString(1),
                        beatsaverId      = reader.GetInt32(2),
                        beatsPerMinute   = reader.GetFloat(3),
                        previewStartTime = reader.GetFloat(4),
                        previewDuration  = reader.GetFloat(5),
                        path             = reader.GetString(6),
                        authorName       = reader.GetString(7),
                        songName         = reader.GetString(8),
                        songSubName      = reader.GetString(9),
                        coverImagePath   = reader.GetString(10),
                        environmentName  = reader.GetString(11)
                    };
                    foreach (CustomSongInfo.DifficultyLevel infoDifficultyLevel in info.difficultyLevels)
                    {
                        Logger.Log(infoDifficultyLevel.difficulty);
                    }
                    ret.Add(info);
                }
            }
            return(ret);
        }
        private CustomLevelStaticData LoadNewSong(CustomSongInfo song, GameScenesManager gameScenesManager)
        {
            CustomLevelStaticData newLevel = null;

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

            ReflectionUtil.SetPrivateField(newLevel, "_levelId", song.levelId);
            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"));

            SceneInfo newSceneInfo = ScriptableObject.CreateInstance <SceneInfo>();

            ReflectionUtil.SetPrivateField(newSceneInfo, "_gameScenesManager", gameScenesManager);
            ReflectionUtil.SetPrivateField(newSceneInfo, "_sceneName", song.environmentName);

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

            List <CustomLevelStaticData.CustomDifficultyLevel> difficultyLevels =
                new List <CustomLevelStaticData.CustomDifficultyLevel>();

            foreach (CustomSongInfo.DifficultyLevel diffLevel in song.difficultyLevels)
            {
                CustomLevelStaticData.CustomDifficultyLevel newDiffLevel =
                    new CustomLevelStaticData.CustomDifficultyLevel();
                try
                {
                    LevelStaticData.Difficulty difficulty =
                        diffLevel.difficulty.ToEnum(LevelStaticData.Difficulty.Normal);
                    ReflectionUtil.SetPrivateField(newDiffLevel, "_difficulty", difficulty);
                    ReflectionUtil.SetPrivateField(newDiffLevel, "_difficultyRank", diffLevel.difficultyRank);

                    if (!File.Exists(song.path + "/" + diffLevel.jsonPath))
                    {
                        Logger.Log("Couldn't find difficulty json " + song.path + "/" + diffLevel.jsonPath);
                        continue;
                    }

                    newDiffLevel.jsonPath  = song.path + "/" + diffLevel.jsonPath;
                    newDiffLevel.audioPath = song.path + "/" + diffLevel.audioPath;
                    difficultyLevels.Add(newDiffLevel);
                }
                catch (Exception e)
                {
                    Logger.Log("Error parsing difficulty level in song: " + song.path);
                    Logger.Log(e.Message);
                    continue;
                }
            }

            if (difficultyLevels.Count == 0)
            {
                return(null);
            }

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