From e83557e938cf1731dae1c869e90a7d31927cb284 Mon Sep 17 00:00:00 2001 From: hehNervii <337575599+hehNervii@users.noreply.github.com> Date: Sat, 31 Oct 2026 11:54:07 -0500 Subject: [PATCH] Holds: fit new holds beside neighbours, keep them through resizes and dividers A word resize keeps its holds at their own times like its dividers, trimming one the new span cuts into, and a whole hold whose letter the new spread moves past scales with the word, so a hold is neither stretched across a cut into an invisible ghost nor lost. Moving a word or line shifts its holds by the same sum as its dividers, so a hold ending on one stays on it. Any hold no play honours is dropped when a line is written or the editor opens a map. A tick marks a moment in the song, so resizing a word or dragging a hold edge keeps ticks where they are and drops only those the hold no longer holds. A new hold fits its letter's own subdivision (short syllables, before a cut, next to another hold), dividers and line-box pipes cannot cross a hold, a new divider takes the nearest letter split that keeps every hold, ticks may sit from the hold's head, and a letter's hold-free due time is the aligned era only. Co-Authored-By: Claude Opus 5.5 --- .../Beatmaps/WordObjects.cs | 20 + .../Edit/ActiveLineDetailPanel.cs | 9 +- .../Edit/HoldPlacement.cs | 196 ++++++++++ .../Edit/LineListPanel.cs | 3 +- .../Edit/LyricTimeline.cs | 3 +- ...atEditorOperations.OriginalSubdivisions.cs | 4 +- .../TypeBeatEditorOperations.Originals.cs | 7 +- .../Edit/TypeBeatEditorOperations.cs | 344 ++++++++++-------- .../Edit/WordScriptEditor.cs | 6 + .../Gameplay/HeldWord.cs | 8 +- .../Gameplay/HoldTicks.cs | 4 +- .../Gameplay/TypingLine.cs | 6 +- 12 files changed, 440 insertions(+), 170 deletions(-) create mode 100644 typebeat.Game.Rulesets.TypeBeat/Edit/HoldPlacement.cs diff --git a/typebeat.Game.Rulesets.TypeBeat/Beatmaps/WordObjects.cs b/typebeat.Game.Rulesets.TypeBeat/Beatmaps/WordObjects.cs index 8c5d6998..7a97dbea 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Beatmaps/WordObjects.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Beatmaps/WordObjects.cs @@ -60,6 +60,26 @@ public WordObjects Retimed(double oldStart, double oldEnd, double newStart, doub return this with { Holds = Holds.Select(h => HoldTicks.Stretched(h, map(h.StartTime), map(h.EndTime))).ToArray() }; } + /// + /// These objects moved whole by : the same sum as the word's dividers and rests, so a hold + /// edge on one of them stays exactly on it ('s scaling can land an ulp past). + /// + public WordObjects Shifted(double deltaMs) + { + if (Holds.Count == 0 || deltaMs == 0) + return this; + + return this with + { + Holds = Holds.Select(h => h with + { + StartTime = h.StartTime + deltaMs, + EndTime = h.EndTime + deltaMs, + Ticks = h.Ticks.Select(t => t + deltaMs).ToArray(), + }).ToArray() + }; + } + /// These objects for a retyped word: holds index characters, so a new spelling drops them. public WordObjects ForText(string oldText, string newText) => Holds.Count == 0 || string.Equals(oldText, newText, StringComparison.Ordinal) diff --git a/typebeat.Game.Rulesets.TypeBeat/Edit/ActiveLineDetailPanel.cs b/typebeat.Game.Rulesets.TypeBeat/Edit/ActiveLineDetailPanel.cs index 18377df3..e6a29d36 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Edit/ActiveLineDetailPanel.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Edit/ActiveLineDetailPanel.cs @@ -628,12 +628,19 @@ private void unsubdivideSelectedWords() if (targets.Length == 0) return; + bool refused = false; editorBeatmap.BeginChange(); foreach (int i in targets) - TypeBeatEditorOperations.RemoveNarrowestSyllableBoundary(editorBeatmap, line, i); + { + if (line.Line.Units[i].SyllableBoundaries.Count > 0 + && !TypeBeatEditorOperations.RemoveNarrowestSyllableBoundary(editorBeatmap, line, i)) + refused = true; + } editorBeatmap.EndChange(); + if (refused) + state.Refuse(); } /// diff --git a/typebeat.Game.Rulesets.TypeBeat/Edit/HoldPlacement.cs b/typebeat.Game.Rulesets.TypeBeat/Edit/HoldPlacement.cs new file mode 100644 index 00000000..fb1159a1 --- /dev/null +++ b/typebeat.Game.Rulesets.TypeBeat/Edit/HoldPlacement.cs @@ -0,0 +1,196 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Linq; +using typebeat.Game.Rulesets.TypeBeat.Beatmaps; +using typebeat.Game.Rulesets.TypeBeat.Gameplay; + +namespace typebeat.Game.Rulesets.TypeBeat.Edit +{ + internal readonly record struct HoldPlacementBounds(double Lower, double Upper); + + /// Editor geometry for a hold's own sung subdivision. Gameplay remains the final validator. + internal static class HoldPlacement + { + /// Gameplay lets a hold touch only the cuts beside its letter, so the editor keeps this far clear of the others. + private const double cut_margin_ms = 0.001; + + /// How far past its letter's target a hold end is kept, so rounding never puts it on the target. + private const double hold_end_past_due_ms = 1; + + /// + /// Where a hold on may sit: inside its subdivision and stretch, clear of the other + /// usable holds, and leaving to the letters either side. + /// + internal static HoldPlacementBounds? GetBounds(TimedUnit unit, int charIndex) + { + if (charIndex < 0 || charIndex >= unit.Text.Length || !Typeability.IsCell(unit.Text[charIndex])) + return null; + + var rests = HeldWord.RestsOf(unit); + double lower = charIndex == 0 ? unit.StartTime : unit.StartTime + TypeBeatEditorOperations.MIN_SYLLABLE_MS; + double upper = charIndex + 1 < unit.Text.Length ? unit.EndTime - TypeBeatEditorOperations.MIN_SYLLABLE_MS : unit.EndTime; + + foreach (var cut in HeldWord.CutsOf(unit, rests.Count > 0, Typeability.IsCell)) + { + if (charIndex >= cut.Char) + lower = Math.Max(lower, cut.Time + (charIndex > cut.Char ? cut_margin_ms : 0)); + else + upper = Math.Min(upper, cut.Time - (charIndex + 1 < cut.Char ? cut_margin_ms : 0)); + } + + foreach (var rest in rests) + { + if (charIndex >= rest.SplitChar) + lower = Math.Max(lower, rest.EndTime); + else + upper = Math.Min(upper, rest.StartTime); + } + + foreach (var hold in HeldWord.UsableHolds(unit)) + { + if (hold.Char < charIndex) + lower = Math.Max(lower, hold.EndTime); + else if (hold.Char > charIndex) + upper = Math.Min(upper, hold.StartTime); + } + + return upper >= lower ? new HoldPlacementBounds(lower, upper) : null; + } + + /// + /// A new hold on : the conventional span (from its letter to its syllable's end, or + /// halfway there), fitted into . No press target or usable hold changes; null when it cannot fit. + /// + internal static WordHold? Create(TimedUnit unit, int charIndex) + { + if (unit.Objects.Holds.Any(h => h.Char == charIndex) || GetBounds(unit, charIndex) is not { } bounds) + return null; + + var flat = TypeBeatEditorOperations.FlattenedWithoutHolds(unit); + int groupIndex = flat.SyllableIndexOf(charIndex); + if (flat.Cells.Count < unit.Text.Length || groupIndex < 0) + return null; + + var group = flat.Syllables[groupIndex]; + double due = HeldWord.LetterDueAt(unit, charIndex); + double start = charIndex == 0 ? unit.StartTime : flat.Cells[charIndex].TargetTime; + double end = charIndex == group.EndCellExclusive - 1 ? group.EndTime : start + (group.EndTime - start) / 2; + + if (!HeldWord.EndsAfterItsLetter(end, due)) + end = due + HeldWord.MIN_HOLD_MS; + + // Grow toward the available end before borrowing earlier time from the syllable. + start = Math.Max(bounds.Lower, start); + end = Math.Min(bounds.Upper, Math.Max(end, Math.Max(start + HeldWord.MIN_HOLD_MS, due + hold_end_past_due_ms))); + start = Math.Max(bounds.Lower, Math.Min(start, end - HeldWord.MIN_HOLD_MS)); + + var hold = new WordHold(charIndex, start, end); + var holds = HeldWord.UsableHolds(unit).Append(hold).OrderBy(h => h.Char).ToArray(); + return HeldWord.UsableHolds(unit.WithObjects(unit.Objects with { Holds = holds })).Count == holds.Length ? hold : null; + } + + /// clamped to where an edge of hold may go, or null. + internal static double? ClampEdge(TimedUnit unit, int holdIndex, bool moveStart, double proposedTime) + { + if (!double.IsFinite(proposedTime) || holdIndex < 0 || holdIndex >= unit.Objects.Holds.Count) + return null; + + var hold = unit.Objects.Holds[holdIndex]; + if ((moveStart && hold.Char == 0) || GetBounds(unit, hold.Char) is not { } bounds) + return null; + + double lower = moveStart ? bounds.Lower : Math.Max(hold.StartTime + HeldWord.MIN_HOLD_MS, HeldWord.LetterDueAt(unit, hold.Char) + hold_end_past_due_ms); + double upper = moveStart ? hold.EndTime - HeldWord.MIN_HOLD_MS : bounds.Upper; + return upper >= lower ? Math.Clamp(proposedTime, lower, upper) : null; + } + + /// over a new span. A tick marks a moment in the song, so ticks keep their times; any the span no longer holds are dropped. + internal static WordHold Respanned(WordHold hold, double start, double end) + { + var moved = hold with { StartTime = start, EndTime = end }; + return hold.Ticks.Count == 0 ? moved : moved with { Ticks = HoldTicks.UsableTicks(moved) }; + } + + /// + /// 's holds on , the same word over a new span: a first-letter hold + /// starts with the word, any other keeps its times trimmed inside the word (see ). A hold the + /// resize left whole, but whose letter the word's new spread moved past it, scales with the word rather than be lost. + /// + internal static WordHold[] Resized(TimedUnit unit, TimedUnit resized) + { + var old = unit.Objects.Holds; + var holds = old.Select(h => trimmed(h, unit.Text.Length, resized.StartTime, resized.EndTime)).ToArray(); + var usable = HeldWord.UsableHolds(resized.WithObjects(resized.Objects with { Holds = holds })); + + if (usable.Count == holds.Length) + return holds; + + var scaled = unit.Objects.Retimed(unit.StartTime, unit.EndTime, resized.StartTime, resized.EndTime).Holds; + + for (int i = 0; i < holds.Length; i++) + { + bool whole = holds[i].EndTime == old[i].EndTime && (old[i].Char == 0 || holds[i].StartTime == old[i].StartTime); + if (whole && !usable.Contains(holds[i])) + holds[i] = scaled[i]; + } + + return holds; + } + + private static WordHold trimmed(WordHold hold, int length, double wordStart, double wordEnd) + { + double start = hold.Char == 0 ? wordStart : Math.Max(hold.StartTime, wordStart + TypeBeatEditorOperations.MIN_SYLLABLE_MS); + double end = Math.Min(hold.EndTime, hold.Char + 1 < length ? wordEnd - TypeBeatEditorOperations.MIN_SYLLABLE_MS : wordEnd); + return Respanned(hold, start, end); + } + + /// + /// Whether every usable hold of is still usable in and crosses + /// its no further. Imported holds may already cross a cut gameplay exempts; an edit may keep that. + /// + internal static bool PreservesHolds(TimedUnit before, TimedUnit after) + { + var still = HeldWord.UsableHolds(after); + foreach (var hold in HeldWord.UsableHolds(before)) + { + if (!still.Contains(hold) || GetBounds(before, hold.Char) is not { } oldBounds || GetBounds(after, hold.Char) is not { } bounds) + return false; + if (Math.Max(0, bounds.Lower - hold.StartTime) > Math.Max(0, oldBounds.Lower - hold.StartTime) + || Math.Max(0, hold.EndTime - bounds.Upper) > Math.Max(0, hold.EndTime - oldBounds.Upper)) + return false; + } + return true; + } + + /// + /// Where divider may move without crossing a usable hold. A hold that already + /// crosses it (see ) only stops it crossing further. + /// + internal static HoldPlacementBounds DividerBounds(TimedUnit unit, int boundaryIndex) + { + double lower = double.NegativeInfinity, upper = double.PositiveInfinity; + var splits = SyllableSegments.SplitsFor(unit); + + if (boundaryIndex >= splits.Count) + return new HoldPlacementBounds(lower, upper); + + // On a paused word the divider's cut is its stretch's own, matched by time. + double time = unit.SyllableBoundaries[boundaryIndex]; + int cut = HeldWord.CutsOf(unit, HeldWord.RestsOf(unit).Count > 0, Typeability.IsCell) + .Where(c => c.Time == time).Select(c => c.Char) + .DefaultIfEmpty(splits[boundaryIndex]).Last(); + + foreach (var hold in HeldWord.UsableHolds(unit)) + { + if (hold.Char < cut) + lower = Math.Max(lower, Math.Min(time, hold.EndTime + (hold.Char + 1 == cut ? 0 : cut_margin_ms))); + else + upper = Math.Min(upper, Math.Max(time, hold.StartTime - (hold.Char == cut ? 0 : cut_margin_ms))); + } + + return new HoldPlacementBounds(lower, upper); + } + } +} diff --git a/typebeat.Game.Rulesets.TypeBeat/Edit/LineListPanel.cs b/typebeat.Game.Rulesets.TypeBeat/Edit/LineListPanel.cs index b466284f..20272fa8 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Edit/LineListPanel.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Edit/LineListPanel.cs @@ -567,7 +567,8 @@ private void commitText() if (state.ShowOriginalLyrics.Value) { - TypeBeatEditorOperations.SetLineOriginal(editorBeatmap, HitObject, textBox.Text); + if (!TypeBeatEditorOperations.SetLineOriginal(editorBeatmap, HitObject, textBox.Text)) + background.FlashColour(TypeBeatStyle.ErrorChar, 400, Easing.OutQuint); textBox.Text = committedText(); return; } diff --git a/typebeat.Game.Rulesets.TypeBeat/Edit/LyricTimeline.cs b/typebeat.Game.Rulesets.TypeBeat/Edit/LyricTimeline.cs index a9a37dfb..946a7723 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Edit/LyricTimeline.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Edit/LyricTimeline.cs @@ -1482,7 +1482,8 @@ protected override bool OnClick(ClickEvent e) protected override bool OnDoubleClick(DoubleClickEvent e) { - TypeBeatEditorOperations.RemoveSyllableBoundary(editorBeatmap, hitObject, unitIndex, boundaryIndex); + if (!TypeBeatEditorOperations.RemoveSyllableBoundary(editorBeatmap, hitObject, unitIndex, boundaryIndex)) + state.Refuse(); return true; } diff --git a/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.OriginalSubdivisions.cs b/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.OriginalSubdivisions.cs index 64cdb3b5..152b1b07 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.OriginalSubdivisions.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.OriginalSubdivisions.cs @@ -30,10 +30,10 @@ private static LyricLine normalizeOriginalSubdivisions(EditorBeatmap beatmap, Ly return units.Where((u, i) => !ReferenceEquals(u, line.Units[i])).Any() ? rebuild(line, units: units) : line; } - /// Reconcile older maps on editor entry, in one undoable change. + /// Reconcile older maps on editor entry, in one undoable change. This also clears the holds no play honours, which an older editor left invisible. public static void NormalizeOriginalSubdivisions(EditorBeatmap beatmap) { - var changes = OrderedLines(beatmap).Select(h => (Object: h, Line: normalizeOriginalSubdivisions(beatmap, h.Line))) + var changes = OrderedLines(beatmap).Select(h => (Object: h, Line: withoutUnplayableHolds(normalizeOriginalSubdivisions(beatmap, h.Line)))) .Where(c => !ReferenceEquals(c.Object.Line, c.Line)).ToArray(); if (changes.Length == 0) return; diff --git a/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.Originals.cs b/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.Originals.cs index 55de4b39..1429e559 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.Originals.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.Originals.cs @@ -106,7 +106,7 @@ public static bool SetWordText(EditorBeatmap editorBeatmap, TypeBeatHitObject hi else { var changed = applyPipes(new[] { unit }, new[] { normalized }, wordPipes, out _)[0]; - if (sameOriginalWord(unit, changed)) + if (sameOriginalWord(unit, changed) || (unit.Text == changed.Text && !HoldPlacement.PreservesHolds(unit, changed))) return false; entries[slot] = (changed, null); } @@ -169,7 +169,7 @@ public static bool SetWordOriginal(EditorBeatmap editorBeatmap, TypeBeatHitObjec : applyOriginalPipes(changed, newOriginal, originalPipes, OriginalSubdivisionLanguage(editorBeatmap, line) ?? LyricOriginals.DetectLanguage(new[] { newOriginal })); - if (sameOriginalWord(unit, changed)) + if (sameOriginalWord(unit, changed) || (unit.Text == changed.Text && !HoldPlacement.PreservesHolds(unit, changed))) return false; entries[slot] = (changed, null); @@ -235,6 +235,9 @@ public static bool SetLineOriginal(EditorBeatmap editorBeatmap, TypeBeatHitObjec } } + if (units.Where((u, i) => !HoldPlacement.PreservesHolds(line.Units[i], u)).Any()) + return false; + if (value == line.Original && units.Where((u, i) => !sameOriginalWord(u, line.Units[i])).Any() == false) return false; diff --git a/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.cs b/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.cs index 7c2cf172..ee5fa481 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Edit/TypeBeatEditorOperations.cs @@ -63,7 +63,7 @@ public static void ShiftAllTimes(EditorBeatmap editorBeatmap, double deltaMs) BackingVocals = BackingVocals.Shift(line.BackingVocals, deltaMs), Units = line.Units.Select(u => new TimedUnit { - Objects = u.Objects.Retimed(u.StartTime, u.EndTime, u.StartTime + deltaMs, u.EndTime + deltaMs), + Objects = u.Objects.Shifted(deltaMs), Text = u.Text, Original = u.Original, OriginalSplits = u.OriginalSplits, StartTime = u.StartTime + deltaMs, @@ -154,10 +154,24 @@ public static TimingGranularity InferGranularity(IReadOnlyList lines) /// private static void setLine(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, LyricLine line) { + line = withoutUnplayableHolds(line); hitObject.Line = line; editorBeatmap.Update(hitObject); } + /// + /// without the holds no play honours: the editor shows only usable holds, so + /// an unusable one would be a ghost the mapper cannot remove, yet submission still refuses it. + /// + private static LyricLine withoutUnplayableHolds(LyricLine line) + { + var units = line.Units.Select(u => HeldWord.UsableHolds(u) is var usable && usable.Count < u.Objects.Holds.Count + ? u.WithObjects(u.Objects with { Holds = usable.ToArray() }) + : u).ToArray(); + + return units.Where((u, i) => !ReferenceEquals(u, line.Units[i])).Any() ? rebuild(line, units: units) : line; + } + /// /// The line's ORIGINAL TEXT (backlog 330) rides along untouched unless /// replaces it; its unromanised words keep their places, clamped @@ -241,8 +255,10 @@ public static string JoinedOriginal(IReadOnlyList units, IReadOnlyLis /// /// A RESIZE (the default) re-times the word AROUND its dividers: the mapper is pulling /// one edge to better fit the vocal, and the vocal events inside the word (a syllable onset, - /// a breath) did not move, so boundaries and rests keep their OWN times and any the new span - /// can no longer hold are dropped (see for the full reasoning). + /// a breath) did not move, so boundaries, rests and holds keep their OWN times and any the new span + /// can no longer hold are dropped (see for the full reasoning); a hold + /// the new span cuts into is trimmed instead, and one whose letter the new spread moves past + /// follows the word (). /// /// A TRANSLATION ( true, and the span really is the old one /// shifted whole) moves the word's interior WITH it: the mapper grabbed the word body, and a @@ -265,7 +281,7 @@ private static TimedUnit retime(TimedUnit unit, double start, double end, Timing return new TimedUnit { - Objects = unit.Objects.Retimed(unit.StartTime, unit.EndTime, start, end), + Objects = unit.Objects.Shifted(delta), Text = unit.Text, Original = unit.Original, OriginalSplits = unit.OriginalSplits, StartTime = start, @@ -286,9 +302,8 @@ private static TimedUnit retime(TimedUnit unit, double start, double end, Timing // re-timed window are dropped: the word shrank past them). var boundaries = clampBoundaries(unit.SyllableBoundaries, start, end); - return new TimedUnit + var resized = new TimedUnit { - Objects = unit.Objects.Retimed(unit.StartTime, unit.EndTime, start, end), Text = unit.Text, Original = unit.Original, OriginalSplits = unit.OriginalSplits, StartTime = start, @@ -302,6 +317,8 @@ private static TimedUnit retime(TimedUnit unit, double start, double end, Timing SyllableSplits = boundaries.Count == unit.SyllableBoundaries.Count ? unit.SyllableSplits : Array.Empty(), Pauses = ClampPauses(unit, start, end), }; + + return unit.Objects.IsEmpty ? resized : resized.WithObjects(unit.Objects with { Holds = HoldPlacement.Resized(unit, resized) }); } /// @@ -1010,6 +1027,7 @@ private static bool setOriginalLineText(EditorBeatmap editorBeatmap, TypeBeatHit return setLineText(editorBeatmap, hitObject, string.Join(' ', tokens), units => { var kept = new List(); + var keptIndices = new List(); var pending = new List(); int sourceCursor = 0; @@ -1021,6 +1039,7 @@ private static bool setOriginalLineText(EditorBeatmap editorBeatmap, TypeBeatHit continue; } + keptIndices.Add(i); string? original = i < sources.Count ? sources[i].Original : null; int at = original == null ? -1 : sourceText.IndexOf(original, sourceCursor, StringComparison.Ordinal); kept.Add(at < 0 || original == null ? LrcParser.WithOriginal(units[i], original) @@ -1029,19 +1048,19 @@ private static bool setOriginalLineText(EditorBeatmap editorBeatmap, TypeBeatHit sourceCursor = at + original.Length; } - return (string.Join(' ', kept.Select(u => u.Text)), kept, (romanised.Original, pending)); + return (string.Join(' ', kept.Select(u => u.Text)), kept, (romanised.Original, pending), keptIndices); }, holdMarksRefused, wordMarks == null ? null : tokenMarks, marksRefused); } /// /// The body of . For a commit that romanised its input /// (), the finishing step turns the placed units into the - /// line's final text, units and originals; it is null for plain text, which keeps the line's + /// line's final text, units, originals and retained source indices; it is null for plain text, which keeps the line's /// originals as they are. Such a commit has already read its hold marks: it passes each token's /// held letters as , and whether any mark was refused. /// private static bool setLineText(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, string rawUserText, - Func, (string Text, IReadOnlyList Units, (string? Original, IReadOnlyList Pending) Originals)>? finish, + Func, (string Text, IReadOnlyList Units, (string? Original, IReadOnlyList Pending) Originals, IReadOnlyList SourceIndices)>? finish, Action? holdMarksRefused = null, IReadOnlyList?>? readHoldMarks = null, bool marksRefused = false) { @@ -1134,9 +1153,10 @@ private static bool setLineText(EditorBeatmap editorBeatmap, TypeBeatHitObject h units = applyPipes(units, tokens, pipes, out authoredSubdivision, line.Units); } - // Word objects follow their words on the paths that rebuild units (the same-count path kept them by place). + // Reuse the object carry's existing LCS correspondence when checking surviving words. + int?[] carriedFrom = Enumerable.Range(0, units.Count).Select(i => (int?)i).ToArray(); if (tokens.Length != line.Units.Count || hitObject.Granularity == TimingGranularity.Line) - units = carryWordObjects(line.Units, units); + units = carryWordObjects(line.Units, units, out carriedFrom); if (hitObject.Granularity != TimingGranularity.Line && !textUnchanged && units.Any(u => u.EndTime - u.StartTime < MIN_WORD_SPAN_MS)) @@ -1151,28 +1171,72 @@ private static bool setLineText(EditorBeatmap editorBeatmap, TypeBeatHitObject h units = clampUnits(units, line.StartTime, windowEnd); } + // Hold-marker deletion is intentional. Only the old holds the mapper kept can + // veto a shape edit, including a pipe and marker changed in the same commit. + bool preservesShape(IReadOnlyList candidate, IReadOnlyList? sourceIndices = null) + { + for (int i = 0; i < candidate.Count; i++) + { + int sourceIndex = sourceIndices?[i] ?? i; + if (carriedFrom[sourceIndex] is not int oldIndex) + continue; + var before = line.Units[oldIndex]; + var after = candidate[i]; + if (before.Text != after.Text || before.Objects.Holds.Count == 0) + continue; + var played = new WordObjects { Holds = HeldWord.UsableHolds(before) } + .Retimed(before.StartTime, before.EndTime, after.StartTime, after.EndTime).Holds; + // Word placement already carries holds, dividers and rests proportionally. + // Compare the old shape in that same frame, so ordinary placement is legal. + if (before.StartTime != after.StartTime || before.EndTime != after.EndTime) + { + before = new TimedUnit + { + Text = before.Text, + StartTime = after.StartTime, + EndTime = after.EndTime, + Objects = before.Objects.Retimed(before.StartTime, before.EndTime, after.StartTime, after.EndTime), + SyllableBoundaries = rescaleBoundaries(before.SyllableBoundaries, before.StartTime, before.EndTime, after.StartTime, after.EndTime), + SyllableSplits = before.SyllableSplits, + Pauses = scalePauses(before, after.StartTime, after.EndTime), + }; + } + var wanted = holdMarks != null && sourceIndex < holdMarks.Count ? holdMarks[sourceIndex] : null; + var kept = before.Objects.Holds.Where(h => wanted == null || wanted.ContainsKey(h.Char)).ToArray(); + before = before.WithObjects(before.Objects with { Holds = kept }); + after = after.WithObjects(after.Objects with { Holds = kept }); + var still = HeldWord.UsableHolds(after); + if (played.Any(h => (wanted == null || wanted.ContainsKey(h.Char)) && !still.Contains(h)) + || !HoldPlacement.PreservesHolds(before, after)) + return false; + } + return true; + } + + if (!preservesShape(units)) + return false; + // The hold marks last, on the words as they will be stored. units = HoldTickMarkers.Apply(units, holdMarks, markedHold, out bool holdsRefused); marksRefused |= holdsRefused; bool wordCountChanged = hitObject.Granularity != TimingGranularity.Line && tokens.Length != line.Units.Count; - editorBeatmap.BeginChange(); - + LyricLine candidate; if (finish != null) { - var (text, finalUnits, originals) = finish(units); - setLine(editorBeatmap, hitObject, rebuild(line, rawText: text, units: finalUnits, originals: originals)); - - // An unromanised word lives only in words[], so the map has to carry them. + var (text, finalUnits, originals, sourceIndices) = finish(units); + if (!preservesShape(finalUnits, sourceIndices)) + return false; + candidate = rebuild(line, rawText: text, units: finalUnits, originals: originals); wordCountChanged |= originals.Pending.Count > 0 || line.UnromanisedWords.Count > 0; } else - { - setLine(editorBeatmap, hitObject, rebuild(line, rawText: normalized, units: units)); - } + candidate = rebuild(line, rawText: normalized, units: units); - setLine(editorBeatmap, hitObject, normalizeOriginalSubdivisions(editorBeatmap, hitObject.Line)); + candidate = normalizeOriginalSubdivisions(editorBeatmap, candidate); + editorBeatmap.BeginChange(); + setLine(editorBeatmap, hitObject, candidate); // The sung end follows the last word only when this commit moved it: a word typed on // at the tail, or the tail word typed away. A same-count commit, and any change that // leaves the last word alone, keeps the stored end_ms exactly. @@ -1230,7 +1294,7 @@ private static void commitUnits(EditorBeatmap editorBeatmap, TypeBeatHitObject h /// Carries word objects across a text commit that rebuilt the units: words are matched by the /// longest common subsequence of their spellings, and a matched word's holds follow its new span. /// - private static IReadOnlyList carryWordObjects(IReadOnlyList before, IReadOnlyList after) + private static IReadOnlyList carryWordObjects(IReadOnlyList before, IReadOnlyList after, out int?[] carriedFrom) { int n = before.Count, m = after.Count; int[,] lcs = new int[n + 1, m + 1]; @@ -1246,12 +1310,14 @@ private static IReadOnlyList carryWordObjects(IReadOnlyList /// + /// A divider never costs the word a hold: when the bisected letter split would leave a held + /// letter on the wrong side of the divider's time, the divider stays where it was put and the + /// nearest split that keeps every hold is taken instead; with none, nothing is added. + /// /// The word becomes Explicit hand timing and the beatmap is promoted to Syllable /// granularity. The encoder only persists syllables[] for units that carry boundaries, so /// without the promotion a subdivision would silently vanish on save. No-op when there is no @@ -2640,21 +2710,34 @@ public static void DeleteLines(EditorBeatmap editorBeatmap, IReadOnlyList? split(int segment) => originalLyrics && unit.Original != null - ? bisectOriginalSplit(unit, segment, OriginalSubdivisionLanguage(editorBeatmap, line), out manual) + bool onOriginal = originalLyrics && unit.Original != null; + string? language = onOriginal ? OriginalSubdivisionLanguage(editorBeatmap, line) : null; + IReadOnlyList? split(int segment) => onOriginal + ? bisectOriginalSplit(unit, segment, language, out manual) : bisectSplit(unit, segment); - void commit(IReadOnlyList times, IReadOnlyList cuts) + bool commit(IReadOnlyList times, IReadOnlyList cuts, int segment) { - editorBeatmap.BeginChange(); - replaceUnitBoundaries(editorBeatmap, hitObject, unitIndex, times, cuts); - if (manual is OriginalLyricSplit link) + var links = manual is OriginalLyricSplit link ? unit.OriginalSplits.Append(link).ToArray() : unit.OriginalSplits; + + if (replaceUnitShape(editorBeatmap, hitObject, unitIndex, times, cuts, unit.Pauses, links)) + return true; + + // Refused for a hold it would cost. A manual original link is tied to its own cut. + if (manual != null) + return false; + + var effective = cuts.Count > 0 ? cuts : SyllableSegments.SplitsFor(unit.Text, times.Count + 1, cuts); + if (effective.Count != times.Count) + return false; + + foreach (int[] moved in movedSplits(unit.Text, effective, segment, c => !onOriginal || OriginalLyricSubdivisions.SourceCut(unit, c, language).HasValue)) { - var changed = hitObject.Line.Units.ToArray(); - changed[unitIndex] = OriginalLyricSubdivisions.WithExplicit(changed[unitIndex], unit.OriginalSplits.Append(link)); - setLine(editorBeatmap, hitObject, rebuild(hitObject.Line, units: changed)); + if (replaceUnitShape(editorBeatmap, hitObject, unitIndex, times, moved, unit.Pauses, links)) + return true; } - editorBeatmap.EndChange(); + + return false; } // Segment edges: word start, existing boundaries, word end. @@ -2667,8 +2750,7 @@ void commit(IReadOnlyList times, IReadOnlyList cuts) var caretBoundaries = unit.SyllableBoundaries.Append(caret).OrderBy(b => b).ToArray(); if (split(caretSegment) is not { } caretSplits) return null; - commit(caretBoundaries, caretSplits); - return caret; + return commit(caretBoundaries, caretSplits, caretSegment) ? caret : null; } // No caret in the word (or none in a sung span of it): split the widest one. @@ -2695,14 +2777,13 @@ void commit(IReadOnlyList times, IReadOnlyList cuts) var boundaries = unit.SyllableBoundaries.Append(mid).OrderBy(b => b).ToArray(); if (split(widestSegment) is not { } midSplits) return null; - commit(boundaries, midSplits); - return mid; + return commit(boundaries, midSplits, widestSegment) ? mid : null; } /// /// Subdivide on one word: inside a hold's tick window it drops a hold tick (), /// anywhere else a syllable boundary (on the original spelling's cuts with , - /// see ). False only when the tick was refused. + /// see ). False when the tick or subdivision was refused. /// public static bool SubdivideWord(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, int unitIndex, double? caretTime, bool originalLyrics = false) { @@ -2718,8 +2799,7 @@ public static bool SubdivideWord(EditorBeatmap editorBeatmap, TypeBeatHitObject } } - AddSyllableBoundary(editorBeatmap, hitObject, unitIndex, caretTime, originalLyrics); - return true; + return AddSyllableBoundary(editorBeatmap, hitObject, unitIndex, caretTime, originalLyrics).HasValue; } /// @@ -2805,6 +2885,31 @@ private static IReadOnlyList bisectSplit(TimedUnit unit, int segment) return splits; } + /// + /// with split moved to each other letter between its neighbours + /// that accepts, nearest first. + /// + private static IEnumerable movedSplits(string text, IReadOnlyList splits, int index, Func allowed) + { + int lo = index > 0 ? splits[index - 1] : 0; + int hi = index + 1 < splits.Count ? splits[index + 1] : text.Length; + int at = splits[index]; + + for (int d = 1; at - d > lo || at + d < hi; d++) + { + for (int side = -1; side <= 1; side += 2) + { + int c = at + side * d; + if (c <= lo || c >= hi || !allowed(c)) + continue; + + int[] moved = splits.ToArray(); + moved[index] = c; + yield return moved; + } + } + } + /// /// Drags syllable boundary of a word to /// , clamped to stay inside the word @@ -2835,6 +2940,14 @@ public static void SetSyllableBoundary(EditorBeatmap editorBeatmap, TypeBeatHitO // The word (or the neighbouring boundaries) leaves no valid slot; no-op rather than // clamp into an inverted range. + if (upper < lower) + return; + + // Nor may it cross a hold. + var holdBounds = HoldPlacement.DividerBounds(unit, boundaryIndex); + lower = Math.Max(lower, holdBounds.Lower); + upper = Math.Min(upper, holdBounds.Upper); + if (upper < lower) return; @@ -2919,31 +3032,31 @@ private static (int Lo, int Hi) stretchCharRange(TimedUnit unit, double time) /// Only the character split moves: no time, no boundary count, so granularity is /// untouched. Single undo step. /// - public static void SetSyllableSplit(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, int unitIndex, int boundaryIndex, int charIndex) + public static bool SetSyllableSplit(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, int unitIndex, int boundaryIndex, int charIndex) { var line = hitObject.Line; if (unitIndex < 0 || unitIndex >= line.Units.Count) - return; + return false; var unit = line.Units[unitIndex]; int segments = unit.SyllableBoundaries.Count + 1; if (boundaryIndex < 0 || boundaryIndex >= segments - 1) - return; + return false; var splits = SyllableSegments.SplitsFor(unit.Text, segments, unit.SyllableSplits).ToList(); // The syllabifier could not even produce this many segments (an over-forced short // word); there is nothing coherent to author against. if (splits.Count != segments - 1) - return; + return false; int lower = (boundaryIndex > 0 ? splits[boundaryIndex - 1] : 0) + 1; int upper = (boundaryIndex < splits.Count - 1 ? splits[boundaryIndex + 1] : unit.Text.Length) - 1; if (upper < lower) - return; + return false; splits[boundaryIndex] = Math.Clamp(charIndex, lower, upper); @@ -2956,7 +3069,7 @@ public static void SetSyllableSplit(EditorBeatmap editorBeatmap, TypeBeatHitObje : splits.ToArray(); if (sameSplits(stored, unit.SyllableSplits)) - return; + return false; var units = line.Units.ToArray(); @@ -2977,9 +3090,13 @@ public static void SetSyllableSplit(EditorBeatmap editorBeatmap, TypeBeatHitObje units[unitIndex] = OriginalLyricSubdivisions.CarryExplicit(unit, units[unitIndex]); + if (!HoldPlacement.PreservesHolds(unit, units[unitIndex])) + return false; + editorBeatmap.BeginChange(); setLine(editorBeatmap, hitObject, rebuild(line, units: units)); editorBeatmap.EndChange(); + return true; } /// @@ -2987,17 +3104,17 @@ public static void SetSyllableSplit(EditorBeatmap editorBeatmap, TypeBeatHitObje /// segments it split. When the word's last boundary goes the beatmap reconciles back down to /// Word granularity. Single undo step. /// - public static void RemoveSyllableBoundary(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, int unitIndex, int boundaryIndex) + public static bool RemoveSyllableBoundary(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, int unitIndex, int boundaryIndex) { var line = hitObject.Line; if (unitIndex < 0 || unitIndex >= line.Units.Count) - return; + return false; var unit = line.Units[unitIndex]; if (boundaryIndex < 0 || boundaryIndex >= unit.SyllableBoundaries.Count) - return; + return false; var boundaries = unit.SyllableBoundaries.Where((_, i) => i != boundaryIndex).ToArray(); @@ -3007,7 +3124,7 @@ public static void RemoveSyllableBoundary(EditorBeatmap editorBeatmap, TypeBeatH ? unit.SyllableSplits.Where((_, i) => i != boundaryIndex).ToArray() : Array.Empty(); - replaceUnitBoundaries(editorBeatmap, hitObject, unitIndex, boundaries, splits); + return replaceUnitBoundaries(editorBeatmap, hitObject, unitIndex, boundaries, splits); } /// @@ -3057,8 +3174,7 @@ public static bool RemoveNarrowestSyllableBoundary(EditorBeatmap editorBeatmap, } } - RemoveSyllableBoundary(editorBeatmap, hitObject, unitIndex, narrowest); - return true; + return RemoveSyllableBoundary(editorBeatmap, hitObject, unitIndex, narrowest); } /// @@ -3067,7 +3183,7 @@ public static bool RemoveNarrowestSyllableBoundary(EditorBeatmap editorBeatmap, /// beatmap's granularity is reconciled (up to Syllable while any boundary survives, back to /// Word when the last one is removed). Single undo step. /// - private static void replaceUnitBoundaries(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, int unitIndex, + private static bool replaceUnitBoundaries(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, int unitIndex, IReadOnlyList boundaries, IReadOnlyList splits) => replaceUnitShape(editorBeatmap, hitObject, unitIndex, boundaries, splits, hitObject.Line.Units[unitIndex].Pauses); @@ -3080,8 +3196,9 @@ private static void replaceUnitBoundaries(EditorBeatmap editorBeatmap, TypeBeatH /// and never below Word while a rest is there, since a rest is persisted inside words[]). /// Single undo step. /// - private static void replaceUnitShape(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, int unitIndex, - IReadOnlyList boundaries, IReadOnlyList splits, IReadOnlyList pauses) + private static bool replaceUnitShape(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, int unitIndex, + IReadOnlyList boundaries, IReadOnlyList splits, IReadOnlyList pauses, + IReadOnlyList? originalSplits = null) { var line = hitObject.Line; var units = line.Units.ToArray(); @@ -3107,8 +3224,12 @@ private static void replaceUnitShape(EditorBeatmap editorBeatmap, TypeBeatHitObj // by the SHIFT+drag that promotes a divider into one. Pauses = pauses, }; - if (unit.OriginalSplits.Count > 0) - units[unitIndex] = OriginalLyricSubdivisions.WithExplicit(units[unitIndex], unit.OriginalSplits); + var links = originalSplits ?? unit.OriginalSplits; + if (links.Count > 0) + units[unitIndex] = OriginalLyricSubdivisions.WithExplicit(units[unitIndex], links); + + if (!HoldPlacement.PreservesHolds(unit, units[unitIndex])) + return false; editorBeatmap.BeginChange(); setLine(editorBeatmap, hitObject, new LyricLine @@ -3126,6 +3247,7 @@ private static void replaceUnitShape(EditorBeatmap editorBeatmap, TypeBeatHitObj }); syncGranularity(editorBeatmap); editorBeatmap.EndChange(); + return true; } #endregion @@ -3325,33 +3447,17 @@ public static bool ExtendSubdivisionIntoPause(EditorBeatmap editorBeatmap, TypeB ? unit.SyllableSplits.Where((_, i) => i != boundaryIndex).ToArray() : Array.Empty(); - // A rest that would overlap or split a hold the word plays is refused. - if (!keepsHolds(unit, withShape(unit, boundaries, kept, added))) - return false; - - replaceUnitShape(editorBeatmap, hitObject, unitIndex, boundaries, kept, added); - return true; + // A rest that would overlap or split a hold the word plays is refused (replaceUnitShape). + return replaceUnitShape(editorBeatmap, hitObject, unitIndex, boundaries, kept, added); } /// - /// Whether every hold plays is still played on : a rest + /// Whether every hold plays is still played with as its rests: a rest /// edit may not overlap or split a hold (), nor leave one ending before - /// its letter is now due. + /// its letter is now due (). /// - private static bool keepsHolds(TimedUnit before, TimedUnit after) - { - var played = HeldWord.UsableHolds(before); - - if (played.Count == 0) - return true; - - var still = HeldWord.UsableHolds(after); - return played.All(still.Contains); - } - - /// private static bool keepsHolds(TimedUnit unit, IReadOnlyList pauses) - => keepsHolds(unit, withShape(unit, unit.SyllableBoundaries, unit.SyllableSplits, pauses)); + => HoldPlacement.PreservesHolds(unit, withShape(unit, unit.SyllableBoundaries, unit.SyllableSplits, pauses)); /// with other subdivisions and rests, for asking what a play would make of it. private static TimedUnit withShape(TimedUnit unit, IReadOnlyList boundaries, IReadOnlyList splits, IReadOnlyList pauses) @@ -3500,13 +3606,10 @@ private static void replaceUnitPauses(EditorBeatmap editorBeatmap, TypeBeatHitOb #region Holds - /// How far past its letter's target a dragged hold end is kept, so rounding never puts it on the target. - private const double hold_end_past_due_ms = 1; - /// /// Adds a hold on , or when null on the first character due at or after - /// . It starts at the letter's target and ends at its syllable's end - /// (halfway there when more letters follow in the syllable), and never past the start of a rest that + /// . It fits at least 100 ms inside the letter's syllable, preserving + /// its press target and the existing holds, and never extends past the start of a rest that /// follows the letter. Null when the hold would be unusable. One undo step. /// public static WordHold? AddHold(EditorBeatmap editorBeatmap, TypeBeatHitObject hitObject, int unitIndex, int? charIndex, double playheadTime) @@ -3531,7 +3634,7 @@ private static void replaceUnitPauses(EditorBeatmap editorBeatmap, TypeBeatHitOb /// public static WordHold? DefaultHold(TimedUnit unit, int? charIndex, double playheadTime) { - var flat = flattenedWithoutHolds(unit); + var flat = FlattenedWithoutHolds(unit); var cellChars = new List(); for (int i = 0; i < unit.Text.Length; i++) @@ -3567,47 +3670,7 @@ private static void replaceUnitPauses(EditorBeatmap editorBeatmap, TypeBeatHitOb } } - if (unit.Objects.Holds.Any(h => h.Char == c)) - return null; - - int gi = flat.SyllableIndexOf(c); - - if (gi < 0) - return null; - - var g = flat.Syllables[gi]; - double start = c == 0 ? unit.StartTime : flat.Cells[c].TargetTime; - double end = c == g.EndCellExclusive - 1 ? g.EndTime : start + (g.EndTime - start) / 2; - - double cap = c + 1 < unit.Text.Length ? unit.EndTime - MIN_SYLLABLE_MS : unit.EndTime; - - // A hold stays inside its stretch: held from the end of the rest before it, let go by the start of - // the rest after it. - foreach (var rest in HeldWord.RestsOf(unit)) - { - if (rest.SplitChar > c) - cap = Math.Min(cap, rest.StartTime); - else - start = Math.Max(start, rest.EndTime); - } - - end = Math.Min(end, cap); - - double due = HeldWord.LetterDueAt(unit, c); - - // A hold must end after its letter is due: extend a default span that does not. - if (!HeldWord.EndsAfterItsLetter(end, due)) - { - end = due + HeldWord.MIN_HOLD_MS; - - if (end > cap) - return null; - } - - var hold = new WordHold(c, start, end); - var holds = unit.Objects.Holds.Append(hold).OrderBy(h => h.Char).ToArray(); - - return allUsable(unit, holds) ? hold : null; + return HoldPlacement.Create(unit, c); } /// Removes hold from a word. One undo step. @@ -3756,36 +3819,11 @@ private static void moveHoldEdge(EditorBeatmap editorBeatmap, TypeBeatHitObject if (moveStart && hold.Char == 0) return; - bool hasNext = hold.Char + 1 < unit.Text.Length; - - // Slack so float error cannot leave a hold just under the minimum. - const double eps = 0.001; - double lower = moveStart ? unit.StartTime + MIN_SYLLABLE_MS : hold.StartTime + HeldWord.MIN_HOLD_MS + eps; - double upper = moveStart ? hold.EndTime - HeldWord.MIN_HOLD_MS - eps : hasNext ? unit.EndTime - MIN_SYLLABLE_MS : unit.EndTime; - - if (moveStart && holdIndex > 0) - lower = Math.Max(lower, holds[holdIndex - 1].EndTime); - - if (!moveStart && holdIndex < holds.Length - 1) - upper = Math.Min(upper, holds[holdIndex + 1].StartTime); - - // A rest is a wall: the hold stays inside its own stretch (HeldWord.ClearOfRest). - foreach (var rest in HeldWord.RestsOf(unit)) - { - if (moveStart && rest.SplitChar <= hold.Char) - lower = Math.Max(lower, rest.EndTime); - else if (!moveStart && rest.SplitChar > hold.Char) - upper = Math.Min(upper, rest.StartTime); - } - - if (!moveStart) - lower = Math.Max(lower, HeldWord.LetterDueAt(unit, hold.Char) + hold_end_past_due_ms); - - if (upper < lower) + if (HoldPlacement.ClampEdge(unit, holdIndex, moveStart, newTime) is not double clamped) return; - newTime = Math.Clamp(newTime, lower, upper); - holds[holdIndex] = moveStart ? HoldTicks.Stretched(hold, newTime, hold.EndTime) : HoldTicks.Stretched(hold, hold.StartTime, newTime); + newTime = clamped; + holds[holdIndex] = HoldPlacement.Respanned(hold, moveStart ? newTime : hold.StartTime, moveStart ? hold.EndTime : newTime); if (!allUsable(unit, holds)) return; @@ -3794,7 +3832,7 @@ private static void moveHoldEdge(EditorBeatmap editorBeatmap, TypeBeatHitObject } /// The word alone as a one-word literate line with no holds, so cell index is char index. - private static TypingLine flattenedWithoutHolds(TimedUnit unit) + internal static TypingLine FlattenedWithoutHolds(TimedUnit unit) => TypingLine.FromLyricLine(new LyricLine { RawText = unit.Text, diff --git a/typebeat.Game.Rulesets.TypeBeat/Edit/WordScriptEditor.cs b/typebeat.Game.Rulesets.TypeBeat/Edit/WordScriptEditor.cs index b10d7df8..7ddd84bd 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Edit/WordScriptEditor.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Edit/WordScriptEditor.cs @@ -158,6 +158,9 @@ private static string signatureOf(LyricLine line) /// One column: an upper (original) box and, for a word, a lower (romanised) box. private partial class ScriptColumn : FillFlowContainer { + [Resolved] + private LyricEditState state { get; set; } = null!; + private readonly List boxes = new List(); private string? fontFamily; @@ -215,7 +218,10 @@ private OsuTextBox box(string text, string placeholder, Func commi return; if (!commit(sender.Text)) + { sender.Text = committed; + state.Refuse(); + } }; boxes.Add(textBox); diff --git a/typebeat.Game.Rulesets.TypeBeat/Gameplay/HeldWord.cs b/typebeat.Game.Rulesets.TypeBeat/Gameplay/HeldWord.cs index 9c7a0b05..9c6a51f5 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Gameplay/HeldWord.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Gameplay/HeldWord.cs @@ -34,7 +34,7 @@ internal static IReadOnlyList UsableHolds(TimedUnit unit, Func 0, isCell).ToArray(); + var cuts = CutsOf(unit, rests.Count > 0, isCell).ToArray(); var kept = new List(); int lastChar = -1; double lastEnd = unit.StartTime; @@ -105,8 +105,8 @@ internal static bool RestFollows(TimedUnit unit, int charIndex, Func internal static bool EndsAfterItsLetter(double holdEnd, double letterDue) => holdEnd > letterDue; /// - /// When character is due without any hold: the later of the two target - /// eras, so a hold is honoured in both eras or neither. + /// When character is due without any hold, in the current subdivision-aligned target + /// era every live play uses. Holds postdate the older era, so no replay of one plays it. /// internal static double LetterDueAt(TimedUnit unit, int charIndex, Func? isCell = null) => TypingLine.HoldFreeCellTarget(unit, charIndex, isCell ?? Typeability.IsCell); @@ -115,7 +115,7 @@ internal static double LetterDueAt(TimedUnit unit, int charIndex, Func); the rests themselves are 's. /// - private static IEnumerable<(int Char, double Time)> cutsOf(TimedUnit unit, bool paused, Func isCell) + internal static IEnumerable<(int Char, double Time)> CutsOf(TimedUnit unit, bool paused, Func isCell) { if (paused && PausedWord.Of(unit.Text, unit.StartTime, unit.EndTime, unit, isCell) is PausedWord.Cut cut) { diff --git a/typebeat.Game.Rulesets.TypeBeat/Gameplay/HoldTicks.cs b/typebeat.Game.Rulesets.TypeBeat/Gameplay/HoldTicks.cs index c86c8b42..8e1f82d3 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Gameplay/HoldTicks.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Gameplay/HoldTicks.cs @@ -14,8 +14,8 @@ public static class HoldTicks /// The closest two ticks may sit. public const double MIN_GAP_MS = 20; - /// The earliest a tick may sit: clear of the press. - public static double WindowStart(double start) => start + HoldTailRule.MIN_SLACK_MS; + /// The earliest a tick may sit: the hold's start. A head pressed after a tick still credits it. + public static double WindowStart(double start) => start; /// A tick must sit before this: clear of the Great release window. public static double WindowEnd(double start, double end) => end - HoldTailRule.Slack(start, end); diff --git a/typebeat.Game.Rulesets.TypeBeat/Gameplay/TypingLine.cs b/typebeat.Game.Rulesets.TypeBeat/Gameplay/TypingLine.cs index c300df64..47bfac7a 100644 --- a/typebeat.Game.Rulesets.TypeBeat/Gameplay/TypingLine.cs +++ b/typebeat.Game.Rulesets.TypeBeat/Gameplay/TypingLine.cs @@ -1945,7 +1945,7 @@ private static void fillPausedStretches(PausedWord.Cut cut, double[] ramp, strin internal static double[] CellTargetsFor(TimedUnit unit, int typeableCount, Func? isCell = null) => tokenCellTargets(unit.Text, unit.StartTime, unit.EndTime, unit, typeableCount, isCell, alignSubdivisions: true); - /// The target of character as the word alone spreads it, the later of the two eras. + /// The target of character as the word alone spreads it in the current, subdivision-aligned era every live play uses. internal static double HoldFreeCellTarget(TimedUnit unit, int charIndex, Func isCell) { int k = 0, j = 0; @@ -1964,9 +1964,7 @@ internal static double HoldFreeCellTarget(TimedUnit unit, int charIndex, Func= k) return unit.EndTime; - double legacy = tokenCellTargets(unit.Text, unit.StartTime, unit.EndTime, unit, k, isCell)[j]; - double aligned = tokenCellTargets(unit.Text, unit.StartTime, unit.EndTime, unit, k, isCell, alignSubdivisions: true)[j]; - return Math.Max(legacy, aligned); + return tokenCellTargets(unit.Text, unit.StartTime, unit.EndTime, unit, k, isCell, alignSubdivisions: true)[j]; } private const double min_boundary_grace_ms = 250;