Example #1
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);
        }
    }
Example #2
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);
        }
    }
    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);
        }
    }
Example #4
0
    /// <summary>
    /// Handle adding and deleting difficulties, they aren't added to the
    /// song being edited until they are saved so this method stages them
    /// </summary>
    /// <param name="row">UI row that was clicked on</param>
    /// <param name="val">True if the diff is being added</param>
    private void OnChange(DifficultyRow row, bool val)
    {
        if (!val && diffs.ContainsKey(row.Name)) // Delete if exists
        {
            // ForceDirty = has never been saved, don't ask for permission
            if (diffs[row.Name].ForceDirty)
            {
                if (row == selected)
                {
                    DeselectDiff();
                }

                diffs.Remove(row.Name);
                row.SetInteractable(false);
                row.NameInput.text = "";
                row.ShowDirtyObjects(false, false);
                return;
            }

            // This diff has previously been saved, confirm deletion
            PersistentUI.Instance.ShowDialogBox("SongEditMenu", "deletediff.dialog",
                                                (r) => HandleDeleteDifficulty(row, r), PersistentUI.DialogBoxPresetType.YesNo, new object[] { diffs[row.Name].DifficultyBeatmap.difficulty });
        }
        else if (val && !diffs.ContainsKey(row.Name)) // Create if does not exist
        {
            DifficultyBeatmap map = new DifficultyBeatmap(currentCharacteristic)
            {
                difficulty     = row.Name,
                difficultyRank = diffRankLookup[row.Name]
            };

            map.UpdateName();

            if (copySource != null)
            {
                var fromDiff = copySource.DifficultySettings;

                CancelCopy();

                if (fromDiff != null)
                {
                    map.noteJumpMovementSpeed   = fromDiff.DifficultyBeatmap.noteJumpMovementSpeed;
                    map.noteJumpStartBeatOffset = fromDiff.DifficultyBeatmap.noteJumpStartBeatOffset;

                    map.customData = fromDiff.DifficultyBeatmap.customData?.Clone();

                    // This sets the current filename as the filename for another diff and will trigger the copy on save
                    map.UpdateName(fromDiff.DifficultyBeatmap.beatmapFilename);
                }
            }

            diffs[row.Name] = new DifficultySettings(map, true);

            row.ShowDirtyObjects(diffs[row.Name]);
            row.SetInteractable(true);
            OnClick(row);
        }
        else if (val) // Create, but already exists
        {
            // I don't know how this would happen anymore
            row.ShowDirtyObjects(diffs[row.Name]);
            row.SetInteractable(true);
            if (!loading)
            {
                OnClick(row);
            }
        }
    }