refactor: Timeline-Labels als eigenes Modell
Das Einsammeln der Labels für die Zeitachse liegt in `src/whiteboard/view/timeline_label_model.gd`. Die Logik ist subtiler, als sie aussieht: Sie läuft über die Abschnitte statt über die Wiedergabe-Einträge, damit Marken ohne Standzeit sichtbar bleiben, und ein Segment ohne eigenes Label erbt die Beschriftung seiner Elementgruppe. - `collect(routine)` liefert Element- und Kür-Labels plus Gesamtdauer. - `_refresh_timeline_labels` ist auf drei Zeilen geschrumpft und setzt nur noch die Zeitachse. - Abgesichert durch die Wiedergabetests, die die Labels der Zeitachse prüfen. Controller: 8.194 -> 8.154 Zeilen. Suite grün.
This commit is contained in:
parent
a403270643
commit
e47b8e0a9a
5 changed files with 76 additions and 48 deletions
|
|
@ -4148,50 +4148,10 @@ func _sort_timeline_labels() -> void:
|
|||
func _refresh_timeline_labels() -> void:
|
||||
if timeline_label_lane == null:
|
||||
return
|
||||
|
||||
# Walk the authored routine like the playback timeline does. Using the
|
||||
# segments directly (instead of only the timed playback entries) also
|
||||
# keeps element markers with zero stand time visible.
|
||||
var element_labels: Array[Dictionary] = []
|
||||
var total := 0.0
|
||||
if _routine != null:
|
||||
for section: RoutineSection in _routine.sections:
|
||||
if section == null:
|
||||
continue
|
||||
var group_starts: Dictionary[String, ResolvedElement] = {}
|
||||
for element: ResolvedElement in section.get_elements():
|
||||
if not element.segments.is_empty():
|
||||
group_starts[element.segments[0].segment_id] = element
|
||||
for segment: PathSegment in section.segments:
|
||||
if segment == null:
|
||||
continue
|
||||
var text := segment.label.strip_edges()
|
||||
if text.is_empty() and group_starts.has(segment.segment_id):
|
||||
text = group_starts[segment.segment_id].get_caption().strip_edges()
|
||||
if not text.is_empty():
|
||||
element_labels.append({
|
||||
"time_seconds": total,
|
||||
"text": text,
|
||||
})
|
||||
total += maxf(
|
||||
segment.get_effective_duration_seconds(),
|
||||
0.0
|
||||
)
|
||||
|
||||
var custom_labels: Array[Dictionary] = []
|
||||
if _routine != null:
|
||||
for entry: Dictionary in _routine.timeline_labels:
|
||||
var text := str(entry.get("text", "")).strip_edges()
|
||||
if text.is_empty():
|
||||
continue
|
||||
custom_labels.append({
|
||||
"time_seconds": float(entry.get("time_seconds", 0.0)),
|
||||
"text": text,
|
||||
})
|
||||
|
||||
var labels := TimelineLabelModel.collect(_routine)
|
||||
timeline_label_lane.set_timeline(
|
||||
element_labels,
|
||||
custom_labels,
|
||||
labels["elements"],
|
||||
labels["custom"],
|
||||
_playback_total_duration
|
||||
)
|
||||
|
||||
|
|
|
|||
53
rinkplanner/src/whiteboard/view/timeline_label_model.gd
Normal file
53
rinkplanner/src/whiteboard/view/timeline_label_model.gd
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
class_name TimelineLabelModel
|
||||
extends RefCounted
|
||||
|
||||
## Collects the labels shown on the playback timeline.
|
||||
##
|
||||
## Pure: the routine goes in, the two label lists and the total duration come
|
||||
## out. Walks the authored sections (not the timed playback entries), so
|
||||
## element markers with zero stand time stay visible. A segment without its own
|
||||
## label falls back to the caption of its element group, so a sequence group is
|
||||
## named once.
|
||||
|
||||
## Returns `{"elements": Array, "custom": Array, "duration": float}`. Each
|
||||
## entry is `{"time_seconds": float, "text": String}`.
|
||||
static func collect(routine: Routine) -> Dictionary:
|
||||
var element_labels: Array[Dictionary] = []
|
||||
var total := 0.0
|
||||
if routine != null:
|
||||
for section: RoutineSection in routine.sections:
|
||||
if section == null:
|
||||
continue
|
||||
var group_starts: Dictionary[String, ResolvedElement] = {}
|
||||
for element: ResolvedElement in section.get_elements():
|
||||
if not element.segments.is_empty():
|
||||
group_starts[element.segments[0].segment_id] = element
|
||||
for segment: PathSegment in section.segments:
|
||||
if segment == null:
|
||||
continue
|
||||
var text := segment.label.strip_edges()
|
||||
if text.is_empty() and group_starts.has(segment.segment_id):
|
||||
text = group_starts[segment.segment_id].get_caption().strip_edges()
|
||||
if not text.is_empty():
|
||||
element_labels.append({
|
||||
"time_seconds": total,
|
||||
"text": text,
|
||||
})
|
||||
total += maxf(segment.get_effective_duration_seconds(), 0.0)
|
||||
|
||||
var custom_labels: Array[Dictionary] = []
|
||||
if routine != null:
|
||||
for entry: Dictionary in routine.timeline_labels:
|
||||
var text := str(entry.get("text", "")).strip_edges()
|
||||
if text.is_empty():
|
||||
continue
|
||||
custom_labels.append({
|
||||
"time_seconds": float(entry.get("time_seconds", 0.0)),
|
||||
"text": text,
|
||||
})
|
||||
|
||||
return {
|
||||
"elements": element_labels,
|
||||
"custom": custom_labels,
|
||||
"duration": total,
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bi7a47b46qnej
|
||||
Loading…
Add table
Add a link
Reference in a new issue