Store grid size back to beatmap on change

This commit is contained in:
Bartłomiej Dach 2021-09-20 20:39:39 +02:00
parent 0d7dac03f4
commit d15bd5a15e
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
3 changed files with 19 additions and 5 deletions

View File

@ -72,6 +72,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
} }
private void gridSizeIs(int size) private void gridSizeIs(int size)
=> AddAssert($"grid size is {size}", () => this.ChildrenOfType<OsuRectangularPositionSnapGrid>().Single().Spacing == new Vector2(size)); => AddAssert($"grid size is {size}", () => this.ChildrenOfType<OsuRectangularPositionSnapGrid>().Single().Spacing == new Vector2(size)
&& EditorBeatmap.BeatmapInfo.GridSize == size);
} }
} }

View File

@ -68,7 +68,7 @@ namespace osu.Game.Rulesets.Osu.Edit
{ {
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
}, },
rectangularPositionSnapGrid = new OsuRectangularPositionSnapGrid(EditorBeatmap.BeatmapInfo.GridSize) rectangularPositionSnapGrid = new OsuRectangularPositionSnapGrid
{ {
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
} }

View File

@ -2,10 +2,12 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osu.Framework.Allocation;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Rulesets.Osu.UI; using osu.Game.Rulesets.Osu.UI;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose.Components; using osu.Game.Screens.Edit.Compose.Components;
using osuTK; using osuTK;
@ -17,10 +19,18 @@ namespace osu.Game.Rulesets.Osu.Edit
private int currentGridSizeIndex = grid_sizes.Length - 1; private int currentGridSizeIndex = grid_sizes.Length - 1;
public OsuRectangularPositionSnapGrid(int gridSize) [Resolved]
private EditorBeatmap editorBeatmap { get; set; }
public OsuRectangularPositionSnapGrid()
: base(OsuPlayfield.BASE_SIZE / 2) : base(OsuPlayfield.BASE_SIZE / 2)
{ {
var gridSizeIndex = Array.IndexOf(grid_sizes, gridSize); }
[BackgroundDependencyLoader]
private void load()
{
var gridSizeIndex = Array.IndexOf(grid_sizes, editorBeatmap.BeatmapInfo.GridSize);
if (gridSizeIndex > 0) if (gridSizeIndex > 0)
currentGridSizeIndex = gridSizeIndex; currentGridSizeIndex = gridSizeIndex;
updateSpacing(); updateSpacing();
@ -34,7 +44,10 @@ namespace osu.Game.Rulesets.Osu.Edit
private void updateSpacing() private void updateSpacing()
{ {
Spacing = new Vector2(grid_sizes[currentGridSizeIndex]); int gridSize = grid_sizes[currentGridSizeIndex];
editorBeatmap.BeatmapInfo.GridSize = gridSize;
Spacing = new Vector2(gridSize);
} }
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e) public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)