mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Moved error checks into Editor
- Invoke Action on error to Notify user - added some comments
This commit is contained in:
parent
19cdf99df8
commit
7492d953ae
@ -67,17 +67,6 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
&& checkCombos;
|
||||
}
|
||||
|
||||
private bool checkSnapAndSelectColumn(double startTime, List<(int, int)> columnPairs = null)
|
||||
{
|
||||
bool checkColumns = columnPairs != null
|
||||
? EditorBeatmap.SelectedHitObjects.All(x => columnPairs.Any(col => isNoteAt(x, col.Item1, col.Item2)))
|
||||
: !EditorBeatmap.SelectedHitObjects.Any();
|
||||
|
||||
return EditorClock.CurrentTime == startTime
|
||||
&& EditorBeatmap.SelectedHitObjects.Count == (columnPairs?.Count ?? 0)
|
||||
&& checkColumns;
|
||||
}
|
||||
|
||||
private bool hasCombosInOrder(IEnumerable<HitObject> selected, params int[] comboNumbers)
|
||||
{
|
||||
List<HitObject> hitObjects = selected.ToList();
|
||||
@ -89,6 +78,17 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
.Any();
|
||||
}
|
||||
|
||||
private bool checkSnapAndSelectColumn(double startTime, IReadOnlyCollection<(int, int)> columnPairs = null)
|
||||
{
|
||||
bool checkColumns = columnPairs != null
|
||||
? EditorBeatmap.SelectedHitObjects.All(x => columnPairs.Any(col => isNoteAt(x, col.Item1, col.Item2)))
|
||||
: !EditorBeatmap.SelectedHitObjects.Any();
|
||||
|
||||
return EditorClock.CurrentTime == startTime
|
||||
&& EditorBeatmap.SelectedHitObjects.Count == (columnPairs?.Count ?? 0)
|
||||
&& checkColumns;
|
||||
}
|
||||
|
||||
private bool isNoteAt(HitObject hitObject, double time, int column)
|
||||
{
|
||||
return hitObject is IHasColumn columnInfo
|
||||
@ -96,7 +96,7 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
&& columnInfo.Column == column;
|
||||
}
|
||||
|
||||
public void SetUpEditor(RulesetInfo ruleset)
|
||||
protected void SetUpEditor(RulesetInfo ruleset)
|
||||
{
|
||||
BeatmapSetInfo beatmapSet = null!;
|
||||
|
||||
@ -320,6 +320,7 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
{ (956, 1) })
|
||||
);
|
||||
|
||||
// TODO: discuss - this selects the first 2 objects on Stable, do we want that or is this fine?
|
||||
AddStepClickLink("00:00:000 (1,2)", "std link");
|
||||
AddAssert("snap to 1, select none", () => checkSnapAndSelectColumn(956));
|
||||
}
|
||||
|
@ -562,43 +562,18 @@ namespace osu.Game
|
||||
{
|
||||
if (ScreenStack.CurrentScreen is not Editor editor)
|
||||
{
|
||||
waitForReady(() => Notifications, _ => Notifications.Post(new SimpleNotification
|
||||
{
|
||||
Icon = FontAwesome.Solid.ExclamationTriangle,
|
||||
Text = EditorStrings.MustBeInEdit,
|
||||
}));
|
||||
postNotification(EditorStrings.MustBeInEdit);
|
||||
return;
|
||||
}
|
||||
|
||||
string[] groups = EditorTimestampParser.GetRegexGroups(timestamp);
|
||||
editor.SeekAndSelectHitObjects(timestamp, onError: postNotification);
|
||||
return;
|
||||
|
||||
if (groups.Length != 2 || string.IsNullOrEmpty(groups[0]))
|
||||
void postNotification(LocalisableString message) => Schedule(() => Notifications.Post(new SimpleNotification
|
||||
{
|
||||
waitForReady(() => Notifications, _ => Notifications.Post(new SimpleNotification
|
||||
{
|
||||
Icon = FontAwesome.Solid.ExclamationTriangle,
|
||||
Text = EditorStrings.FailedToProcessTimestamp
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
string timeGroup = groups[0];
|
||||
string objectsGroup = groups[1];
|
||||
string timeMinutes = timeGroup.Split(':').FirstOrDefault() ?? string.Empty;
|
||||
|
||||
// Currently, lazer chat highlights infinite-long editor links like `10000000000:00:000 (1)`
|
||||
// Limit timestamp link length at 30000 min (50 hr) to avoid parsing issues
|
||||
if (timeMinutes.Length > 5 || double.Parse(timeMinutes) > 30_000)
|
||||
{
|
||||
waitForReady(() => Notifications, _ => Notifications.Post(new SimpleNotification
|
||||
{
|
||||
Icon = FontAwesome.Solid.ExclamationTriangle,
|
||||
Text = EditorStrings.TooLongTimestamp
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
editor.SeekAndSelectHitObjects(timeGroup, objectsGroup);
|
||||
Icon = FontAwesome.Solid.ExclamationTriangle,
|
||||
Text = message
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1138,11 +1138,33 @@ namespace osu.Game.Screens.Edit
|
||||
loader?.CancelPendingDifficultySwitch();
|
||||
}
|
||||
|
||||
public void SeekAndSelectHitObjects(string timeGroup, string objectsGroup)
|
||||
public void SeekAndSelectHitObjects(string timestamp, Action<LocalisableString> onError)
|
||||
{
|
||||
string[] groups = EditorTimestampParser.GetRegexGroups(timestamp);
|
||||
|
||||
if (groups.Length != 2 || string.IsNullOrEmpty(groups[0]))
|
||||
{
|
||||
onError.Invoke(EditorStrings.FailedToProcessTimestamp);
|
||||
return;
|
||||
}
|
||||
|
||||
string timeGroup = groups[0];
|
||||
string objectsGroup = groups[1];
|
||||
string timeMinutes = timeGroup.Split(':').FirstOrDefault() ?? string.Empty;
|
||||
|
||||
// Currently, lazer chat highlights infinite-long editor links like `10000000000:00:000 (1)`
|
||||
// Limit timestamp link length at 30000 min (50 hr) to avoid parsing issues
|
||||
if (timeMinutes.Length > 5 || double.Parse(timeMinutes) > 30_000)
|
||||
{
|
||||
onError.Invoke(EditorStrings.TooLongTimestamp);
|
||||
return;
|
||||
}
|
||||
|
||||
double position = EditorTimestampParser.GetTotalMilliseconds(timeGroup);
|
||||
|
||||
editorBeatmap.SelectedHitObjects.Clear();
|
||||
|
||||
// Only seeking is necessary
|
||||
if (string.IsNullOrEmpty(objectsGroup))
|
||||
{
|
||||
if (clock.IsRunning)
|
||||
@ -1155,8 +1177,9 @@ namespace osu.Game.Screens.Edit
|
||||
if (Mode.Value != EditorScreenMode.Compose)
|
||||
Mode.Value = EditorScreenMode.Compose;
|
||||
|
||||
// Seek to the next closest HitObject's position
|
||||
// Seek to the next closest HitObject
|
||||
HitObject nextObject = editorBeatmap.HitObjects.FirstOrDefault(x => x.StartTime >= position);
|
||||
|
||||
if (nextObject != null && nextObject.StartTime > 0)
|
||||
position = nextObject.StartTime;
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace osu.Game.Screens.Edit
|
||||
return (times[0] * 60 + times[1]) * 1_000 + times[2];
|
||||
}
|
||||
|
||||
public static List<HitObject> GetSelectedHitObjects(IEnumerable<HitObject> editorHitObjects, string objectsGroup, double position)
|
||||
public static List<HitObject> GetSelectedHitObjects(IReadOnlyList<HitObject> editorHitObjects, string objectsGroup, double position)
|
||||
{
|
||||
List<HitObject> hitObjects = editorHitObjects.Where(x => x.StartTime >= position).ToList();
|
||||
List<HitObject> selectedObjects = new List<HitObject>();
|
||||
@ -51,7 +51,7 @@ namespace osu.Game.Screens.Edit
|
||||
}
|
||||
|
||||
// Stable behavior
|
||||
// - always selects next closest object when `objectsGroup` only has one, non-Column item
|
||||
// - always selects the next closest object when `objectsGroup` only has one (combo) item
|
||||
if (objectsToSelect.Length != 1 || objectsGroup.Contains('|'))
|
||||
return selectedObjects;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user