Пример #1
0
        public static CustomBeatmapLevelCollectionSO CreateInstance(IPreviewBeatmapLevel[] beatmapLevels)
        {
            CustomBeatmapLevelCollectionSO customBeatmapLevelCollectionSO = PersistentScriptableObject.CreateInstance <CustomBeatmapLevelCollectionSO>();

            customBeatmapLevelCollectionSO._beatmapLevels = beatmapLevels;
            return(customBeatmapLevelCollectionSO);
        }
Пример #2
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);
        }
Пример #3
0
        public static CustomPlaylistSO[] load()
        {
            string[] playlistPaths            = Directory.EnumerateFiles(Path.Combine(Environment.CurrentDirectory, "Playlists"), "*.*").Where(p => p.EndsWith(".json") || p.EndsWith(".bplist")).ToArray();
            List <CustomPlaylistSO> playlists = new List <CustomPlaylistSO>();

            for (int i = 0; i < playlistPaths.Length; i++)
            {
                try
                {
                    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
                                    {
                                        Plugin.Log.Warn($"Song not downloaded, : {(string.IsNullOrEmpty(hash) ? " unknown hash!" : ("hash " + hash + "!"))}");
                                    }
                                }
                                else
                                {
                                    Plugin.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));
                    }
                } catch (Exception e)
                {
                    Plugin.Log.Critical($"Error loading Playlist File: " + playlistPaths[i] + " Exception: " + e.Message);
                }
            }
            return(playlists.ToArray());
        }