From 2aa0c7783dd9c6c9395abb95413c777566ca0d4a Mon Sep 17 00:00:00 2001 From: kstefanowicz Date: Sat, 20 Jul 2024 10:10:08 -0400 Subject: [PATCH 1/2] Save grid rotation to beatmap --- osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs | 3 +++ osu.Game/Beatmaps/BeatmapImporter.cs | 1 + osu.Game/Beatmaps/BeatmapInfo.cs | 2 ++ osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs | 4 ++++ osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs | 2 ++ 5 files changed, 12 insertions(+) diff --git a/osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs b/osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs index 73ecb2fe7c15..c83ea9d717a7 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs @@ -150,6 +150,8 @@ private void load() }; Spacing.Value = editorBeatmap.BeatmapInfo.GridSize; + + GridLinesRotation.Value = editorBeatmap.BeatmapInfo.GridRotation; } protected override void LoadComplete() @@ -184,6 +186,7 @@ protected override void LoadComplete() { gridLinesRotationSlider.ContractedLabelText = $"R: {rotation.NewValue:#,0.##}"; gridLinesRotationSlider.ExpandedLabelText = $"Rotation: {rotation.NewValue:#,0.##}"; + editorBeatmap.BeatmapInfo.GridRotation = (int)rotation.NewValue; }, true); expandingContainer?.Expanded.BindValueChanged(v => diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index 71aa5b0333f5..bb7a2cd149b7 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -427,6 +427,7 @@ private List createBeatmapDifficulties(BeatmapSetInfo beatmapSet, R DistanceSpacing = decodedInfo.DistanceSpacing, BeatDivisor = decodedInfo.BeatDivisor, GridSize = decodedInfo.GridSize, + GridRotation = decodedInfo.GridRotation, TimelineZoom = decodedInfo.TimelineZoom, MD5Hash = memoryStream.ComputeMD5Hash(), EndTimeObjectCount = decoded.HitObjects.Count(h => h is IHasDuration), diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index 425fd98d27e9..21085314a55c 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -173,6 +173,8 @@ public void ResetOnlineInfo() public int GridSize { get; set; } + public int GridRotation { get; set; } + public double TimelineZoom { get; set; } = 1.0; /// diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs index 9418a389aaec..cd024f149917 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs @@ -343,6 +343,10 @@ private void handleEditor(string line) beatmap.BeatmapInfo.GridSize = Parsing.ParseInt(pair.Value); break; + case @"GridRotation": + beatmap.BeatmapInfo.GridRotation = Parsing.ParseInt(pair.Value); + break; + case @"TimelineZoom": beatmap.BeatmapInfo.TimelineZoom = Math.Max(0, Parsing.ParseDouble(pair.Value)); break; diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs index 8a8964ccd442..017843f01631 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs @@ -115,7 +115,9 @@ private void handleEditor(TextWriter writer) writer.WriteLine(FormattableString.Invariant($"DistanceSpacing: {beatmap.BeatmapInfo.DistanceSpacing}")); writer.WriteLine(FormattableString.Invariant($"BeatDivisor: {beatmap.BeatmapInfo.BeatDivisor}")); writer.WriteLine(FormattableString.Invariant($"GridSize: {beatmap.BeatmapInfo.GridSize}")); + writer.WriteLine(FormattableString.Invariant($"GridRotation: {beatmap.BeatmapInfo.GridRotation}")); writer.WriteLine(FormattableString.Invariant($"TimelineZoom: {beatmap.BeatmapInfo.TimelineZoom}")); + } private void handleMetadata(TextWriter writer) From 9379e6af5133d9804c3f1c8c5cb63e66020fd2cf Mon Sep 17 00:00:00 2001 From: kstefanowicz Date: Mon, 22 Jul 2024 11:18:27 -0400 Subject: [PATCH 2/2] Implement saving grid settings Size, Rotation, StartX, StartY, GridType in IBeatmap --- .../Edit/OsuGridToolboxGroup.cs | 38 +++++++++++++++++-- osu.Game/Beatmaps/Beatmap.cs | 6 +++ osu.Game/Beatmaps/BeatmapConverter.cs | 5 +++ osu.Game/Beatmaps/BeatmapImporter.cs | 2 - osu.Game/Beatmaps/BeatmapInfo.cs | 4 -- .../Beatmaps/Formats/LegacyBeatmapDecoder.cs | 16 +++++++- .../Beatmaps/Formats/LegacyBeatmapEncoder.cs | 7 +++- osu.Game/Beatmaps/IBeatmap.cs | 9 +++++ .../Difficulty/DifficultyCalculator.cs | 6 +++ osu.Game/Screens/Edit/EditorBeatmap.cs | 26 +++++++++++++ 10 files changed, 105 insertions(+), 14 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs b/osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs index c83ea9d717a7..a572d8470c7d 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuGridToolboxGroup.cs @@ -19,6 +19,7 @@ using osu.Game.Screens.Edit.Components.RadioButtons; using osuTK; using osuTK.Graphics; +using Vortice.DXGI; namespace osu.Game.Rulesets.Osu.Edit { @@ -149,9 +150,30 @@ private void load() }, }; - Spacing.Value = editorBeatmap.BeatmapInfo.GridSize; + Spacing.Value = editorBeatmap.GridSize; + GridLinesRotation.Value = editorBeatmap.GridRotation; + if (editorBeatmap.GridStartPositionX != 0) + { + StartPositionX.Value = editorBeatmap.GridStartPositionX; + } + if (editorBeatmap.GridStartPositionY != 0) + { + StartPositionY.Value = editorBeatmap.GridStartPositionY; + } + + switch (editorBeatmap.GridType) + { + case "Square": + GridType.Value = PositionSnapGridType.Square; + break; + case "Triangle": + GridType.Value = PositionSnapGridType.Triangle; + break; + case "Circle": + GridType.Value = PositionSnapGridType.Circle; + break; + } - GridLinesRotation.Value = editorBeatmap.BeatmapInfo.GridRotation; } protected override void LoadComplete() @@ -165,6 +187,7 @@ protected override void LoadComplete() startPositionXSlider.ContractedLabelText = $"X: {x.NewValue:N0}"; startPositionXSlider.ExpandedLabelText = $"X Offset: {x.NewValue:N0}"; StartPosition.Value = new Vector2(x.NewValue, StartPosition.Value.Y); + editorBeatmap.GridStartPositionX = (int)x.NewValue; }, true); StartPositionY.BindValueChanged(y => @@ -172,6 +195,7 @@ protected override void LoadComplete() startPositionYSlider.ContractedLabelText = $"Y: {y.NewValue:N0}"; startPositionYSlider.ExpandedLabelText = $"Y Offset: {y.NewValue:N0}"; StartPosition.Value = new Vector2(StartPosition.Value.X, y.NewValue); + editorBeatmap.GridStartPositionY = (int)y.NewValue; }, true); Spacing.BindValueChanged(spacing => @@ -179,14 +203,14 @@ protected override void LoadComplete() spacingSlider.ContractedLabelText = $"S: {spacing.NewValue:N0}"; spacingSlider.ExpandedLabelText = $"Spacing: {spacing.NewValue:N0}"; SpacingVector.Value = new Vector2(spacing.NewValue); - editorBeatmap.BeatmapInfo.GridSize = (int)spacing.NewValue; + editorBeatmap.GridSize = (int)spacing.NewValue; }, true); GridLinesRotation.BindValueChanged(rotation => { gridLinesRotationSlider.ContractedLabelText = $"R: {rotation.NewValue:#,0.##}"; gridLinesRotationSlider.ExpandedLabelText = $"Rotation: {rotation.NewValue:#,0.##}"; - editorBeatmap.BeatmapInfo.GridRotation = (int)rotation.NewValue; + editorBeatmap.GridRotation = (int)rotation.NewValue; }, true); expandingContainer?.Expanded.BindValueChanged(v => @@ -205,12 +229,18 @@ protected override void LoadComplete() GridLinesRotation.Value = ((GridLinesRotation.Value + 405) % 90) - 45; GridLinesRotation.MinValue = -45; GridLinesRotation.MaxValue = 45; + editorBeatmap.GridType = "Square"; break; case PositionSnapGridType.Triangle: GridLinesRotation.Value = ((GridLinesRotation.Value + 390) % 60) - 30; GridLinesRotation.MinValue = -30; GridLinesRotation.MaxValue = 30; + editorBeatmap.GridType = "Triangle"; + break; + + case PositionSnapGridType.Circle: + editorBeatmap.GridType = "Circle"; break; } }, true); diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 282f8fe7941c..1b74380d82bc 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -115,6 +115,12 @@ public double GetMostCommonBeatLength() return mostCommon.beatLength; } + public int GridSize { get; set; } + public int GridRotation { get; set; } + public int GridStartPositionX { get; set; } + public int GridStartPositionY { get; set; } + public string GridType { get; set; } + IBeatmap IBeatmap.Clone() => Clone(); public Beatmap Clone() => (Beatmap)MemberwiseClone(); diff --git a/osu.Game/Beatmaps/BeatmapConverter.cs b/osu.Game/Beatmaps/BeatmapConverter.cs index c43bd494e95d..0a6e924f8a94 100644 --- a/osu.Game/Beatmaps/BeatmapConverter.cs +++ b/osu.Game/Beatmaps/BeatmapConverter.cs @@ -73,6 +73,11 @@ protected virtual Beatmap ConvertBeatmap(IBeatmap original, CancellationToken beatmap.HitObjects = convertHitObjects(original.HitObjects, original, cancellationToken).OrderBy(s => s.StartTime).ToList(); beatmap.Breaks = original.Breaks; beatmap.UnhandledEventLines = original.UnhandledEventLines; + beatmap.GridSize = original.GridSize; + beatmap.GridRotation = original.GridRotation; + beatmap.GridStartPositionX = original.GridStartPositionX; + beatmap.GridStartPositionY = original.GridStartPositionY; + beatmap.GridType = original.GridType; return beatmap; } diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index bb7a2cd149b7..adcc1ba1dbd2 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -426,8 +426,6 @@ private List createBeatmapDifficulties(BeatmapSetInfo beatmapSet, R SamplesMatchPlaybackRate = decodedInfo.SamplesMatchPlaybackRate, DistanceSpacing = decodedInfo.DistanceSpacing, BeatDivisor = decodedInfo.BeatDivisor, - GridSize = decodedInfo.GridSize, - GridRotation = decodedInfo.GridRotation, TimelineZoom = decodedInfo.TimelineZoom, MD5Hash = memoryStream.ComputeMD5Hash(), EndTimeObjectCount = decoded.HitObjects.Count(h => h is IHasDuration), diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index 21085314a55c..67dea71467fc 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -171,10 +171,6 @@ public void ResetOnlineInfo() public int BeatDivisor { get; set; } = 4; - public int GridSize { get; set; } - - public int GridRotation { get; set; } - public double TimelineZoom { get; set; } = 1.0; /// diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs index cd024f149917..652b3ba837fe 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs @@ -340,11 +340,23 @@ private void handleEditor(string line) break; case @"GridSize": - beatmap.BeatmapInfo.GridSize = Parsing.ParseInt(pair.Value); + beatmap.GridSize = Parsing.ParseInt(pair.Value); break; case @"GridRotation": - beatmap.BeatmapInfo.GridRotation = Parsing.ParseInt(pair.Value); + beatmap.GridRotation = Parsing.ParseInt(pair.Value); + break; + + case @"GridStartPositionX": + beatmap.GridStartPositionX = Parsing.ParseInt(pair.Value); + break; + + case @"GridStartPositionY": + beatmap.GridStartPositionY = Parsing.ParseInt(pair.Value); + break; + + case @"GridType": + beatmap.GridType = pair.Value; break; case @"TimelineZoom": diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs index 017843f01631..36a685ded33a 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs @@ -114,8 +114,11 @@ private void handleEditor(TextWriter writer) writer.WriteLine(FormattableString.Invariant($"Bookmarks: {string.Join(',', beatmap.BeatmapInfo.Bookmarks)}")); writer.WriteLine(FormattableString.Invariant($"DistanceSpacing: {beatmap.BeatmapInfo.DistanceSpacing}")); writer.WriteLine(FormattableString.Invariant($"BeatDivisor: {beatmap.BeatmapInfo.BeatDivisor}")); - writer.WriteLine(FormattableString.Invariant($"GridSize: {beatmap.BeatmapInfo.GridSize}")); - writer.WriteLine(FormattableString.Invariant($"GridRotation: {beatmap.BeatmapInfo.GridRotation}")); + writer.WriteLine(FormattableString.Invariant($"GridSize: {beatmap.GridSize}")); + writer.WriteLine(FormattableString.Invariant($"GridRotation: {beatmap.GridRotation}")); + writer.WriteLine(FormattableString.Invariant($"GridStartPositionX: {beatmap.GridStartPositionX}")); + writer.WriteLine(FormattableString.Invariant($"GridStartPositionY: {beatmap.GridStartPositionY}")); + writer.WriteLine(FormattableString.Invariant($"GridType: {beatmap.GridType}")); writer.WriteLine(FormattableString.Invariant($"TimelineZoom: {beatmap.BeatmapInfo.TimelineZoom}")); } diff --git a/osu.Game/Beatmaps/IBeatmap.cs b/osu.Game/Beatmaps/IBeatmap.cs index 430a31769bcd..494891e91080 100644 --- a/osu.Game/Beatmaps/IBeatmap.cs +++ b/osu.Game/Beatmaps/IBeatmap.cs @@ -74,6 +74,15 @@ public interface IBeatmap /// /// The shallow-cloned beatmap. IBeatmap Clone(); + + /// + /// Grid settings for the beatmap + /// + public int GridSize { get; set; } + public int GridRotation { get; set; } + public int GridStartPositionX { get; set; } + public int GridStartPositionY { get; set; } + public string GridType { get; set; } } /// diff --git a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs index 63b27243d02a..62a2e73adfc3 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs @@ -341,6 +341,12 @@ public SortedList Breaks public double GetMostCommonBeatLength() => baseBeatmap.GetMostCommonBeatLength(); public IBeatmap Clone() => new ProgressiveCalculationBeatmap(baseBeatmap.Clone()); + public int GridSize { get; set; } + public int GridRotation { get; set; } + public int GridStartPositionX { get; set; } + public int GridStartPositionY { get; set; } + public string GridType { get; set; } + #endregion } } diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index ad31c2ccc324..b0ef32205636 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -89,6 +89,32 @@ public partial class EditorBeatmap : TransactionalCommitComponent, IBeatmap, IBe public BindableInt PreviewTime { get; } + public int GridSize + { + get => PlayableBeatmap.GridSize; + set => PlayableBeatmap.GridSize = value; + } + public int GridRotation + { + get => PlayableBeatmap.GridRotation; + set => PlayableBeatmap.GridRotation = value; + } + public int GridStartPositionX + { + get => PlayableBeatmap.GridStartPositionX; + set => PlayableBeatmap.GridStartPositionX = value; + } + public int GridStartPositionY + { + get => PlayableBeatmap.GridStartPositionY; + set => PlayableBeatmap.GridStartPositionY = value; + } + public string GridType + { + get => PlayableBeatmap.GridType; + set => PlayableBeatmap.GridType = value; + } + private readonly IBeatmapProcessor beatmapProcessor; private readonly Dictionary> startTimeBindables = new Dictionary>();