public static StandardLevelInfoSaveData DeserializeFromJSONString(string stringData, StandardLevelInfoSaveData standardSaveData) { // StandardLevelInfoSaveData standardSaveData = StandardLevelInfoSaveData.DeserializeFromJSONString(stringData); if (standardSaveData.version != "2.0.0") { return(standardSaveData); } Dictionary <string, dynamic> beatmapsByFilename = new Dictionary <string, dynamic>(); OopsAllCustomDatas customDatas = JsonConvert.DeserializeObject <OopsAllCustomDatas>(stringData, new CustomDataConverter()); DifficultyBeatmapSet[] customBeatmapSets = new DifficultyBeatmapSet[standardSaveData.difficultyBeatmapSets.Length]; for (int i = 0; i < standardSaveData.difficultyBeatmapSets.Length; i++) { var standardBeatmapSet = standardSaveData.difficultyBeatmapSets[i]; DifficultyBeatmap[] customBeatmaps = new DifficultyBeatmap[standardBeatmapSet.difficultyBeatmaps.Length]; for (int j = 0; j < standardBeatmapSet.difficultyBeatmaps.Length; j++) { var standardBeatmap = standardBeatmapSet.difficultyBeatmaps[j]; DifficultyBeatmap customBeatmap = new DifficultyBeatmap(standardBeatmap.difficulty, standardBeatmap.difficultyRank, standardBeatmap.beatmapFilename, standardBeatmap.noteJumpMovementSpeed, standardBeatmap.noteJumpStartBeatOffset, customDatas._difficultyBeatmapSets[i]._difficultyBeatmaps[j]._customData ?? Tree()); customBeatmaps[j] = customBeatmap; beatmapsByFilename[customBeatmap.beatmapFilename] = customBeatmap.customData; } customBeatmapSets[i] = new DifficultyBeatmapSet(standardBeatmapSet.beatmapCharacteristicName, customBeatmaps); } CustomLevelInfoSaveData result = new CustomLevelInfoSaveData(standardSaveData.songName, standardSaveData.songSubName, standardSaveData.songAuthorName, standardSaveData.levelAuthorName, standardSaveData.beatsPerMinute, standardSaveData.songTimeOffset, standardSaveData.shuffle, standardSaveData.shufflePeriod, standardSaveData.previewStartTime, standardSaveData.previewDuration, standardSaveData.songFilename, standardSaveData.coverImageFilename, standardSaveData.environmentName, customBeatmapSets, customDatas._customData ?? Tree(), beatmapsByFilename); return(result); }
public void SetSpawningData() { SelectedDifficultyMap = SelectedSongData.SongInfoFileData.DifficultyBeatmapSets[DifficultySetIndex].DifficultyBeatmaps[difficultyIndex]; SongSpawningInfo = new SongSpawningInfo { BPM = SelectedSongData.SongInfoFileData.BeatsPerMinute, NoteJumpSpeed = SelectedDifficultyMap.NoteJumpMovementSpeed, NoteJumpStartBeatOffset = (float)SelectedDifficultyMap.NoteJumpStartBeatOffset, SecondEquivalentOfBeat = 60 / SelectedSongData.SongInfoFileData.BeatsPerMinute, }; float jumpSpeedThreshold = 18f; float minHalfJumpDuration = 1f; float halfJumpDuration = 4f; while (SongSpawningInfo.NoteJumpSpeed * SongSpawningInfo.SecondEquivalentOfBeat * halfJumpDuration > jumpSpeedThreshold) { halfJumpDuration /= 2f; } halfJumpDuration += SongSpawningInfo.NoteJumpStartBeatOffset; if (halfJumpDuration < minHalfJumpDuration) { halfJumpDuration = minHalfJumpDuration; } SongSpawningInfo.HalfJumpDuration = halfJumpDuration; SongSpawningInfo.JumpDistance = SongSpawningInfo.NoteJumpSpeed * (SongSpawningInfo.SecondEquivalentOfBeat * (halfJumpDuration * 2)); SongSpawningInfo.JumpDistance += 1.4f; }
private BeatSaberMap TryGetExistingMapFromDiff(DifficultyBeatmap diff) { try { return(Song.GetMapFromDifficultyBeatmap(diff)); } catch (Exception) {}; return(null); }
public BeatSaberMap GetMapFromDifficultyBeatmap(DifficultyBeatmap data) { JSONNode mainNode = GetNodeFromFile(directory + "/" + data.beatmapFilename); if (mainNode == null) { Debug.LogWarning("Failed to get difficulty json file " + (directory + "/" + data.beatmapFilename)); return(null); } return(BeatSaberMap.GetBeatSaberMapFromJSON(mainNode, directory + "/" + data.beatmapFilename)); }
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); } }
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); } }
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 DifficultySettings(DifficultyBeatmap difficultyBeatmap, bool ForceDirty) : this(difficultyBeatmap) { this.ForceDirty = ForceDirty; }
public DifficultySettings(DifficultyBeatmap difficultyBeatmap) { difficultyBeatmap.GetOrCreateCustomData(); DifficultyBeatmap = difficultyBeatmap; Revert(); }
/// <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); } } }