public T ParseJSON <T>(JSONNode eventNode, ref float beatsPerMinute, ref float shuffle, ref float shufflePeriod) where T : ChromaJSONBeatmapObject
        {
            JSONNode.Enumerator nodeEnum = eventNode.GetEnumerator();
            while (nodeEnum.MoveNext())
            {
                string   key  = nodeEnum.Current.Key;
                JSONNode node = nodeEnum.Current.Value;

                switch (key)
                {
                case "_time":
                    time = GetRealTimeFromBPMTime(node.AsFloat, ref beatsPerMinute, ref shuffle, ref shufflePeriod);
                    break;

                case "_type":
                    type = (BeatmapEventType)node.AsInt;
                    break;

                default:
                    ParseNode(key, node);
                    break;
                }
            }

            return(this as T);
        }
Beispiel #2
0
        internal static IList <Subject> OptionalListOf(JSONNode subjectsNode)
        {
            if (subjectsNode == null)
            {
                return(null);
            }

            List <Subject> list = new List <Subject>();

            JSONNode.Enumerator e = subjectsNode.GetEnumerator();
            while (e.MoveNext())
            {
                KeyValuePair <String, JSONNode> pair = e.Current;
                list.Add(new Subject(pair.Key, pair.Value.AsLong));
            }
            return(list.Count == 0 ? null : list);
        }
    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;
                        }
                    }
                    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);
        }
    }
Beispiel #4
0
        public virtual void configure(JSONNode json_node)
        {
            this.id    = json_node["id"].AsInt;
            this.order = json_node["order"].AsInt;

            //inputs
            var json_inputs = json_node["inputs"];

            if (json_inputs != null)
            {
                JSONNode.Enumerator it = json_inputs.GetEnumerator();
                int i = 0;
                while (it.MoveNext())
                {
                    JSONNode json_slot = it.Current;
                    string   str_type  = json_slot["type"];
                    DataType type      = DataType.NONE;
                    if (str_type != null && Globals.stringToDataType.ContainsKey(str_type))
                    {
                        type = Globals.stringToDataType[str_type];
                    }
                    LSlot slot = null;
                    if (inputs.Count > i)
                    {
                        slot = inputs[i];
                    }
                    if (slot == null)
                    {
                        slot = this.addInput(json_slot["name"], type);
                    }
                    JSONNode json_link = json_slot["link"];
                    if (json_link != null)
                    {
                        slot.link = graph.links_by_id[json_link.AsInt];
                    }
                    ++i;
                }
            }

            //outputs
            var json_outputs = json_node["outputs"];

            if (json_outputs != null)
            {
                JSONNode.Enumerator it = json_outputs.GetEnumerator();
                int i = 0;
                while (it.MoveNext())
                {
                    JSONNode json_slot = it.Current;
                    string   str_type  = json_slot["type"];
                    DataType type      = DataType.NONE;
                    if (str_type != null && Globals.stringToDataType.ContainsKey(str_type))
                    {
                        type = Globals.stringToDataType[str_type];
                    }
                    LSlot slot = null;
                    if (outputs.Count > i)
                    {
                        slot = outputs[i];
                    }
                    if (slot == null)
                    {
                        slot = this.addOutput(json_slot["name"], type);
                    }

                    JSONNode json_links = json_slot["links"];
                    if (json_links != null)
                    {
                        JSONNode.Enumerator it2 = json_links.GetEnumerator();
                        while (it2.MoveNext())
                        {
                            JSONNode json_link_id = it2.Current;
                            LLink    link         = graph.links_by_id[json_link_id.AsInt];
                            if (link != null)
                            {
                                slot.links.Add(link);
                            }
                            else
                            {
                                Debug.LogError("Link ID not found!: " + json_link_id);
                            }
                        }
                    }
                    ++i;
                }
            }

            //custom data (properties)
            this.onConfigure(json_node);
        }
Beispiel #5
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));
                            }
                        }
                        if (n["_editor"]?.Value != null)
                        {
                            song.editor = n["_editor"].Value;
                        }
                    }
                    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 = GetColorFromJSONNode(d["_customData"]["_colorLeft"]);
                            }
                            if (d["_customData"]["_colorRight"] != null)
                            {
                                beatmap.colorRight = GetColorFromJSONNode(d["_customData"]["_colorRight"]);
                            }
                            if (d["_customData"]["_envColorLeft"] != null)
                            {
                                beatmap.envColorLeft = GetColorFromJSONNode(d["_customData"]["_envColorLeft"]);
                            }
                            else if (d["_customData"]["_colorLeft"] != null)
                            {
                                beatmap.envColorLeft = beatmap.colorLeft;
                            }
                            if (d["_customData"]["_envColorRight"] != null)
                            {
                                beatmap.envColorRight = GetColorFromJSONNode(d["_customData"]["_envColorRight"]);
                            }
                            else if (d["_customData"]["_colorRight"] != null)
                            {
                                beatmap.envColorRight = beatmap.colorRight;
                            }
                            if (d["_customData"]["_obstacleColor"] != null)
                            {
                                beatmap.obstacleColor = GetColorFromJSONNode(d["_customData"]["_obstacleColor"]);
                            }
                            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);
        }
    }
Beispiel #6
0
    public JSONNode.Enumerator getConversationIter(string conversationKey)
    {
        JSONNode conversation = data[conversationKey];

        return(conversation.GetEnumerator());
    }
    public static BeatSaberSong GetSongFromFolder(string directory)
    {
        try
        {
            //"excuse me this is not a schema change" ~lolPants
            //...after saying that beatsaver will stop accepting "info.dat" for uploading in the near future monkaHMMMMMMM
            JSONNode mainNode = GetNodeFromFile(directory + "/Info.dat");
            if (mainNode == null)
            {
                //Virgin "info.dat" VS chad "Info.dat"
                mainNode = GetNodeFromFile(directory + "/info.dat");
                if (mainNode == null)
                {
                    return(null);
                }
            }

            BeatSaberSong song = new BeatSaberSong(directory, mainNode);
            song.editor = $"{Application.productName}/{Application.version}";
            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;
                    if (!song.customData["_contributors"].IsNull)
                    {
                        foreach (JSONNode contributor in song.customData["_contributors"])
                        {
                            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);
        }
    }
Beispiel #8
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);

            List <DifficultyBeatmapSet> difficultyDataList = new List <DifficultyBeatmapSet>();

            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;

                case "_customData": song.customData = node; 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 = GetColorFromJSONNode(d["_customData"]["_colorLeft"]);
                            }
                            if (d["_customData"]["_colorRight"] != null)
                            {
                                beatmap.colorRight = GetColorFromJSONNode(d["_customData"]["_colorRight"]);
                            }
                            beatmap.UpdateName(d["_beatmapFilename"]);
                            set.difficultyBeatmaps.Add(beatmap);
                        }
                        //Debug.Log("Found difficulty data for " + difficultyData.jsonPath);
                        difficultyDataList.Add(set);
                    }

                    break;
                }
            }

            song.difficultyBeatmapSets = difficultyDataList;

            return(song);
        } catch (Exception e) {
            Debug.LogError(e);
            return(null);
        }
    }