public void MetadataObjectUI(JSONObject j)
 {
     JSONNode.Enumerator iter = j.GetEnumerator();
     while (iter.MoveNext())
     {
         KeyValuePair <string, JSONNode> N = (KeyValuePair <string, JSONNode>)iter.Current;
         if (N.Value.AsArray != null && N.Value.AsArray.Count != 0)
         {
             if (N.Value.AsArray.Count == 3 && N.Value.AsArray [0].Value != "XYZ")
             {
                 MetadataVector3UI(N.Value.AsArray, N.Key);
                 continue;
             }
             if (!ShowPosition.ContainsKey(N.Key))
             {
                 ShowPosition.Add(N.Key, true);
             }
             ShowPosition [N.Key] = EditorGUILayout.Foldout(ShowPosition [N.Key], N.Key);
             if (ShowPosition [N.Key] == true)
             {
                 EditorGUI.indentLevel++;
                 MetadataArrayUI(N.Value.AsArray, name);
                 EditorGUI.indentLevel--;
             }
             continue;
         }
         if (N.Value.AsObject != null && N.Value.AsObject.Count != 0)
         {
             if (N.Value.AsObject.Count == 3)
             {
                 JSONNode.Enumerator iter2 = N.Value.AsObject.GetEnumerator();
                 int nb = 0;
                 while (iter2.MoveNext())
                 {
                     KeyValuePair <string, JSONNode> K = (KeyValuePair <string, JSONNode>)iter2.Current;
                     if (K.Key == "x" || K.Key == "y" || K.Key == "z")
                     {
                         nb++;
                     }
                 }
                 if (nb == 3)
                 {
                     MetadataVector3UI(N.Value.AsObject, N.Key);
                     continue;
                 }
             }
             if (!ShowPosition.ContainsKey(N.Key))
             {
                 ShowPosition.Add(N.Key, true);
             }
             ShowPosition [N.Key] = EditorGUILayout.Foldout(ShowPosition [N.Key], N.Key);
             if (ShowPosition [N.Key] == true)
             {
                 EditorGUI.indentLevel++;
                 MetadataObjectUI(N.Value.AsObject);
                 EditorGUI.indentLevel--;
             }
             continue;
         }
         EditorGUILayout.LabelField(N.Key, N.Value.ToString());
     }
 }
예제 #2
0
    public static BeatSaberMap GetBeatSaberMapFromJSON(JSONNode mainNode, string directoryAndFile)
    {
        try {
            BeatSaberMap map = new BeatSaberMap();
            map.mainNode = mainNode;

            map.directoryAndFile = directoryAndFile;

            List <MapEvent>           eventsList       = new List <MapEvent>();
            List <BeatmapNote>        notesList        = new List <BeatmapNote>();
            List <BeatmapObstacle>    obstaclesList    = new List <BeatmapObstacle>();
            List <BeatmapBPMChange>   bpmList          = new List <BeatmapBPMChange>();
            List <BeatmapBookmark>    bookmarksList    = new List <BeatmapBookmark>();
            List <BeatmapCustomEvent> customEventsList = new List <BeatmapCustomEvent>();

            JSONNode.Enumerator nodeEnum = mainNode.GetEnumerator();
            while (nodeEnum.MoveNext())
            {
                string   key  = nodeEnum.Current.Key;
                JSONNode node = nodeEnum.Current.Value;

                switch (key)
                {
                case "_version": map._version = node.Value; break;

                case "_events":
                    foreach (JSONNode n in node)
                    {
                        eventsList.Add(new MapEvent(n));
                    }
                    break;

                case "_notes":
                    foreach (JSONNode n in node)
                    {
                        notesList.Add(new BeatmapNote(n));
                    }
                    break;

                case "_obstacles":
                    foreach (JSONNode n in node)
                    {
                        obstaclesList.Add(new BeatmapObstacle(n));
                    }
                    break;

                case "_customData":
                    JSONNode.Enumerator dataNodeEnum = node.GetEnumerator();
                    while (dataNodeEnum.MoveNext())
                    {
                        string   dataKey  = dataNodeEnum.Current.Key;
                        JSONNode dataNode = dataNodeEnum.Current.Value;
                        switch (dataKey)
                        {
                        case "_BPMChanges":
                            foreach (JSONNode n in dataNode)
                            {
                                bpmList.Add(new BeatmapBPMChange(n));
                            }
                            break;

                        case "_bpmChanges":
                            foreach (JSONNode n in dataNode)
                            {
                                bpmList.Add(new BeatmapBPMChange(n));
                            }
                            break;

                        case "_bookmarks":
                            foreach (JSONNode n in dataNode)
                            {
                                bookmarksList.Add(new BeatmapBookmark(n));
                            }
                            break;

                        case "_customEvents":
                            foreach (JSONNode n in dataNode)
                            {
                                customEventsList.Add(new BeatmapCustomEvent(n));
                            }
                            break;

                        case "_time":
                            map._time = dataNode.AsFloat;
                            break;

                        case "_atlasBeatsMap":
                            map._atlasBeatsMap = map.checkUIntParse(dataNode.ToString());
                            break;
                        }
                    }
                    break;

                case "_BPMChanges":
                    foreach (JSONNode n in node)
                    {
                        bpmList.Add(new BeatmapBPMChange(n));
                    }
                    break;

                case "_bpmChanges":
                    foreach (JSONNode n in node)
                    {
                        bpmList.Add(new BeatmapBPMChange(n));
                    }
                    break;

                case "_bookmarks":
                    foreach (JSONNode n in node)
                    {
                        bookmarksList.Add(new BeatmapBookmark(n));
                    }
                    break;

                case "_customEvents":
                    foreach (JSONNode n in node)
                    {
                        customEventsList.Add(new BeatmapCustomEvent(n));
                    }
                    break;
                }
            }

            map._events       = eventsList;
            map._notes        = notesList;
            map._obstacles    = obstaclesList;
            map._BPMChanges   = bpmList.DistinctBy(x => x.ConvertToJSON().ToString()).ToList();
            map._bookmarks    = bookmarksList;
            map._customEvents = customEventsList.DistinctBy(x => x.ConvertToJSON().ToString()).ToList();
            return(map);
        } catch (Exception e) {
            Debug.LogException(e);
            return(null);
        }
    }
예제 #3
0
    public static BeatSaberSong GetSongFromFolder(string directory)
    {
        try
        {
            JSONNode mainNode = GetNodeFromFile(directory + "/info.dat");
            if (mainNode == null)
            {
                return(null);
            }

            BeatSaberSong song = new BeatSaberSong(directory, mainNode);

            JSONNode.Enumerator nodeEnum = mainNode.GetEnumerator();
            while (nodeEnum.MoveNext())
            {
                string   key  = nodeEnum.Current.Key;
                JSONNode node = nodeEnum.Current.Value;

                switch (key)
                {
                case "_songName": song.songName = node.Value; break;

                case "_songSubName": song.songSubName = node.Value; break;

                case "_songAuthorName": song.songAuthorName = node.Value; break;

                case "_levelAuthorName": song.levelAuthorName = node.Value; break;

                case "_beatsPerMinute": song.beatsPerMinute = node.AsFloat; break;

                case "_songTimeOffset": song.songTimeOffset = node.AsFloat; break;

                case "_previewStartTime": song.previewStartTime = node.AsFloat; break;

                case "_previewDuration": song.previewDuration = node.AsFloat; break;

                case "_shuffle": song.shuffle = node.AsFloat; break;

                case "_shufflePeriod": song.shufflePeriod = node.AsFloat; break;

                case "_coverImageFilename": song.coverImageFilename = node.Value; break;

                case "_songFilename": song.songFilename = node.Value; break;

                case "_environmentName": song.environmentName = node.Value; break;
                //Because there is only one option, I wont load from file.
                //case "_allDirectionsEnvironmentName": song.allDirectionsEnvironmentName = node.Value; break;

                case "_customData":
                    song.customData = node;
                    foreach (JSONNode n in node)
                    {
                        if (n["_contributors"]?.AsArray != null)
                        {
                            foreach (JSONNode contributor in n["_contributors"].AsArray)
                            {
                                song.contributors.Add(new MapContributor(contributor));
                            }
                        }
                    }
                    break;

                case "_difficultyBeatmapSets":
                    foreach (JSONNode n in node)
                    {
                        DifficultyBeatmapSet set = new DifficultyBeatmapSet();
                        set.beatmapCharacteristicName = n["_beatmapCharacteristicName"];
                        foreach (JSONNode d in n["_difficultyBeatmaps"])
                        {
                            DifficultyBeatmap beatmap = new DifficultyBeatmap(set)
                            {
                                difficulty              = d["_difficulty"].Value,
                                difficultyRank          = d["_difficultyRank"].AsInt,
                                noteJumpMovementSpeed   = d["_noteJumpMovementSpeed"].AsFloat,
                                noteJumpStartBeatOffset = d["_noteJumpStartBeatOffset"].AsFloat,
                                customData              = d["_customData"],
                            };
                            if (d["_customData"]["_colorLeft"] != null)
                            {
                                beatmap.colorLeft = d["_customData"]["_colorLeft"].AsObject.ReadColor();
                            }
                            if (d["_customData"]["_colorRight"] != null)
                            {
                                beatmap.colorRight = d["_customData"]["_colorRight"].AsObject.ReadColor();
                            }
                            if (d["_customData"]["_envColorLeft"] != null)
                            {
                                beatmap.envColorLeft = d["_customData"]["_envColorLeft"].AsObject.ReadColor();
                            }
                            else if (d["_customData"]["_colorLeft"] != null)
                            {
                                beatmap.envColorLeft = beatmap.colorLeft;
                            }
                            if (d["_customData"]["_envColorRight"] != null)
                            {
                                beatmap.envColorRight = d["_customData"]["_envColorRight"].AsObject.ReadColor();
                            }
                            else if (d["_customData"]["_colorRight"] != null)
                            {
                                beatmap.envColorRight = beatmap.colorRight;
                            }
                            if (d["_customData"]["_obstacleColor"] != null)
                            {
                                beatmap.obstacleColor = d["_customData"]["_obstacleColor"].AsObject.ReadColor();
                            }
                            beatmap.UpdateName(d["_beatmapFilename"]);
                            set.difficultyBeatmaps.Add(beatmap);
                        }
                        set.difficultyBeatmaps = set.difficultyBeatmaps.OrderBy(x => x.difficultyRank).ToList();
                        song.difficultyBeatmapSets.Add(set);
                    }
                    song.difficultyBeatmapSets = song.difficultyBeatmapSets.OrderBy(x =>
                                                                                    SongInfoEditUI.CharacteristicDropdownToBeatmapName.IndexOf(x.beatmapCharacteristicName)).ToList();
                    break;
                }
            }
            return(song);
        }
        catch (Exception e)
        {
            Debug.LogError(e);
            return(null);
        }
    }