Esempio n. 1
0
        private bool UpdateSongConfig(AssetsFile songsAssetFile, BeatSaberSong song, CustomLevelLoader loader)
        {
            BeatmapLevelDataObject level = null;

            if (!string.IsNullOrWhiteSpace(song.SongID))
            {
                var levels = _manager.MassFindAssets <BeatmapLevelDataObject>(x => x.Object.LevelID == song.SongID, false).Select(x => x.Object).ToList();
                if (levels.Count() > 0)
                {
                    if (levels.Count() > 1)
                    {
                        Log.LogErr($"Song ID {song.SongID} already has more than one entry in the assets, this may cause problems!");
                    }
                    else
                    {
                        Log.LogMsg($"Song ID {song.SongID} exists already and won't be loaded");
                    }
                    level          = levels.First();
                    song.LevelData = level;
                    return(true);
                }
                else
                {
                    Log.LogMsg($"Song ID '{song.SongID}' does not exist and will be created");
                }
            }
            if (level != null && !string.IsNullOrWhiteSpace(song.CustomSongPath))
            {
                Log.LogErr("SongID and CustomSongsFolder are both set and the level already exists.  The existing one will be used and CustomSongsFolder won'tbe imported again.");
                return(false);
            }

            //load new song
            if (!string.IsNullOrWhiteSpace(song.CustomSongPath))
            {
                try
                {
                    var deser = loader.DeserializeFromJson(song.CustomSongPath, song.SongID);
                    var found = songsAssetFile.FindAssets <BeatmapLevelDataObject>(x => x.Object.LevelID == deser.LevelID).Select(x => x.Object).FirstOrDefault();
                    if (found != null)
                    {
                        Log.LogErr($"No song id was specified, but the level {found.LevelID} is already in the assets, skipping it.");
                        song.LevelData = found;
                        return(true);
                    }
                    level = loader.LoadSongToAsset(deser, song.CustomSongPath, true);
                }
                catch (Exception ex)
                {
                    Log.LogErr($"Exception loading custom song folder '{song.CustomSongPath}', skipping it", ex);
                    return(false);
                }

                if (level == null)
                {
                    Log.LogErr($"Song at folder '{song.CustomSongPath}' failed to load, skipping it");
                    return(false);
                }

                song.LevelData = level;
                return(true);
            }
            //level == null && string.IsNullOrWhiteSpace(song.CustomSongFolder)

            Log.LogErr($"Song ID '{song.SongID}' either was not specified or could not be found and no CustomSongFolder was specified, skipping it.");
            return(false);
        }