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) { imageBytes = Convert.FromBase64String(DEFAULT_IMAGE.Substring(DEFAULT_IMAGE.IndexOf(",") + 1)); } try { imageBytes = resizeImageBytes(imageBytes); } catch (Exception) { } Texture2D tex = new Texture2D(1024, 1024); tex.LoadImage(imageBytes); customPlaylistSO._coverImage = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0f, 0f), imageHeight); customPlaylistSO._beatmapLevelCollection = beatmapLevelCollection; return(customPlaylistSO); }
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()); }