Beispiel #1
0
        private static bool TryDeserializeBeatmap(byte[] bytes, out SerializableBeatmap beatmapData)
        {
            string jsonStr = System.Text.Encoding.Unicode.GetString(bytes);

            beatmapData = JsonUtility.FromJson <SerializableBeatmap>(jsonStr);
            return(beatmapData != null);
        }
Beispiel #2
0
        public static bool TryWriteBeatmap(string songName, BeatmapDifficulty difficulty, Beatmap beatmap)
        {
            try
            {
                var    beatmapData = new SerializableBeatmap(beatmap);
                string directory   = GetBeatmapSubDirectoryPath(songName, beatmap.TypeInstance);
                string filePath    = GetBeatmapFilePath(songName, beatmap.TypeInstance, difficulty);
                byte[] bytes       = SerializeBeatmap(beatmapData);

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite))
                {
                    fs.Write(bytes, 0, bytes.Length);
                }
                Game.Log(Logging.Category.SONG_DATA, "Wrote beatmap to file: " + directory, Logging.Level.LOG);
                return(true);
            }
            catch (System.Exception e)
            {
                Game.Log(Logging.Category.SONG_DATA, "Unable to write beatmap to file: " + e, Logging.Level.LOG_WARNING);
            }
            return(false);
        }
Beispiel #3
0
        private static byte[] SerializeBeatmap(SerializableBeatmap beatmapData)
        {
            string jsonStr = JsonUtility.ToJson(beatmapData);

            return(System.Text.Encoding.Unicode.GetBytes(jsonStr));
        }