feat: Element-Marker mit Inspector und Export

- PathSegment traegt element_type/element_code/element_level (D3)
- Element-Werkzeug setzt Punktmarker per Tipp; Inspector fuer Typ,
  Kuerzel und Level; Marker per Griff verschiebbar
- Darstellung auf Canvas und in Praesentation inkl. Ghosting,
  Labels-Schalter blendet Kuerzel aus
- Sequenzbereiche sind getaggte Segmente, Tag ueber Inspector setzbar
- SVG/PNG-Export mit Typform und Kuerzel
- Timing-Leiste blendet irrelevante Regler im Element-Modus aus
- Griff-Drag beginnt erst mit der ersten Bewegung (kein Undo bei Tipp)
- Tests: 577 Assertions gruen; Findings, Architektur und Roadmap aktuell
This commit is contained in:
torsten 2026-10-30 23:38:57 +01:00
parent 7c6c8fc3d4
commit 5968272691
15 changed files with 1429 additions and 67 deletions

View file

@ -312,7 +312,24 @@ disabled = true
text = "Label"
tooltip_text = "Beschriftung für das ausgewählte Segment"
[node name="ElementButton" type="Button" parent="Layout/TimingBar/TimingContent"]
unique_name_in_owner = true
custom_minimum_size = Vector2(96, 56)
layout_mode = 2
theme_override_font_sizes/font_size = 15
disabled = true
text = "Element"
tooltip_text = "Elementtyp, Kürzel und Level für das ausgewählte Segment"
[node name="ElementTypeOption" type="OptionButton" parent="Layout/TimingBar/TimingContent"]
unique_name_in_owner = true
custom_minimum_size = Vector2(132, 56)
layout_mode = 2
theme_override_font_sizes/font_size = 15
tooltip_text = "Elementtyp für neue Marker und die aktuelle Auswahl"
[node name="TimingSeparator1" type="VSeparator" parent="Layout/TimingBar/TimingContent"]
unique_name_in_owner = true
layout_mode = 2
[node name="DurationMinusButton" type="Button" parent="Layout/TimingBar/TimingContent"]
@ -344,6 +361,7 @@ text = "+"
tooltip_text = "Dauer erhöhen"
[node name="TimingSeparator2" type="VSeparator" parent="Layout/TimingBar/TimingContent"]
unique_name_in_owner = true
layout_mode = 2
[node name="SpeedMinusButton" type="Button" parent="Layout/TimingBar/TimingContent"]
@ -375,6 +393,7 @@ text = "+"
tooltip_text = "Tempo erhöhen"
[node name="TimingSeparator3" type="VSeparator" parent="Layout/TimingBar/TimingContent"]
unique_name_in_owner = true
layout_mode = 2
[node name="ProfileOption" type="OptionButton" parent="Layout/TimingBar/TimingContent"]
@ -543,6 +562,66 @@ placeholder_text = "z. B. 3Lz, Eingang, Choreo"
max_length = 40
caret_blink = true
[node name="ElementDialog" type="ConfirmationDialog" parent="."]
unique_name_in_owner = true
title = "Element"
size = Vector2i(520, 360)
ok_button_text = "Übernehmen"
cancel_button_text = "Abbrechen"
[node name="ElementBox" type="VBoxContainer" parent="ElementDialog"]
offset_left = 12.0
offset_top = 12.0
offset_right = 508.0
offset_bottom = 280.0
theme_override_constants/separation = 8
[node name="ElementTypeLabel" type="Label" parent="ElementDialog/ElementBox"]
layout_mode = 2
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
theme_override_font_sizes/font_size = 15
text = "Elementtyp"
[node name="ElementDialogTypeOption" type="OptionButton" parent="ElementDialog/ElementBox"]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 56)
layout_mode = 2
theme_override_font_sizes/font_size = 17
[node name="ElementCodeLabel" type="Label" parent="ElementDialog/ElementBox"]
layout_mode = 2
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
theme_override_font_sizes/font_size = 15
text = "Kürzel"
[node name="ElementCodeEdit" type="LineEdit" parent="ElementDialog/ElementBox"]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 56)
layout_mode = 2
theme_override_font_sizes/font_size = 17
placeholder_text = "z. B. 3Lz, CCoSp4, ChStSq"
max_length = 24
caret_blink = true
[node name="ElementLevelLabel" type="Label" parent="ElementDialog/ElementBox"]
layout_mode = 2
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
theme_override_font_sizes/font_size = 15
text = "Level (Pirouetten und Sequenzen)"
[node name="ElementLevelOption" type="OptionButton" parent="ElementDialog/ElementBox"]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 56)
layout_mode = 2
theme_override_font_sizes/font_size = 17
[node name="ElementHint" type="Label" parent="ElementDialog/ElementBox"]
layout_mode = 2
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
theme_override_font_sizes/font_size = 14
text = "„Kein Element“ entfernt die Markierung; reine Punktmarker werden dabei gelöscht. Kürzel erscheinen auf Canvas und Export."
autowrap_mode = 3
[node name="DeleteDialog" type="ConfirmationDialog" parent="."]
unique_name_in_owner = true
title = "Abschnitt löschen"

View file

@ -26,6 +26,19 @@ enum TimingMode {
DURATION,
}
## Element markers follow decision D3: a jump point or spin centre is a
## zero-length segment tagged with an element. A sequence can also be a range,
## i.e. a normal segment that carries the element type.
enum ElementType {
NONE,
JUMP,
SPIN,
SEQUENCE,
}
const ELEMENT_CODE_MAX_LENGTH := 24
const ELEMENT_MAX_LEVEL := 4
@export var segment_id: String = ""
@export var curve: Curve2D
@export var direction: Direction = Direction.FORWARD
@ -34,6 +47,11 @@ enum TimingMode {
@export var speed_mps: float = 4.3
@export var timing_mode: TimingMode = TimingMode.SPEED
@export var element_id: String = ""
@export var element_type: ElementType = ElementType.NONE
@export var element_code: String = ""
## ISU level: 0 is "Base", 1–4 are the graded levels. Only used by spins and
## sequences; jumps keep 0.
@export var element_level: int = 0
@export var label: String = ""
## Geometry metadata. Start and end are always the first and last curve points;
@ -91,6 +109,48 @@ func is_marker() -> bool:
return get_length_m() <= 0.0
## True for a zero-length element marker (jump point, spin centre). A sequence
## range keeps its length and is only tagged with an element type.
func is_element_marker() -> bool:
return element_type != ElementType.NONE and is_marker()
func is_element() -> bool:
return element_type != ElementType.NONE
static func element_type_name(type: ElementType) -> String:
match type:
ElementType.JUMP:
return "Sprung"
ElementType.SPIN:
return "Pirouette"
ElementType.SEQUENCE:
return "Sequenz"
return "Element"
## Applies an element in one step and keeps code and level within their bounds.
func set_element(type: ElementType, code: String, level: int) -> void:
element_type = type
if type == ElementType.NONE:
element_code = ""
element_level = 0
return
element_code = code.strip_edges().left(ELEMENT_CODE_MAX_LENGTH)
element_level = clampi(level, 0, ELEMENT_MAX_LEVEL)
## Short caption for the canvas and exports, e.g. "3Lz" or "CCoSp4 L3".
func get_element_caption() -> String:
var code := element_code.strip_edges()
if code.is_empty():
code = element_type_name(element_type)
if element_level > 0 and element_type != ElementType.JUMP:
return "%s L%d" % [code, element_level]
return code
func is_arc() -> bool:
return template == Template.ARC
@ -110,6 +170,14 @@ func validate() -> PackedStringArray:
errors.append("a segment with length needs a positive duration_seconds")
if speed_mps <= 0.0:
errors.append("speed_mps must be positive")
if element_level < 0 or element_level > ELEMENT_MAX_LEVEL:
errors.append("element_level must be between 0 and %d" % ELEMENT_MAX_LEVEL)
if element_code.strip_edges().length() > ELEMENT_CODE_MAX_LENGTH:
errors.append(
"element_code must not exceed %d characters" % ELEMENT_CODE_MAX_LENGTH
)
if element_type == ElementType.NONE and not element_code.strip_edges().is_empty():
errors.append("element_code needs an element_type")
if template == Template.ARC:
if arc_depth_ratio <= 0.0 or arc_depth_ratio >= 0.5:
errors.append("arc_depth_ratio must be between 0 and 0.5")

View file

@ -9,6 +9,7 @@ enum Tool {
LINE,
ARC_LEFT,
ARC_RIGHT,
ELEMENT,
}
enum FileAction {
@ -57,6 +58,9 @@ const COMPACT_LAYOUT_WIDTH := 1280.0
@onready var title_label: Label = %Title
@onready var tool_label: Label = %ToolLabel
@onready var timing_title: Label = %TimingTitle
@onready var timing_separator_1: VSeparator = %TimingSeparator1
@onready var timing_separator_2: VSeparator = %TimingSeparator2
@onready var timing_separator_3: VSeparator = %TimingSeparator3
@onready var sections_panel: PanelContainer = %SectionsPanel
@onready var tool_option: OptionButton = %ToolOption
@onready var forward_button: Button = %ForwardButton
@ -93,6 +97,12 @@ const COMPACT_LAYOUT_WIDTH := 1280.0
@onready var timing_selection_label: Label = %TimingSelectionLabel
@onready var label_button: Button = %LabelButton
@onready var labels_toggle: Button = %LabelsToggle
@onready var element_button: Button = %ElementButton
@onready var element_type_option: OptionButton = %ElementTypeOption
@onready var element_dialog: ConfirmationDialog = %ElementDialog
@onready var element_dialog_type_option: OptionButton = %ElementDialogTypeOption
@onready var element_code_edit: LineEdit = %ElementCodeEdit
@onready var element_level_option: OptionButton = %ElementLevelOption
@onready var segment_label_dialog: ConfirmationDialog = %SegmentLabelDialog
@onready var segment_label_edit: LineEdit = %SegmentLabelEdit
@onready var duration_minus_button: Button = %DurationMinusButton
@ -130,6 +140,8 @@ var _section_buttons: Dictionary[String, Button] = {}
var _tool: Tool = Tool.LINE
var _direction: PathSegment.Direction = PathSegment.Direction.FORWARD
var _edge: PathSegment.Edge = PathSegment.Edge.OUTSIDE
var _element_type: PathSegment.ElementType = PathSegment.ElementType.JUMP
var _element_level: int = 0
var _preset_speed: float = DEFAULT_SPEED_MPS
var _current_path: String = ""
var _dirty: bool = false
@ -159,6 +171,7 @@ func _ready() -> void:
_setup_file_menu()
_setup_playback_controls()
_setup_timing_controls()
_setup_element_controls()
_setup_export_controls()
labels_toggle.set_pressed_no_signal(rink_canvas.labels_visible)
@ -187,6 +200,7 @@ func _ready() -> void:
rink_canvas.draw_updated.connect(_on_draw_updated)
rink_canvas.draw_finished.connect(_on_draw_finished)
rink_canvas.draw_cancelled.connect(_on_draw_cancelled)
rink_canvas.marker_requested.connect(_on_marker_requested)
rink_canvas.segment_selected.connect(_on_segment_selected)
rink_canvas.selection_cleared.connect(_on_selection_cleared)
rink_canvas.segment_handle_drag_started.connect(_on_handle_drag_started)
@ -215,6 +229,9 @@ func _ready() -> void:
labels_toggle.toggled.connect(_on_labels_toggled)
segment_label_dialog.confirmed.connect(_on_label_confirmed)
segment_label_edit.text_submitted.connect(_on_label_submitted)
element_button.pressed.connect(_open_element_dialog)
element_dialog.confirmed.connect(_on_element_confirmed)
element_type_option.item_selected.connect(_on_element_type_selected)
resized.connect(_apply_responsive_layout)
_apply_display_scale()
@ -355,6 +372,167 @@ func _on_label_submitted(text: String) -> void:
set_selected_segment_label(text)
func get_element_type() -> PathSegment.ElementType:
return _element_type
## Selects the type used for the next marker. Existing selections are not
## touched; the toolbar option applies to the selection separately.
func set_element_type(type: PathSegment.ElementType) -> void:
_element_type = type
var index := element_type_option.get_item_index(type)
if index >= 0:
element_type_option.select(index)
func get_element_level() -> int:
return _element_level
func get_selected_element_caption() -> String:
var segment := get_selected_segment()
return segment.get_element_caption() if segment != null else ""
## Tags the selected segment with an element (or removes the tag). Returns true
## when the model changed.
func set_selected_element(
type: PathSegment.ElementType,
code: String,
level: int
) -> bool:
var segment := get_selected_segment()
if segment == null:
return false
if type == PathSegment.ElementType.NONE and segment.is_element_marker():
# A point marker without an element has no meaning: remove it entirely.
return delete_selected_segment()
var cleaned := code.strip_edges().left(PathSegment.ELEMENT_CODE_MAX_LENGTH)
var clamped := clampi(level, 0, PathSegment.ELEMENT_MAX_LEVEL)
if type == PathSegment.ElementType.NONE:
cleaned = ""
clamped = 0
if (
segment.element_type == type
and segment.element_code == cleaned
and segment.element_level == clamped
):
return false
_record_undo()
segment.set_element(type, cleaned, clamped)
if type != PathSegment.ElementType.NONE:
# Keep the placement defaults on the last real element type.
_element_type = type
_element_level = clamped
_mark_dirty()
rink_canvas.refresh()
_sync_toolbar_to_selection()
_update_status()
return true
## Places a zero-length element marker. The marker is selected so the element
## inspector can refine code and level; the type defaults to the last placed
## element if the caller does not pass one.
func add_element_marker(
position: Vector2,
type: PathSegment.ElementType = PathSegment.ElementType.JUMP,
code: String = "",
level: int = -1
) -> PathSegment:
if _active_section == null:
return null
if type == PathSegment.ElementType.NONE:
type = PathSegment.ElementType.JUMP
if _playing or not _playback_section_id.is_empty():
reset_playback()
_record_undo()
var segment := _create_segment(position, _direction, _edge)
var curve := Curve2D.new()
curve.add_point(_routine.rink.clamp_point(position))
segment.curve = curve
segment.duration_seconds = 0.0
segment.timing_mode = PathSegment.TimingMode.SPEED
segment.set_element(
type,
code,
_element_level if level < 0 else level
)
_active_section.segments.append(segment)
_selected_segment_id = segment.segment_id
_mark_dirty()
rink_canvas.set_selected_segment(segment.segment_id)
rink_canvas.refresh()
_update_status()
return segment
func _on_marker_requested(model_point: Vector2) -> void:
add_element_marker(model_point, _element_type, "", _element_level)
func _setup_element_controls() -> void:
element_type_option.clear()
element_type_option.add_item("Sprung", PathSegment.ElementType.JUMP)
element_type_option.add_item("Pirouette", PathSegment.ElementType.SPIN)
element_type_option.add_item("Sequenz", PathSegment.ElementType.SEQUENCE)
element_type_option.select(
element_type_option.get_item_index(PathSegment.ElementType.JUMP)
)
element_dialog_type_option.clear()
element_dialog_type_option.add_item("Kein Element", PathSegment.ElementType.NONE)
element_dialog_type_option.add_item("Sprung", PathSegment.ElementType.JUMP)
element_dialog_type_option.add_item("Pirouette", PathSegment.ElementType.SPIN)
element_dialog_type_option.add_item("Sequenz", PathSegment.ElementType.SEQUENCE)
element_level_option.clear()
element_level_option.add_item("Base", 0)
for level: int in range(1, PathSegment.ELEMENT_MAX_LEVEL + 1):
element_level_option.add_item("Level %d" % level, level)
func _on_element_type_selected(index: int) -> void:
var type: PathSegment.ElementType = element_type_option.get_item_id(index)
_element_type = type
var selected := get_selected_segment()
if selected == null:
return
set_selected_element(type, selected.element_code, selected.element_level)
func _open_element_dialog() -> void:
var segment := get_selected_segment()
if segment == null:
return
var type_index := element_dialog_type_option.get_item_index(segment.element_type)
if type_index < 0:
type_index = 0
element_dialog_type_option.select(type_index)
element_code_edit.text = segment.element_code
var level_index := element_level_option.get_item_index(segment.element_level)
if level_index < 0:
level_index = 0
element_level_option.select(level_index)
element_dialog.popup_centered(Vector2i(520, 360))
element_code_edit.grab_focus()
element_code_edit.select_all()
func _on_element_confirmed() -> void:
var type: PathSegment.ElementType = element_dialog_type_option.get_item_id(
element_dialog_type_option.selected
)
var level: int = element_level_option.get_item_id(element_level_option.selected)
set_selected_element(type, element_code_edit.text, level)
func add_section() -> RoutineSection:
_record_undo()
_section_counter += 1
@ -612,6 +790,9 @@ func _clone_segment(source: PathSegment) -> PathSegment:
clone.speed_mps = source.speed_mps
clone.timing_mode = source.timing_mode
clone.element_id = source.element_id
clone.element_type = source.element_type
clone.element_code = source.element_code
clone.element_level = source.element_level
clone.label = source.label
clone.template = source.template
clone.arc_depth_ratio = source.arc_depth_ratio
@ -705,6 +886,7 @@ func _setup_tool_options() -> void:
tool_option.add_item("Linie", Tool.LINE)
tool_option.add_item("Bogen links", Tool.ARC_LEFT)
tool_option.add_item("Bogen rechts", Tool.ARC_RIGHT)
tool_option.add_item("Element", Tool.ELEMENT)
tool_option.select(tool_option.get_item_index(Tool.LINE))
_apply_tool(Tool.LINE)
@ -716,8 +898,10 @@ func _on_tool_selected(index: int) -> void:
func _apply_tool(tool: Tool) -> void:
_tool = tool
var selecting := tool == Tool.SELECT
rink_canvas.set_drawing_enabled(not selecting)
var placing := tool == Tool.ELEMENT
rink_canvas.set_drawing_enabled(not selecting and not placing)
rink_canvas.set_selection_enabled(selecting)
rink_canvas.set_marker_placement_enabled(placing)
_update_status()
@ -731,6 +915,8 @@ func _tool_from_id(tool_id: int) -> Tool:
return Tool.ARC_LEFT
Tool.ARC_RIGHT:
return Tool.ARC_RIGHT
Tool.ELEMENT:
return Tool.ELEMENT
return Tool.LINE
@ -739,7 +925,7 @@ func _on_direction_pressed(direction: PathSegment.Direction) -> void:
_update_direction_buttons()
var selected := get_selected_segment()
if selected != null:
if selected != null and not selected.is_element_marker():
_record_undo()
selected.direction = direction
_mark_dirty()
@ -752,7 +938,7 @@ func _on_edge_pressed(edge: PathSegment.Edge) -> void:
_update_edge_buttons()
var selected := get_selected_segment()
if selected != null:
if selected != null and not selected.is_element_marker():
_record_undo()
selected.edge = edge
_mark_dirty()
@ -860,7 +1046,17 @@ func _apply_handle_drag(
handle: int,
model_point: Vector2
) -> void:
if segment.curve == null or segment.curve.point_count < 2:
if segment.curve == null:
return
if segment.is_element_marker():
if handle == RinkCanvas.Handle.START or handle == RinkCanvas.Handle.END:
var shifted := _routine.rink.clamp_point(model_point)
segment.curve.clear_points()
segment.curve.add_point(shifted)
return
if segment.curve.point_count < 2:
return
var start := segment.curve.get_point_position(0)
@ -1288,21 +1484,49 @@ func _setup_timing_controls() -> void:
_update_timing_ui()
## Timing controls are meaningless while placing markers and for point
## markers, so they are hidden instead of only disabled. Keeps the bar on one
## row on the tablet in landscape.
func _set_timing_details_visible(visible: bool) -> void:
for control: Control in [
duration_minus_button,
duration_value_label,
duration_plus_button,
speed_minus_button,
speed_value_label,
speed_plus_button,
profile_option,
calibrate_button,
reset_timing_button,
timing_separator_1,
timing_separator_2,
timing_separator_3,
]:
control.visible = visible
func _set_timing_controls_enabled(enabled: bool) -> void:
label_button.disabled = not enabled
element_button.disabled = not enabled
duration_minus_button.disabled = not enabled
duration_plus_button.disabled = not enabled
speed_minus_button.disabled = not enabled
speed_plus_button.disabled = not enabled
calibrate_button.disabled = not enabled
reset_timing_button.disabled = not enabled
profile_option.disabled = not enabled
func _update_timing_ui() -> void:
var selected := get_selected_segment()
_set_timing_details_visible(
_tool != Tool.ELEMENT
and (selected == null or not selected.is_element_marker())
)
if selected == null:
timing_selection_label.text = "Kein Segment ausgewählt"
label_button.tooltip_text = "Beschriftung für das ausgewählte Segment"
element_button.tooltip_text = "Element für das ausgewählte Segment"
duration_value_label.text = "…"
speed_value_label.text = "…"
_set_timing_controls_enabled(false)
@ -1316,7 +1540,38 @@ func _update_timing_ui() -> void:
if not label_text.is_empty()
else "Beschriftung für das ausgewählte Segment"
)
if selected.is_element_marker():
element_button.tooltip_text = "Element bearbeiten: %s" % (
selected.get_element_caption()
)
timing_selection_label.text = "%s · %s" % [
PathSegment.element_type_name(selected.element_type),
selected.get_element_caption(),
]
duration_value_label.text = "–"
speed_value_label.text = "–"
# A point marker has no distance and no duration of its own.
duration_minus_button.disabled = true
duration_plus_button.disabled = true
speed_minus_button.disabled = true
speed_plus_button.disabled = true
calibrate_button.disabled = true
reset_timing_button.disabled = true
profile_option.disabled = true
return
element_button.tooltip_text = (
"Element bearbeiten: %s" % selected.get_element_caption()
if selected.is_element()
else "Element für das ausgewählte Segment"
)
var kind := "Bogen" if selected.is_arc() else "Linie"
if selected.is_element():
kind = "%s · %s" % [
PathSegment.element_type_name(selected.element_type),
selected.get_element_caption(),
]
timing_selection_label.text = "%s · %s m" % [
kind,
_format_decimal(selected.get_length_m()),
@ -2166,6 +2421,14 @@ func _sync_toolbar_to_selection() -> void:
_edge = selected.edge
_update_direction_buttons()
_update_edge_buttons()
if selected.is_element():
_element_type = selected.element_type
_element_level = selected.element_level
var index := element_type_option.get_item_index(selected.element_type)
if index >= 0:
element_type_option.set_block_signals(true)
element_type_option.select(index)
element_type_option.set_block_signals(false)
func _update_direction_buttons() -> void:
@ -2205,6 +2468,14 @@ func _update_status() -> void:
delete_segment_button.disabled = selected == null
if selected != null:
if selected.is_element_marker():
text += " | Auswahl: %s · %s" % [
PathSegment.element_type_name(selected.element_type),
selected.get_element_caption(),
]
status_label.text = text
return
var direction_word := (
"vorwärts"
if selected.direction == PathSegment.Direction.FORWARD
@ -2233,9 +2504,9 @@ func _update_status() -> void:
status_label.text = text
return
var hint := (
"Tippen: auswählen · Griffe/Buttons: bearbeiten · leere Fläche: pan"
if _tool == Tool.SELECT
else "Links ziehen: zeichnen · Mitte/2 Finger: pan · Rad/Pinch: zoom"
)
var hint := "Links ziehen: zeichnen · Mitte/2 Finger: pan · Rad/Pinch: zoom"
if _tool == Tool.SELECT:
hint = "Tippen: auswählen · Griffe/Buttons: bearbeiten · leere Fläche: pan"
elif _tool == Tool.ELEMENT:
hint = "Tippen: Element setzen · Element-Button: Typ, Kürzel, Level"
status_label.text = "%s | %s" % [text, hint]

View file

@ -18,6 +18,10 @@ const OUTSIDE_COLOR := "#DC2626"
const INSIDE_COLOR := "#2563EB"
const TEXT_COLOR := "#0f172a"
const MUTED_TEXT_COLOR := "#64748b"
const ELEMENT_JUMP_COLOR := "#f59e0b"
const ELEMENT_SPIN_COLOR := "#8b5cf6"
const ELEMENT_SEQUENCE_COLOR := "#10b981"
const ELEMENT_RADIUS := 11.0
static func build(routine: Routine, section_id: String = "") -> String:
@ -139,6 +143,7 @@ static func build(routine: Routine, section_id: String = "") -> String:
]
)
_add_element_markers(lines, sections, scale, center)
_add_segment_labels(lines, sections, scale, center)
_add_section_badges(lines, sections, scale, center)
@ -205,6 +210,88 @@ static func _add_section_badges(
## Point elements (jump, spin, sequence centre) are shapes with a caption,
## matching the canvas rendering. Sequence ranges remain regular polylines.
static func _add_element_markers(
lines: PackedStringArray,
sections: Array[RoutineSection],
scale: float,
center: Vector2
) -> void:
for section: RoutineSection in sections:
for segment: PathSegment in section.segments:
if segment == null or segment.curve == null:
continue
if not segment.is_element_marker() or segment.curve.point_count == 0:
continue
var point := center + segment.curve.get_point_position(0) * scale
var color := _element_color(segment.element_type)
lines.append(
'<g class="element-marker" data-element="%s">'
% _escape(segment.get_element_caption())
)
match segment.element_type:
PathSegment.ElementType.JUMP:
var top := Vector2(point.x, point.y - ELEMENT_RADIUS)
var right := Vector2(point.x + ELEMENT_RADIUS, point.y)
var bottom := Vector2(point.x, point.y + ELEMENT_RADIUS)
var left := Vector2(point.x - ELEMENT_RADIUS, point.y)
lines.append(
'<polygon points="%s" fill="%s" stroke="%s" stroke-width="2"/>'
% [
_points(PackedVector2Array([top, right, bottom, left])),
color,
TEXT_COLOR,
]
)
PathSegment.ElementType.SEQUENCE:
lines.append(
'<rect x="%s" y="%s" width="%s" height="%s" fill="%s" stroke="%s" stroke-width="2"/>'
% [
_n(point.x - ELEMENT_RADIUS),
_n(point.y - ELEMENT_RADIUS),
_n(ELEMENT_RADIUS * 2.0),
_n(ELEMENT_RADIUS * 2.0),
color,
TEXT_COLOR,
]
)
_:
lines.append(
'<circle cx="%s" cy="%s" r="%s" fill="%s" stroke="%s" stroke-width="2"/>'
% [
_n(point.x),
_n(point.y),
_n(ELEMENT_RADIUS),
color,
TEXT_COLOR,
]
)
lines.append(
'<text x="%s" y="%s" font-family="sans-serif" font-size="12" font-weight="bold" fill="%s" stroke="#ffffff" stroke-width="3.5" paint-order="stroke" text-anchor="middle">%s</text>'
% [
_n(point.x),
_n(point.y - ELEMENT_RADIUS - 7.0),
TEXT_COLOR,
_escape(segment.get_element_caption()),
]
)
lines.append("</g>")
static func _element_color(type: PathSegment.ElementType) -> String:
match type:
PathSegment.ElementType.JUMP:
return ELEMENT_JUMP_COLOR
PathSegment.ElementType.SPIN:
return ELEMENT_SPIN_COLOR
PathSegment.ElementType.SEQUENCE:
return ELEMENT_SEQUENCE_COLOR
return MUTED_TEXT_COLOR
## Free-text labels of all drawn segments. A white outline (paint-order:
## stroke) keeps them readable on top of the ice and the path lines.
static func _add_segment_labels(
@ -217,7 +304,11 @@ static func _add_segment_labels(
for segment: PathSegment in section.segments:
if segment == null or segment.curve == null:
continue
if segment.is_element_marker():
continue
var text := segment.label.strip_edges()
if text.is_empty() and segment.is_element():
text = segment.get_element_caption()
if text.is_empty():
continue
var length := segment.curve.get_baked_length()

View file

@ -11,6 +11,7 @@ signal draw_started(model_point: Vector2)
signal draw_updated(model_point: Vector2)
signal draw_finished(model_point: Vector2)
signal draw_cancelled
signal marker_requested(model_point: Vector2)
signal segment_selected(segment_id: String)
signal selection_cleared
signal segment_handle_drag_started(segment_id: String, handle: int)
@ -38,6 +39,13 @@ const BULGE_HANDLE_COLOR := Color("#f59e0b")
const LABEL_TEXT_COLOR := Color("#f8fafc")
const LABEL_BACKGROUND_COLOR := Color(0.043, 0.071, 0.129, 0.86)
const LABEL_BORDER_COLOR := Color(0.31, 0.38, 0.49, 0.9)
const ELEMENT_JUMP_COLOR := Color("#f59e0b")
const ELEMENT_SPIN_COLOR := Color("#8b5cf6")
const ELEMENT_SEQUENCE_COLOR := Color("#10b981")
const ELEMENT_BORDER_COLOR := Color("#0f172a")
const ELEMENT_RADIUS_PX := 9.0
const ELEMENT_CAPTION_FONT_SIZE := 13
const ELEMENT_MARKER_HIT_RADIUS_PX := 24.0
const OUTLINE_ARC_SEGMENTS := 12
const CENTER_CIRCLE_RADIUS_M := 4.5
const CENTER_CIRCLE_SEGMENTS := 64
@ -73,9 +81,11 @@ var _pinch_center: Vector2 = Vector2.ZERO
var _pinch_distance: float = 0.0
var _selection_enabled: bool = false
var _marker_placement_enabled: bool = false
var _selected_segment_id: String = ""
var _handle_drag: Handle = Handle.NONE
var _handle_drag_segment_id: String = ""
var _handle_drag_started: bool = false
var _handle_touch_index: int = -1
var _last_handle_model_point: Vector2 = Vector2.ZERO
@ -167,6 +177,19 @@ func set_selection_enabled(enabled: bool) -> void:
_clear_selection()
## In marker placement mode a single tap drops an element marker instead of
## drawing or selecting.
func set_marker_placement_enabled(enabled: bool) -> void:
_marker_placement_enabled = enabled
if enabled:
_cancel_drawing()
_abort_handle_drag()
func is_marker_placement_enabled() -> bool:
return _marker_placement_enabled
func set_selected_segment(segment_id: String) -> void:
_selected_segment_id = segment_id
queue_redraw()
@ -411,10 +434,130 @@ func _draw_playback_marker() -> void:
func _draw_section(section: RoutineSection, alpha: float) -> void:
var step_px := GHOST_SAMPLE_STEP_PX if alpha < 1.0 else CURVE_SAMPLE_STEP_PX
for segment: PathSegment in section.segments:
if segment != null and segment.curve != null:
if segment == null or segment.curve == null:
continue
if segment.is_element_marker():
_draw_element_marker(
segment,
alpha,
segment.segment_id == _selected_segment_id
)
else:
_draw_segment(segment, alpha, step_px)
## Element markers show a type-specific shape at their point plus a short
## caption. The caption honours the global labels toggle, the shape does not:
## a marker without its shape would be invisible.
func _draw_element_marker(
segment: PathSegment,
alpha: float,
selected: bool = false
) -> void:
if segment.curve == null or segment.curve.point_count == 0:
return
var center := _transform.model_to_screen(segment.curve.get_point_position(0))
var radius := maxf(ELEMENT_RADIUS_PX, 0.28 * _transform.pixels_per_meter)
var fill := _element_color(segment.element_type)
fill.a *= alpha
var border := Color(ELEMENT_BORDER_COLOR, ELEMENT_BORDER_COLOR.a * alpha)
if selected:
draw_circle(center, radius + 5.0, SELECTION_HALO_COLOR)
_draw_element_shape(center, radius, segment.element_type, fill, border)
if not labels_visible:
return
_draw_element_caption(center + Vector2(0.0, -(radius + 14.0)), segment, alpha)
func _draw_element_shape(
center: Vector2,
radius: float,
type: PathSegment.ElementType,
fill: Color,
border: Color
) -> void:
match type:
PathSegment.ElementType.JUMP:
var diamond := PackedVector2Array([
center + Vector2(0.0, -radius),
center + Vector2(radius, 0.0),
center + Vector2(0.0, radius),
center + Vector2(-radius, 0.0),
])
draw_colored_polygon(diamond, fill)
var closed := diamond.duplicate()
closed.append(diamond[0])
draw_polyline(closed, border, 2.0, true)
PathSegment.ElementType.SEQUENCE:
var box := Rect2(
center - Vector2(radius, radius),
Vector2(radius * 2.0, radius * 2.0)
)
draw_rect(box, fill, true)
draw_rect(box, border, false, 2.0)
_:
draw_circle(center, radius, fill)
draw_arc(center, radius, 0.0, TAU, 32, border, 2.0, true)
func _draw_element_caption(
anchor: Vector2,
segment: PathSegment,
alpha: float
) -> void:
var text := segment.get_element_caption()
var font := ThemeDB.fallback_font
var text_size := font.get_string_size(
text,
HORIZONTAL_ALIGNMENT_LEFT,
-1,
ELEMENT_CAPTION_FONT_SIZE
)
var ascent := font.get_ascent(ELEMENT_CAPTION_FONT_SIZE)
var descent := font.get_descent(ELEMENT_CAPTION_FONT_SIZE)
var padding := Vector2(6.0, 2.0)
var box_size := Vector2(
text_size.x + padding.x * 2.0,
ascent + descent + padding.y * 2.0
)
var center := anchor - Vector2(0.0, box_size.y * 0.5)
var background := LABEL_BACKGROUND_COLOR
background.a *= alpha
var border := LABEL_BORDER_COLOR
border.a *= alpha
var box := Rect2(center - box_size * 0.5, box_size)
draw_rect(box, background, true)
draw_rect(box, border, false, 1.0)
var baseline := center.y + (ascent - descent) * 0.5
var text_color := LABEL_TEXT_COLOR
text_color.a *= alpha
draw_string(
font,
Vector2(center.x - text_size.x * 0.5, baseline),
text,
HORIZONTAL_ALIGNMENT_LEFT,
-1,
ELEMENT_CAPTION_FONT_SIZE,
text_color
)
func _element_color(type: PathSegment.ElementType) -> Color:
match type:
PathSegment.ElementType.JUMP:
return ELEMENT_JUMP_COLOR
PathSegment.ElementType.SPIN:
return ELEMENT_SPIN_COLOR
PathSegment.ElementType.SEQUENCE:
return ELEMENT_SEQUENCE_COLOR
return LABEL_BORDER_COLOR
## Free-text labels sit next to the middle of their segment. Only the active
## section (or all sections in presentation mode) is labelled; ghosted
## sections are already too faint for readable text.
@ -422,7 +565,9 @@ func _draw_section_labels(section: RoutineSection) -> void:
for segment: PathSegment in section.segments:
if segment == null or segment.curve == null:
continue
if segment.label.strip_edges().is_empty():
if segment.is_element_marker():
continue
if segment.label.strip_edges().is_empty() and not segment.is_element():
continue
_draw_segment_label(segment, segment.segment_id == _selected_segment_id)
@ -443,6 +588,8 @@ func _draw_segment_label(segment: PathSegment, selected: bool = false) -> void:
var normal := Vector2(-tangent.y, tangent.x).normalized()
var text := segment.label.strip_edges()
if text.is_empty() and segment.is_element():
text = segment.get_element_caption()
var font := ThemeDB.fallback_font
var font_size := 14
var text_size := font.get_string_size(
@ -543,6 +690,14 @@ func _draw_selection_handles() -> void:
if segment == null:
return
if segment.is_element_marker():
if segment.curve != null and segment.curve.point_count > 0:
_draw_handle(
_transform.model_to_screen(segment.curve.get_point_position(0)),
HANDLE_FILL_COLOR
)
return
var points := _sample_segment_screen(segment)
if points.is_empty():
return
@ -752,7 +907,7 @@ func _find_segment_at(screen_point: Vector2) -> PathSegment:
return null
var closest_segment: PathSegment = null
var closest_distance := SEGMENT_HIT_RADIUS_PX
var closest_distance := INF
for segment: PathSegment in active.segments:
if segment == null or segment.curve == null:
continue
@ -760,7 +915,12 @@ func _find_segment_at(screen_point: Vector2) -> PathSegment:
screen_point,
_sample_curve_screen(segment.curve)
)
if distance <= closest_distance:
var limit := (
ELEMENT_MARKER_HIT_RADIUS_PX
if segment.is_element_marker()
else SEGMENT_HIT_RADIUS_PX
)
if distance <= limit and distance < closest_distance:
closest_distance = distance
closest_segment = segment
return closest_segment
@ -791,6 +951,14 @@ func _handle_at(screen_point: Vector2) -> Handle:
if segment == null:
return Handle.NONE
if segment.is_element_marker():
if segment.curve == null or segment.curve.point_count == 0:
return Handle.NONE
var point := _transform.model_to_screen(segment.curve.get_point_position(0))
if screen_point.distance_to(point) <= HANDLE_HIT_RADIUS_PX:
return Handle.START
return Handle.NONE
var points := _sample_curve_screen(segment.curve)
if points.is_empty():
return Handle.NONE
@ -853,7 +1021,11 @@ func _handle_mouse_button(event: InputEventMouseButton) -> void:
accept_event()
MOUSE_BUTTON_LEFT:
if event.pressed:
if _selection_enabled:
if _marker_placement_enabled:
if not _request_marker(event.position):
_panning = true
accept_event()
elif _selection_enabled:
_begin_selection_press(event.position)
accept_event()
elif drawing_enabled and _begin_drawing(event.position):
@ -875,6 +1047,7 @@ func _handle_mouse_button(event: InputEventMouseButton) -> void:
func _handle_mouse_motion(event: InputEventMouseMotion) -> void:
if _handle_drag != Handle.NONE:
_ensure_handle_drag_started()
_last_handle_model_point = _transform.screen_to_model(event.position)
segment_handle_dragged.emit(
_handle_drag_segment_id,
@ -892,8 +1065,8 @@ func _begin_selection_press(screen_point: Vector2) -> void:
if handle != Handle.NONE:
_handle_drag = handle
_handle_drag_segment_id = _selected_segment_id
_handle_drag_started = false
_last_handle_model_point = _transform.screen_to_model(screen_point)
segment_handle_drag_started.emit(_handle_drag_segment_id, handle)
return
var segment := _find_segment_at(screen_point)
@ -909,27 +1082,40 @@ func _finish_handle_drag(screen_point: Vector2) -> void:
if _handle_drag == Handle.NONE:
return
var model_point := _transform.screen_to_model(screen_point)
segment_handle_drag_finished.emit(
_handle_drag_segment_id,
_handle_drag,
model_point
)
if _handle_drag_started:
var model_point := _transform.screen_to_model(screen_point)
segment_handle_drag_finished.emit(
_handle_drag_segment_id,
_handle_drag,
model_point
)
_handle_drag = Handle.NONE
_handle_drag_segment_id = ""
_handle_drag_started = false
## The drag gesture only starts on the first motion. A plain tap on a handle
## therefore neither moves anything nor adds an undo entry.
func _ensure_handle_drag_started() -> void:
if _handle_drag_started:
return
_handle_drag_started = true
segment_handle_drag_started.emit(_handle_drag_segment_id, _handle_drag)
func _abort_handle_drag() -> void:
if _handle_drag == Handle.NONE:
return
segment_handle_drag_finished.emit(
_handle_drag_segment_id,
_handle_drag,
_last_handle_model_point
)
if _handle_drag_started:
segment_handle_drag_finished.emit(
_handle_drag_segment_id,
_handle_drag,
_last_handle_model_point
)
_handle_drag = Handle.NONE
_handle_drag_segment_id = ""
_handle_drag_started = false
func _select_segment(segment: PathSegment) -> void:
@ -958,7 +1144,10 @@ func _handle_screen_touch(event: InputEventScreenTouch) -> void:
_cancel_drawing()
_panning = false
if _selection_enabled:
if _marker_placement_enabled:
if not _request_marker(event.position):
_pan_touch_index = event.index
elif _selection_enabled:
_begin_selection_press(event.position)
if _handle_drag != Handle.NONE:
_handle_touch_index = event.index
@ -1004,6 +1193,7 @@ func _handle_screen_drag(event: InputEventScreenDrag) -> void:
_touch_points[event.index] = event.position
if _handle_drag != Handle.NONE and event.index == _handle_touch_index:
_ensure_handle_drag_started()
_last_handle_model_point = _transform.screen_to_model(event.position)
segment_handle_dragged.emit(
_handle_drag_segment_id,
@ -1020,6 +1210,16 @@ func _handle_screen_drag(event: InputEventScreenDrag) -> void:
accept_event()
## Drops a marker when the tap lands inside the rink. Returns false so the
## caller can fall back to panning.
func _request_marker(screen_point: Vector2) -> bool:
var model_point := _transform.screen_to_model(screen_point)
if _rink == null or not _rink.contains_point(model_point):
return false
marker_requested.emit(model_point)
return true
func _begin_drawing(screen_point: Vector2) -> bool:
var model_point := _transform.screen_to_model(screen_point)
if not _rink.contains_point(model_point):

View file

@ -56,4 +56,11 @@ xvfb-run -a $GODOT --path rinkplanner \
--script res://tests/manual/capture.gd -- 1024 768 /tmp/capture.png
```
Element-Marker visuell prüfen (optional mit `place` oder `dialog`):
```bash
xvfb-run -a $GODOT --path rinkplanner \
--script res://tests/manual/capture_elements.gd -- 1400 876 /tmp/elements.png dialog
```
Exit code `0` means all assertions passed. Failures are printed to stderr.

View file

@ -0,0 +1,95 @@
extends SceneTree
## Manual visual smoke test for element markers.
##
## Usage:
## xvfb-run -a godot --path rinkplanner \
## --script res://tests/manual/capture_elements.gd -- 1400 876 /tmp/elements.png
func _init() -> void:
_capture.call_deferred()
func _capture() -> void:
var args := OS.get_cmdline_user_args()
var width := int(args[0]) if args.size() > 0 else 1400
var height := int(args[1]) if args.size() > 1 else 876
var output := args[2] if args.size() > 2 else "user://capture_elements.png"
var packed := load("res://scenes/whiteboard/whiteboard.tscn") as PackedScene
var controller := packed.instantiate() as WhiteboardController
controller.restore_autosave = false
controller.autosave_enabled = false
root.add_child(controller)
root.size = Vector2i(width, height)
await process_frame
await process_frame
controller.add_segment(
Vector2(-24.0, -10.0),
Vector2(-12.0, -10.0),
PathSegment.Direction.FORWARD,
PathSegment.Edge.OUTSIDE
)
controller.add_segment(
Vector2(-12.0, -10.0),
Vector2(0.0, -4.0),
PathSegment.Direction.FORWARD,
PathSegment.Edge.INSIDE,
WhiteboardController.Tool.ARC_LEFT
)
controller.add_segment(
Vector2(0.0, -4.0),
Vector2(14.0, 4.0),
PathSegment.Direction.BACKWARD,
PathSegment.Edge.OUTSIDE
)
var jump := controller.add_element_marker(
Vector2(-18.0, 2.0),
PathSegment.ElementType.JUMP,
"3Lz",
0
)
controller.add_element_marker(
Vector2(-4.0, 9.0),
PathSegment.ElementType.SPIN,
"CCoSp4",
3
)
controller.add_element_marker(
Vector2(12.0, -8.0),
PathSegment.ElementType.SEQUENCE,
"ChStSq",
2
)
# A sequence range is a normal segment that carries an element type.
var sequence := controller.add_segment(
Vector2(4.0, 12.0),
Vector2(18.0, 12.0),
PathSegment.Direction.FORWARD,
PathSegment.Edge.OUTSIDE
)
controller.select_segment(sequence.segment_id)
controller.set_selected_element(
PathSegment.ElementType.SEQUENCE,
"StSq",
2
)
controller.select_segment(jump.segment_id)
if args.size() > 3 and args[3] == "place":
controller.set_tool(WhiteboardController.Tool.ELEMENT)
elif args.size() > 3 and args[3] == "dialog":
controller.element_button.pressed.emit()
controller.rink_canvas.fit_rink()
controller.rink_canvas.refresh()
await process_frame
await process_frame
await RenderingServer.frame_post_draw
var path := ProjectSettings.globalize_path(output)
root.get_texture().get_image().save_png(path)
print("Saved %s at %dx%d" % [path, width, height])
quit(0)

View file

@ -0,0 +1 @@
uid://c4gybrr5m7y8e

View file

@ -37,6 +37,26 @@ func _run() -> void:
svg.contains('paint-order="stroke"'),
"SVG labels get a white outline"
)
_check(
_count(svg, 'class="element-marker"') == 2,
"SVG contains both element markers"
)
_check(
svg.contains('data-element="3Lz"'),
"SVG names the jump marker"
)
_check(
svg.contains('data-element="CCoSp4 L3"'),
"SVG names the spin marker with its level"
)
_check(
svg.contains(">CCoSp4 L3</text>"),
"SVG draws the element caption"
)
_check(
svg.contains("<polygon points="),
"jump markers are drawn as a diamond"
)
var section_svg := RoutineSvgExporter.build(routine, "section-1")
_check(
@ -51,6 +71,14 @@ func _run() -> void:
not section_svg.contains("Abschnitt 2"),
"section export excludes the other section"
)
_check(
_count(section_svg, 'class="element-marker"') == 1,
"section export keeps its own element marker"
)
_check(
not section_svg.contains('data-element="3Lz"'),
"section export excludes markers of other sections"
)
var scene := WhiteboardScene.instantiate()
var controller := scene as WhiteboardController
@ -107,6 +135,13 @@ func _make_routine() -> Routine:
PathSegment.Edge.OUTSIDE
)
labelled.label = "3Lz & <Spin>"
var spin_marker := _make_marker(
"seg-marker-spin",
Vector2(-5.0, 6.0),
PathSegment.ElementType.SPIN,
"CCoSp4",
3
)
section_one.segments = [
labelled,
_make_segment(
@ -116,6 +151,7 @@ func _make_routine() -> Routine:
PathSegment.Direction.BACKWARD,
PathSegment.Edge.INSIDE
),
spin_marker,
]
var section_two := RoutineSection.new()
@ -133,7 +169,14 @@ func _make_routine() -> Routine:
arc.arc_bulge_left = true
arc.arc_depth_ratio = 0.4
arc.curve = _arc_curve(Vector2(0.0, 0.0), Vector2(10.0, 0.0))
section_two.segments = [arc]
var jump_marker := _make_marker(
"seg-marker-jump",
Vector2(14.0, 5.0),
PathSegment.ElementType.JUMP,
"3Lz",
0
)
section_two.segments = [arc, jump_marker]
routine.sections = [section_one, section_two]
return routine
@ -157,6 +200,22 @@ func _make_segment(
return segment
func _make_marker(
segment_id: String,
position: Vector2,
type: PathSegment.ElementType,
code: String,
level: int
) -> PathSegment:
var marker := PathSegment.new()
marker.segment_id = segment_id
marker.curve = Curve2D.new()
marker.curve.add_point(position)
marker.speed_mps = 4.3
marker.set_element(type, code, level)
return marker
func _arc_curve(from: Vector2, to: Vector2) -> Curve2D:
var curve := Curve2D.new()
var points := ArcGeometry.build_points(

View file

@ -17,6 +17,7 @@ var _failures: PackedStringArray = PackedStringArray()
func _init() -> void:
_test_rink_geometry()
_test_segment_timing()
_test_element_markers()
_test_section_aggregation()
_test_routine_validation()
_finish()
@ -167,6 +168,96 @@ func _test_segment_timing() -> void:
)
func _test_element_markers() -> void:
var jump: PathSegment = PathSegmentModel.new()
jump.segment_id = "seg-jump"
var curve := Curve2D.new()
curve.add_point(Vector2(5.0, 3.0))
jump.curve = curve
jump.duration_seconds = 0.0
jump.speed_mps = 4.3
jump.set_element(PathSegmentModel.ElementType.JUMP, " 3Lz ", 0)
_check(jump.is_marker(), "zero-length element is a marker")
_check(jump.is_element(), "element marker reports an element type")
_check(jump.is_element_marker(), "zero-length element is a point marker")
_check(jump.is_valid(), "zero-length jump marker is valid")
_check(jump.element_code == "3Lz", "element code is trimmed")
_check(
jump.get_element_caption() == "3Lz",
"jump caption is the element code"
)
_check(
PathSegmentModel.element_type_name(PathSegmentModel.ElementType.JUMP) == "Sprung",
"jump type has a German name"
)
var spin: PathSegment = PathSegmentModel.new()
spin.segment_id = "seg-spin"
spin.curve = curve
spin.duration_seconds = 0.0
spin.speed_mps = 4.3
spin.set_element(PathSegmentModel.ElementType.SPIN, "CCoSp4", 3)
_check(
spin.get_element_caption() == "CCoSp4 L3",
"spin caption includes the level"
)
_check(spin.is_valid(), "spin marker with a level is valid")
spin.set_element(PathSegmentModel.ElementType.SPIN, "", 9)
_check(spin.element_level == 4, "level is clamped to the maximum")
_check(
spin.get_element_caption() == "Pirouette L4",
"caption falls back to the type name"
)
spin.set_element(
PathSegmentModel.ElementType.SEQUENCE,
"123456789012345678901234567890",
0
)
_check(
spin.element_code.length() == PathSegmentModel.ELEMENT_CODE_MAX_LENGTH,
"element code is truncated to the maximum length"
)
_check(
spin.get_element_caption() == spin.element_code,
"sequence caption uses the truncated code"
)
spin.set_element(PathSegmentModel.ElementType.NONE, "rest", 3)
_check(
spin.element_type == PathSegmentModel.ElementType.NONE
and spin.element_code.is_empty()
and spin.element_level == 0,
"clearing the element resets code and level"
)
_check(not spin.is_element(), "cleared segment is not an element")
var missing_type: PathSegment = PathSegmentModel.new()
missing_type.segment_id = "seg-code-only"
missing_type.curve = _make_curve(Vector2(0.0, 0.0), Vector2(1.0, 0.0))
missing_type.duration_seconds = 1.0
missing_type.element_code = "3Lz"
_check(
not missing_type.is_valid(),
"element code without an element type is invalid"
)
var plain: PathSegment = _make_segment(
"seg-plain",
1.0,
Vector2(0.0, 0.0),
Vector2(1.0, 0.0)
)
_check(not plain.is_element(), "plain segment has no element")
_check(not plain.is_element_marker(), "plain segment is not a point marker")
_check(
plain.get_element_caption() == "Element",
"plain segment caption falls back to the generic name"
)
func _test_section_aggregation() -> void:
var section: RoutineSection = RoutineSectionModel.new()
section.section_id = "section-steps"

View file

@ -83,6 +83,49 @@ func _run() -> void:
"synthetic mouse after touch is ignored"
)
# Element tool: a single tap drops a marker, a drag still pans.
controller.set_tool(WhiteboardController.Tool.ELEMENT)
var count_before_marker := section.segments.size()
var marker_screen := view.model_to_screen(Vector2(6.0, 6.0))
_touch(canvas, 0, marker_screen, true)
_touch(canvas, 0, marker_screen, false)
_check(
section.segments.size() == count_before_marker + 1,
"one tap places an element marker"
)
var placed_marker := section.segments[section.segments.size() - 1]
_check(
placed_marker.is_element_marker(),
"tapped marker is a zero-length element"
)
_check(
controller.get_selected_segment() == placed_marker,
"placed marker is selected for the inspector"
)
controller.set_tool(WhiteboardController.Tool.SELECT)
controller.clear_selection()
_check(
controller.get_selected_segment() == null,
"selection can be cleared before tapping"
)
var undo_before := controller.undo_button.disabled
_touch(canvas, 0, marker_screen, true)
_touch(canvas, 0, marker_screen, false)
_check(
controller.get_selected_segment() == placed_marker,
"tapping the marker selects it"
)
_check_vec(
placed_marker.curve.get_point_position(0),
Vector2(6.0, 6.0),
"tapping the marker does not move it"
)
_check(
controller.undo_button.disabled == undo_before,
"tapping a marker leaves the undo button state alone"
)
# Two-finger pan.
controller.set_tool(WhiteboardController.Tool.SELECT)
var count_before_pan := section.segments.size()

View file

@ -619,6 +619,214 @@ func _run() -> void:
controller.set_selected_segment_label("Eingang")
var saved_label := controller.get_selected_segment_label()
# Element markers (D3): a jump point/spin centre is a zero-length segment.
controller.set_tool(WhiteboardController.Tool.ELEMENT)
_check(
canvas.is_marker_placement_enabled(),
"element tool enables marker placement"
)
var marker_count_before := section.segments.size()
var jump_point := Vector2(14.0, 7.0)
_mouse_button(canvas, view.model_to_screen(jump_point), true)
_mouse_button(canvas, view.model_to_screen(jump_point), false)
var jump := controller.get_selected_segment()
_check(
section.segments.size() == marker_count_before + 1,
"tap in element mode adds a marker"
)
_check(jump != null and jump.is_element_marker(), "placed marker is a point marker")
if jump != null:
_check_approx(jump.get_length_m(), 0.0, "marker has no length")
_check_approx(jump.duration_seconds, 0.0, "marker has no duration")
_check(
jump.element_type == PathSegment.ElementType.JUMP,
"default marker type is a jump"
)
_check(
jump.get_element_caption() == "Sprung",
"marker falls back to the type name"
)
_check(
controller.status_label.text.contains("Sprung"),
"status bar names the placed element"
)
_check_approx(
controller.get_playback_duration(),
routine.get_duration_seconds(),
"markers do not add playback time"
)
# A tap on the selected marker handle must not record an undo entry:
# undo has to remove the marker itself.
var jump_id := jump.segment_id
controller.set_tool(WhiteboardController.Tool.SELECT)
controller.select_segment(jump_id)
var marker_tap := view.model_to_screen(jump_point)
_mouse_button(canvas, marker_tap, true)
_mouse_button(canvas, marker_tap, false)
_check(controller.undo(), "tap on a marker handle is undoable")
section = controller.get_active_section()
_check(
section.get_segment_by_id(jump_id) == null,
"a plain tap adds no undo entry, so undo removes the marker"
)
_check(controller.redo(), "marker placement can be redone")
section = controller.get_active_section()
jump = section.get_segment_by_id(jump_id)
_check(jump != null, "redo restores the placed marker")
controller.set_tool(WhiteboardController.Tool.ELEMENT)
controller.set_element_type(PathSegment.ElementType.SPIN)
_check(
controller.get_element_type() == PathSegment.ElementType.SPIN,
"element type can be selected for placement"
)
var spin_point := Vector2(6.0, -6.0)
_mouse_button(canvas, view.model_to_screen(spin_point), true)
_mouse_button(canvas, view.model_to_screen(spin_point), false)
var spin := controller.get_selected_segment()
_check(
spin != null and spin.element_type == PathSegment.ElementType.SPIN,
"toolbar type is used for the next marker"
)
_check(
controller.set_selected_element(
PathSegment.ElementType.SPIN,
"CCoSp4",
3
),
"element code and level can be edited"
)
_check(
spin.get_element_caption() == "CCoSp4 L3",
"marker caption includes code and level"
)
_check(controller.undo(), "element edit can be undone")
var restored_spin := controller.get_active_section().get_segment_by_id(
spin.segment_id
)
_check(
restored_spin != null
and restored_spin.element_code.is_empty()
and restored_spin.element_level == 0,
"undo restores the previous element data"
)
_check(controller.redo(), "element edit can be redone")
spin = controller.get_active_section().get_segment_by_id(spin.segment_id)
_check(
spin != null and spin.get_element_caption() == "CCoSp4 L3",
"redo restores the element data"
)
# Element inspector dialog.
controller.select_segment(spin.segment_id)
controller.element_button.pressed.emit()
_check(controller.element_dialog.visible, "element button opens the dialog")
_check(
controller.element_code_edit.text == "CCoSp4",
"element dialog is prefilled with the code"
)
controller.element_code_edit.text = "CCoSp3"
controller.element_level_option.select(
controller.element_level_option.get_item_index(2)
)
controller.element_dialog.confirmed.emit()
_check(
controller.get_selected_element_caption() == "CCoSp3 L2",
"element dialog applies code and level"
)
controller.element_dialog.hide()
# Dragging the marker handle moves the point.
controller.set_tool(WhiteboardController.Tool.SELECT)
controller.select_segment(spin.segment_id)
var moved_to := Vector2(4.0, -3.0)
var marker_screen := view.model_to_screen(spin_point)
var marker_target := view.model_to_screen(moved_to)
_mouse_button(canvas, marker_screen, true)
_mouse_motion(canvas, marker_target, marker_target - marker_screen)
_mouse_button(canvas, marker_target, false)
_check_vec(
spin.curve.get_point_position(0),
moved_to,
"dragging the marker handle moves the element"
)
_check(controller.undo(), "marker drag can be undone")
var unmoved := controller.get_active_section().get_segment_by_id(spin.segment_id)
_check(
unmoved != null and unmoved.curve.point_count == 1,
"undo keeps the marker a single point"
)
_check_vec(
unmoved.curve.get_point_position(0),
spin_point,
"undo restores the marker position"
)
_check(controller.redo(), "marker drag can be redone")
# Deleting through the inspector: a marker without an element is removed.
controller.select_segment(spin.segment_id)
controller.set_selected_element(PathSegment.ElementType.NONE, "", 0)
_check(
controller.get_active_section().get_segment_by_id(spin.segment_id) == null,
"removing the element deletes the point marker"
)
_check(
controller.get_selected_segment() == null,
"deleting the marker clears the selection"
)
_check(controller.undo(), "marker deletion can be undone")
spin = controller.get_active_section().get_segment_by_id(spin.segment_id)
_check(
spin != null and spin.is_element_marker(),
"undo restores the deleted marker"
)
# A drawn segment can be tagged as a sequence range and untagged again.
var range_segment := controller.add_segment(
Vector2(-2.0, 11.0),
Vector2(10.0, 11.0),
PathSegment.Direction.FORWARD,
PathSegment.Edge.OUTSIDE
)
controller.select_segment(range_segment.segment_id)
_check(
controller.set_selected_element(
PathSegment.ElementType.SEQUENCE,
"StSq",
2
),
"a drawn segment can carry a sequence element"
)
_check(
controller.get_selected_element_caption() == "StSq L2",
"sequence range caption combines code and level"
)
_check(
controller.set_selected_element(PathSegment.ElementType.NONE, "", 0),
"the element tag can be removed from a range"
)
var untagged := controller.get_active_section().get_segment_by_id(
range_segment.segment_id
)
_check(
untagged != null and untagged.get_length_m() > 0.0,
"removing the tag keeps the drawn path"
)
_check(
not untagged.is_element(),
"removed range is no longer an element"
)
_check(
controller.get_element_type() != PathSegment.ElementType.NONE,
"removing a tag keeps a usable placement type"
)
controller.set_tool(WhiteboardController.Tool.LINE)
var saved_marker_id: String = jump.segment_id
# Save/load round-trip.
var roundtrip_path := "user://test_roundtrip.tres"
var saved_section_title := controller.get_active_section().title
@ -679,6 +887,25 @@ func _run() -> void:
"load restores the segment label"
)
var loaded_marker := controller.get_active_section().get_segment_by_id(
saved_marker_id
)
_check(loaded_marker != null, "load restores element markers")
if loaded_marker != null:
_check(loaded_marker.is_element_marker(), "loaded marker stays a point marker")
_check(
loaded_marker.element_type == PathSegment.ElementType.JUMP,
"load restores the element type"
)
_check(
loaded_marker.get_element_caption() == "Sprung",
"load restores the element caption"
)
_check(
loaded_marker.curve.point_count == 1,
"load keeps the marker curve as a single point"
)
DirAccess.remove_absolute(roundtrip_path)
var too_new_path := "user://test_too_new.tres"