public static CustomPlaylistSO[] load()
        {
            List <string> playlistPaths = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Playlists"), "*.json", SearchOption.TopDirectoryOnly).Concat(
                Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Playlists"), "*.bplist", SearchOption.TopDirectoryOnly)).ToList();
            List <CustomPlaylistSO> playlists = new List <CustomPlaylistSO>();

            for (int i = 0; i < playlistPaths.Count; i++)
            {
                JObject playlistJSON = JObject.Parse(File.ReadAllText(playlistPaths[i]));
                if (playlistJSON["songs"] != null)
                {
                    JArray songs = (JArray)playlistJSON["songs"];
                    List <IPreviewBeatmapLevel> beatmapLevels = new List <IPreviewBeatmapLevel>();
                    for (int j = 0; j < songs.Count; j++)
                    {
                        IPreviewBeatmapLevel beatmapLevel = null;
                        String hash = (string)songs[j]["hash"];
                        beatmapLevel = MatchSong(hash);
                        if (beatmapLevel != null)
                        {
                            beatmapLevels.Add(beatmapLevel);
                        }
                        else
                        {
                            String levelID = (string)songs[j]["levelId"];
                            if (!string.IsNullOrEmpty(levelID))
                            {
                                hash         = Collections.hashForLevelID(levelID);
                                beatmapLevel = MatchSong(hash);
                                if (beatmapLevel != null)
                                {
                                    beatmapLevels.Add(beatmapLevel);
                                }
                                else
                                {
                                    Logger.log.Warn($"Song not downloaded, : {(string.IsNullOrEmpty(hash) ? " unknown hash!" : ("hash " + hash + "!"))}");
                                }
                            }
                            else
                            {
                                Logger.log.Warn($"Song not downloaded, : {(string.IsNullOrEmpty(hash) ? " unknown hash!" : ("hash " + hash + "!"))}");
                            }
                        }
                    }
                    CustomBeatmapLevelCollectionSO customBeatmapLevelCollection = CustomBeatmapLevelCollectionSO.CreateInstance(beatmapLevels.ToArray());
                    String playlistTitle = "Untitled Playlist";
                    String playlistImage = CustomPlaylistSO.DEFAULT_IMAGE;
                    if ((string)playlistJSON["playlistTitle"] != null)
                    {
                        playlistTitle = (string)playlistJSON["playlistTitle"];
                    }
                    if ((string)playlistJSON["image"] != null)
                    {
                        playlistImage = (string)playlistJSON["image"];
                    }
                    playlists.Add(CustomPlaylistSO.CreateInstance(playlistTitle, playlistImage, customBeatmapLevelCollection));
                }
            }
            return(playlists.ToArray());
        }
Example #2
0
        public static CustomBeatmapLevelCollectionSO CreateInstance(IPreviewBeatmapLevel[] beatmapLevels)
        {
            CustomBeatmapLevelCollectionSO customBeatmapLevelCollectionSO = PersistentScriptableObject.CreateInstance <CustomBeatmapLevelCollectionSO>();

            customBeatmapLevelCollectionSO._beatmapLevels = beatmapLevels;
            return(customBeatmapLevelCollectionSO);
        }
Example #3
0
        public static CustomPlaylistSO CreateInstance(String name, String coverImage, CustomBeatmapLevelCollectionSO beatmapLevelCollection)
        {
            CustomPlaylistSO customPlaylistSO = ScriptableObject.CreateInstance <CustomPlaylistSO>();

            customPlaylistSO._playListLocalizedName = name;
            byte[] imageBytes;
            try
            {
                imageBytes = Convert.FromBase64String(coverImage.Substring(coverImage.IndexOf(",") + 1));
            }
            catch (Exception e)
            {
                imageBytes = Convert.FromBase64String(DEFAULT_IMAGE.Substring(DEFAULT_IMAGE.IndexOf(",") + 1));
            }
            Texture2D tex = new Texture2D(2, 2);

            tex.LoadImage(imageBytes);
            customPlaylistSO._coverImage             = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
            customPlaylistSO._beatmapLevelCollection = beatmapLevelCollection;
            return(customPlaylistSO);
        }