feat: add step-sequence groups, freehand editing and element PDF
- group contiguous path segments into one sequence element with shared group IDs - resolve elements centrally and score/adult-count groups once - add freehand tool with point editing, smoothing and RDP reduction - render one PDF table row and badge per element instead of per segment - turn playback start/pause/reset into icon buttons - add multi-select grouping and extend tests/documentation
This commit is contained in:
parent
e9d520459e
commit
55e7b163b5
33 changed files with 4623 additions and 345 deletions
|
|
@ -31,6 +31,7 @@ func _init() -> void:
|
|||
_test_category_fields()
|
||||
_test_jump_permissions()
|
||||
_test_gold_limits()
|
||||
_test_sequence_group_count()
|
||||
_test_valid_gold()
|
||||
_test_duration_and_repetitions()
|
||||
_test_structured_jump()
|
||||
|
|
@ -146,6 +147,34 @@ func _test_gold_limits() -> void:
|
|||
_check(_has_message(report, "Choreographic Spin"), "choreo spin message")
|
||||
|
||||
|
||||
func _test_sequence_group_count() -> void:
|
||||
var routine := _make_routine("gold")
|
||||
var section := routine.sections[0]
|
||||
for index: int in range(3):
|
||||
var segment: PathSegment = PathSegmentModel.new()
|
||||
segment.segment_id = "seq-%d" % index
|
||||
var curve := Curve2D.new()
|
||||
curve.add_point(Vector2(float(index) * 2.0, 0.0))
|
||||
curve.add_point(Vector2(float(index) * 2.0 + 1.0, 0.0))
|
||||
segment.curve = curve
|
||||
segment.set_speed_mps(4.3)
|
||||
segment.element_group_id = "el-001"
|
||||
if index == 0:
|
||||
segment.set_element(PathSegment.ElementType.SEQUENCE, "StSq", 0)
|
||||
section.segments.append(segment)
|
||||
|
||||
var report := _validator.validate_report(routine)
|
||||
_check(report.element_count == 1, "the sequence group counts as one element")
|
||||
_check(
|
||||
report.get_check("category_sequences").passed,
|
||||
"a multi-segment step sequence stays within the category limit"
|
||||
)
|
||||
_check(
|
||||
not _has_message(report, "Schrittsequenzen: 3"),
|
||||
"the category does not count the group segments separately"
|
||||
)
|
||||
|
||||
|
||||
func _test_valid_gold() -> void:
|
||||
var routine := _make_routine("gold")
|
||||
var section := routine.sections[0]
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ func _run() -> void:
|
|||
svg.contains(">3Lz & <Spin></text>"),
|
||||
"SVG contains and escapes segment labels"
|
||||
)
|
||||
_check(
|
||||
_count(svg, ">3Lz & <Spin></text>") == 1,
|
||||
"SVG draws a sequence group label only once"
|
||||
)
|
||||
_check(
|
||||
svg.contains('paint-order="stroke"'),
|
||||
"SVG labels get a white outline"
|
||||
|
|
@ -161,15 +165,19 @@ func _run() -> void:
|
|||
long_section.title = "Langer Abschnitt"
|
||||
long_section.sequence_order = 2
|
||||
for index: int in range(30):
|
||||
long_section.segments.append(
|
||||
_make_segment(
|
||||
"seg-long-%d" % index,
|
||||
Vector2(-20.0 + float(index) * 0.5, -10.0),
|
||||
Vector2(-19.5 + float(index) * 0.5, -10.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
var long_segment := _make_segment(
|
||||
"seg-long-%d" % index,
|
||||
Vector2(-20.0 + float(index) * 0.5, -10.0),
|
||||
Vector2(-19.5 + float(index) * 0.5, -10.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
long_segment.set_element(
|
||||
PathSegment.ElementType.SEQUENCE,
|
||||
"StSq",
|
||||
0
|
||||
)
|
||||
long_section.segments.append(long_segment)
|
||||
long_routine.sections.append(long_section)
|
||||
var long_pdf := RoutinePdfExporter.build(long_routine, "section-long")
|
||||
_check(
|
||||
|
|
@ -177,6 +185,8 @@ func _run() -> void:
|
|||
"long PDF section continues on a second page"
|
||||
)
|
||||
|
||||
_test_pdf_element_table()
|
||||
|
||||
var scene := WhiteboardScene.instantiate()
|
||||
var controller := scene as WhiteboardController
|
||||
if controller != null:
|
||||
|
|
@ -297,6 +307,60 @@ func _run() -> void:
|
|||
_finish()
|
||||
|
||||
|
||||
func _test_pdf_element_table() -> void:
|
||||
var routine := Routine.new()
|
||||
routine.routine_id = "pdf-element-table"
|
||||
routine.title = "PDF Elemente"
|
||||
routine.rink = RinkDimensions.new()
|
||||
var section := RoutineSection.new()
|
||||
section.section_id = "section-elements"
|
||||
section.title = "Sequenz"
|
||||
section.sequence_order = 0
|
||||
|
||||
var first := _make_segment(
|
||||
"seg-group-1",
|
||||
Vector2(-20.0, 0.0),
|
||||
Vector2(-10.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
first.element_group_id = "el-001"
|
||||
first.set_element(PathSegment.ElementType.SEQUENCE, "StSq", 1)
|
||||
first.label = "Gruppe"
|
||||
var second := _make_segment(
|
||||
"seg-group-2",
|
||||
Vector2(-10.0, 0.0),
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.INSIDE
|
||||
)
|
||||
second.element_group_id = "el-001"
|
||||
var plain := _make_segment(
|
||||
"seg-plain",
|
||||
Vector2(0.0, 0.0),
|
||||
Vector2(10.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
plain.label = "NurPfad"
|
||||
section.segments = [first, second, plain]
|
||||
routine.sections = [section]
|
||||
|
||||
var pdf := RoutinePdfExporter.build(routine, section.section_id)
|
||||
var text := pdf.get_string_from_ascii()
|
||||
_check(text.contains("Gruppe"), "PDF table contains the element label")
|
||||
_check(text.contains("StSq L1"), "PDF table shows the element code")
|
||||
_check(text.contains("2 Teile"), "PDF table shows the sequence part count")
|
||||
_check(
|
||||
_count(text, "Gruppe") == 1,
|
||||
"PDF table has one row per element instead of per segment"
|
||||
)
|
||||
_check(
|
||||
not text.contains("NurPfad"),
|
||||
"free-text labels of plain path segments are not table rows"
|
||||
)
|
||||
|
||||
|
||||
func _make_routine() -> Routine:
|
||||
var routine := Routine.new()
|
||||
routine.routine_id = "export-test"
|
||||
|
|
@ -318,6 +382,16 @@ func _make_routine() -> Routine:
|
|||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
labelled.label = "3Lz & <Spin>"
|
||||
labelled.element_group_id = "el-steps"
|
||||
labelled.set_element(PathSegment.ElementType.SEQUENCE, "StSq", 2)
|
||||
var step_two := _make_segment(
|
||||
"seg-2",
|
||||
Vector2(-10.0, -8.0),
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.Direction.BACKWARD,
|
||||
PathSegment.Edge.INSIDE
|
||||
)
|
||||
step_two.element_group_id = "el-steps"
|
||||
var spin_marker := _make_marker(
|
||||
"seg-marker-spin",
|
||||
Vector2(-5.0, 6.0),
|
||||
|
|
@ -325,17 +399,7 @@ func _make_routine() -> Routine:
|
|||
"CCoSp4",
|
||||
3
|
||||
)
|
||||
section_one.segments = [
|
||||
labelled,
|
||||
_make_segment(
|
||||
"seg-2",
|
||||
Vector2(-10.0, -8.0),
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.Direction.BACKWARD,
|
||||
PathSegment.Edge.INSIDE
|
||||
),
|
||||
spin_marker,
|
||||
]
|
||||
section_one.segments = [labelled, step_two, spin_marker]
|
||||
|
||||
var section_two := RoutineSection.new()
|
||||
section_two.section_id = "section-2"
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ func _test_json_roundtrip() -> void:
|
|||
encoded.contains("\"direction\": \"backward\""),
|
||||
"enums are stored as readable names"
|
||||
)
|
||||
_check(
|
||||
encoded.contains("\"template\": \"freehand\""),
|
||||
"freehand template is stored as a readable name"
|
||||
)
|
||||
|
||||
var result := RoutineFile.decode_json(encoded)
|
||||
_check(str(result["error"]).is_empty(), "encoded JSON decodes without error")
|
||||
|
|
@ -82,7 +86,40 @@ func _test_json_roundtrip() -> void:
|
|||
if section == null:
|
||||
return
|
||||
_check(section.title == "Abschnitt 1", "section title survives")
|
||||
_check(section.segments.size() == 3, "all segments survive")
|
||||
_check(section.segments.size() == 5, "all segments survive")
|
||||
|
||||
var sequence_lead := section.get_segment_by_id("seg-line")
|
||||
var sequence_member := section.get_segment_by_id("seg-sequence-member")
|
||||
_check(
|
||||
sequence_lead != null
|
||||
and sequence_lead.element_group_id == "el-001"
|
||||
and sequence_lead.element_type == PathSegment.ElementType.SEQUENCE,
|
||||
"sequence lead and group id survive"
|
||||
)
|
||||
_check(
|
||||
sequence_member != null
|
||||
and sequence_member.element_group_id == "el-001"
|
||||
and sequence_member.element_type == PathSegment.ElementType.NONE,
|
||||
"sequence member keeps its group id without element data"
|
||||
)
|
||||
_check(
|
||||
section.get_elements().size() == 3,
|
||||
"the loaded group resolves with the other elements"
|
||||
)
|
||||
|
||||
var freehand := section.get_segment_by_id("seg-freehand")
|
||||
_check(freehand != null, "freehand segment survives")
|
||||
if freehand != null:
|
||||
_check(
|
||||
freehand.template == PathSegment.Template.FREEHAND,
|
||||
"freehand template survives"
|
||||
)
|
||||
_check(freehand.curve.point_count == 3, "freehand points survive")
|
||||
_check_vec(
|
||||
freehand.curve.get_point_position(1),
|
||||
Vector2(5.0, -8.0),
|
||||
"freehand interior point survives"
|
||||
)
|
||||
|
||||
var arc := section.get_segment_by_id("seg-arc")
|
||||
_check(arc != null, "arc segment survives")
|
||||
|
|
@ -102,6 +139,11 @@ func _test_json_roundtrip() -> void:
|
|||
arc.element_features == PackedStringArray(["difficult_exit"]),
|
||||
"features survive"
|
||||
)
|
||||
_check_vec(
|
||||
arc.element_jump_vector,
|
||||
Vector2(1.5, 0.5),
|
||||
"jump vector survives"
|
||||
)
|
||||
_check(arc.curve.point_count == 2, "curve points survive")
|
||||
_check_vec(
|
||||
arc.curve.get_point_position(0),
|
||||
|
|
@ -129,6 +171,16 @@ func _test_json_roundtrip() -> void:
|
|||
0.7,
|
||||
"marker stand time survives"
|
||||
)
|
||||
_check_approx(
|
||||
marker.element_revolutions,
|
||||
14.0,
|
||||
"spin revolution count survives"
|
||||
)
|
||||
_check(
|
||||
marker.element_rotation_direction
|
||||
== PathSegment.RotationDirection.CLOCKWISE,
|
||||
"spin rotation direction survives"
|
||||
)
|
||||
|
||||
|
||||
func _test_json_rejects() -> void:
|
||||
|
|
@ -314,6 +366,16 @@ func _make_routine() -> Routine:
|
|||
line.curve.add_point(Vector2(-15.0, 0.0))
|
||||
line.curve.add_point(Vector2(-5.0, 0.0))
|
||||
line.set_speed_mps(4.0)
|
||||
line.element_group_id = "el-001"
|
||||
line.set_element(PathSegment.ElementType.SEQUENCE, "StSq", 0)
|
||||
|
||||
var sequence_member := PathSegment.new()
|
||||
sequence_member.segment_id = "seg-sequence-member"
|
||||
sequence_member.curve = Curve2D.new()
|
||||
sequence_member.curve.add_point(Vector2(-5.0, 0.0))
|
||||
sequence_member.curve.add_point(Vector2(0.0, 0.0))
|
||||
sequence_member.set_speed_mps(4.0)
|
||||
sequence_member.element_group_id = "el-001"
|
||||
|
||||
var arc := PathSegment.new()
|
||||
arc.segment_id = "seg-arc"
|
||||
|
|
@ -343,6 +405,16 @@ func _make_routine() -> Routine:
|
|||
PathSegment.JumpKind.COMBINATION,
|
||||
PackedStringArray(["2T", "2S"])
|
||||
)
|
||||
arc.set_element_jump_vector(Vector2(1.5, 0.5))
|
||||
|
||||
var freehand := PathSegment.new()
|
||||
freehand.segment_id = "seg-freehand"
|
||||
freehand.template = PathSegment.Template.FREEHAND
|
||||
freehand.curve = Curve2D.new()
|
||||
freehand.curve.add_point(Vector2(0.0, -10.0))
|
||||
freehand.curve.add_point(Vector2(5.0, -8.0))
|
||||
freehand.curve.add_point(Vector2(10.0, -11.0))
|
||||
freehand.set_speed_mps(4.0)
|
||||
|
||||
var marker := PathSegment.new()
|
||||
marker.segment_id = "seg-marker"
|
||||
|
|
@ -351,8 +423,10 @@ func _make_routine() -> Routine:
|
|||
marker.speed_mps = 4.0
|
||||
marker.set_element(PathSegment.ElementType.SPIN, "CCoSp4", 4)
|
||||
marker.set_element_duration(0.7)
|
||||
marker.set_element_revolutions(14.0)
|
||||
marker.element_rotation_direction = PathSegment.RotationDirection.CLOCKWISE
|
||||
|
||||
section.segments = [line, arc, marker]
|
||||
section.segments = [line, sequence_member, arc, freehand, marker]
|
||||
routine.sections = [section]
|
||||
return routine
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ func _init() -> void:
|
|||
_test_element_markers()
|
||||
_test_jump_combinations()
|
||||
_test_section_aggregation()
|
||||
_test_element_groups()
|
||||
_test_routine_validation()
|
||||
_finish()
|
||||
|
||||
|
|
@ -192,6 +193,53 @@ func _test_element_markers() -> void:
|
|||
PathSegmentModel.element_type_name(PathSegmentModel.ElementType.JUMP) == "Sprung",
|
||||
"jump type has a German name"
|
||||
)
|
||||
_check_approx(
|
||||
jump.get_jump_revolutions(),
|
||||
3.0,
|
||||
"a 3Lz turns three times in the air"
|
||||
)
|
||||
_check_approx(
|
||||
jump.get_jump_distance_m(),
|
||||
3.0,
|
||||
"jump distance is one metre per revolution"
|
||||
)
|
||||
jump.set_element(PathSegmentModel.ElementType.JUMP, "2A", 0)
|
||||
_check_approx(
|
||||
jump.get_jump_revolutions(),
|
||||
2.5,
|
||||
"an Axel adds half a revolution"
|
||||
)
|
||||
jump.set_element(PathSegmentModel.ElementType.JUMP, "unbekannt", 0)
|
||||
_check_approx(
|
||||
jump.get_jump_revolutions(),
|
||||
1.0,
|
||||
"unknown jump codes fall back to one revolution"
|
||||
)
|
||||
jump.set_element(PathSegmentModel.ElementType.JUMP, "3Lz", 0)
|
||||
_check(jump.has_jump_vector() == false, "new jumps start with an automatic vector")
|
||||
jump.set_element_jump_vector(Vector2(0.0, 2.0))
|
||||
_check(jump.has_jump_vector(), "a dragged tip stores an explicit jump vector")
|
||||
_check_approx(
|
||||
jump.get_jump_distance_m(),
|
||||
2.0,
|
||||
"the explicit vector defines the jump distance"
|
||||
)
|
||||
jump.set_element_jump_vector(Vector2(0.0, 40.0))
|
||||
_check_approx(
|
||||
jump.get_jump_distance_m(),
|
||||
PathSegmentModel.ELEMENT_MAX_JUMP_DISTANCE_M,
|
||||
"the jump vector is clamped to the maximum"
|
||||
)
|
||||
jump.set_element_jump_vector(Vector2.ZERO)
|
||||
_check(not jump.has_jump_vector(), "a zero vector means automatic")
|
||||
_check_approx(
|
||||
jump.get_jump_distance_m(),
|
||||
3.0,
|
||||
"zero vector falls back to the code distance"
|
||||
)
|
||||
jump.set_element(PathSegmentModel.ElementType.SEQUENCE, "StSq", 0)
|
||||
_check(not jump.has_jump_vector(), "a sequence drops the jump vector")
|
||||
jump.set_element(PathSegmentModel.ElementType.JUMP, "3Lz", 0)
|
||||
|
||||
var spin: PathSegment = PathSegmentModel.new()
|
||||
spin.segment_id = "seg-spin"
|
||||
|
|
@ -236,6 +284,53 @@ func _test_element_markers() -> void:
|
|||
)
|
||||
spin.set_element_duration(8.0)
|
||||
|
||||
spin.set_element_revolutions(12.0)
|
||||
_check_approx(
|
||||
spin.get_spin_revolutions_per_second(),
|
||||
1.5,
|
||||
"spin rate is revolutions divided by stand time"
|
||||
)
|
||||
spin.set_element_revolutions(-3.0)
|
||||
_check_approx(
|
||||
spin.element_revolutions,
|
||||
0.0,
|
||||
"negative revolutions are clamped to zero"
|
||||
)
|
||||
spin.element_revolutions = 500.0
|
||||
_check(
|
||||
not spin.is_valid(),
|
||||
"revolutions above the maximum are invalid"
|
||||
)
|
||||
spin.set_element_revolutions(20.0)
|
||||
_check(spin.is_valid(), "a spin with a plausible revolution count is valid")
|
||||
_check(
|
||||
spin.element_rotation_direction == PathSegmentModel.RotationDirection.COUNTERCLOCKWISE,
|
||||
"spins default to counterclockwise"
|
||||
)
|
||||
_check_approx(
|
||||
spin.get_rotation_sign(),
|
||||
-1.0,
|
||||
"counterclockwise spins use negative screen angles"
|
||||
)
|
||||
_check(
|
||||
PathSegmentModel.rotation_direction_name(
|
||||
PathSegmentModel.RotationDirection.COUNTERCLOCKWISE
|
||||
) == "linksherum",
|
||||
"counterclockwise is named linksherum"
|
||||
)
|
||||
spin.element_rotation_direction = PathSegmentModel.RotationDirection.CLOCKWISE
|
||||
_check_approx(
|
||||
spin.get_rotation_sign(),
|
||||
1.0,
|
||||
"clockwise spins use positive screen angles"
|
||||
)
|
||||
_check(
|
||||
PathSegmentModel.rotation_direction_name(
|
||||
PathSegmentModel.RotationDirection.CLOCKWISE
|
||||
) == "rechtsherum",
|
||||
"clockwise is named rechtsherum"
|
||||
)
|
||||
|
||||
spin.set_element(
|
||||
PathSegmentModel.ElementType.SEQUENCE,
|
||||
"123456789012345678901234567890",
|
||||
|
|
@ -249,6 +344,21 @@ func _test_element_markers() -> void:
|
|||
spin.get_element_caption() == spin.element_code,
|
||||
"sequence caption uses the truncated code"
|
||||
)
|
||||
_check_approx(
|
||||
spin.element_revolutions,
|
||||
0.0,
|
||||
"switching to a sequence drops the spin revolutions"
|
||||
)
|
||||
_check_approx(
|
||||
spin.get_spin_revolutions_per_second(),
|
||||
0.0,
|
||||
"a sequence has no rotation rate"
|
||||
)
|
||||
_check(
|
||||
spin.element_rotation_direction
|
||||
== PathSegmentModel.RotationDirection.COUNTERCLOCKWISE,
|
||||
"a sequence drops the spin direction"
|
||||
)
|
||||
|
||||
spin.set_element(PathSegmentModel.ElementType.NONE, "rest", 3)
|
||||
_check(
|
||||
|
|
@ -467,6 +577,112 @@ func _test_section_aggregation() -> void:
|
|||
_check_approx(section.get_length_m(), 10.0, "markers keep the section length")
|
||||
|
||||
|
||||
func _test_element_groups() -> void:
|
||||
var section: RoutineSection = RoutineSectionModel.new()
|
||||
section.section_id = "section-steps"
|
||||
section.sequence_order = 0
|
||||
var first := _make_segment(
|
||||
"seg-steps-1",
|
||||
3.0,
|
||||
Vector2(-5.0, 0.0),
|
||||
Vector2(0.0, 0.0)
|
||||
)
|
||||
var second := _make_segment(
|
||||
"seg-steps-2",
|
||||
2.0,
|
||||
Vector2(0.0, 0.0),
|
||||
Vector2(5.0, 0.0)
|
||||
)
|
||||
var third := _make_segment(
|
||||
"seg-steps-3",
|
||||
1.0,
|
||||
Vector2(5.0, 0.0),
|
||||
Vector2(5.0, 5.0)
|
||||
)
|
||||
first.element_group_id = "el-001"
|
||||
second.element_group_id = "el-001"
|
||||
third.element_group_id = "el-001"
|
||||
first.set_element(PathSegment.ElementType.SEQUENCE, "StSq", 2)
|
||||
section.segments = [first, second, third]
|
||||
|
||||
var elements := section.get_elements()
|
||||
_check(elements.size() == 1, "a sequence group resolves to one element")
|
||||
if not elements.is_empty():
|
||||
var element: ResolvedElement = elements[0]
|
||||
_check(element.get_lead() == first, "the tagged segment is the lead")
|
||||
_check(element.segments.size() == 3, "all member segments are resolved")
|
||||
_check(element.get_type() == PathSegment.ElementType.SEQUENCE, "type is resolved")
|
||||
_check(element.get_code() == "StSq", "code is read from the lead")
|
||||
_check(element.get_level() == 2, "level is read from the lead")
|
||||
_check_approx(
|
||||
element.get_duration_seconds(),
|
||||
6.0,
|
||||
"group duration sums all member segments"
|
||||
)
|
||||
var member_element := section.get_element_for_segment("seg-steps-2")
|
||||
_check(
|
||||
member_element != null
|
||||
and member_element.element_id == element.element_id,
|
||||
"a member segment resolves to its group"
|
||||
)
|
||||
_check(
|
||||
section.get_element_group_segments("el-001").size() == 3,
|
||||
"group segments can be looked up by id"
|
||||
)
|
||||
_check(section.is_valid(), "a well-formed sequence group is valid")
|
||||
|
||||
# Members must stay adjacent and the group needs exactly one lead.
|
||||
var split := section.duplicate(true) as RoutineSection
|
||||
split.segments[1].element_group_id = ""
|
||||
var split_errors := split.validate()
|
||||
_check(
|
||||
_contains_error(split_errors, "split across non-adjacent"),
|
||||
"non-adjacent group members are rejected"
|
||||
)
|
||||
|
||||
var two_leads := section.duplicate(true) as RoutineSection
|
||||
two_leads.segments[1].set_element(
|
||||
PathSegment.ElementType.SEQUENCE,
|
||||
"StSq",
|
||||
2
|
||||
)
|
||||
_check(
|
||||
_contains_error(two_leads.validate(), "exactly one lead"),
|
||||
"a group may have only one lead segment"
|
||||
)
|
||||
|
||||
var wrong_type := section.duplicate(true) as RoutineSection
|
||||
wrong_type.segments[0].set_element(
|
||||
PathSegment.ElementType.SPIN,
|
||||
"CCoSp",
|
||||
0
|
||||
)
|
||||
_check(
|
||||
_contains_error(wrong_type.validate(), "only supported for sequence ranges"),
|
||||
"only sequence ranges may span multiple segments"
|
||||
)
|
||||
|
||||
var no_lead: RoutineSection = RoutineSectionModel.new()
|
||||
no_lead.section_id = "section-steps"
|
||||
no_lead.sequence_order = 0
|
||||
var orphan := _make_segment(
|
||||
"seg-orphan",
|
||||
1.0,
|
||||
Vector2(0.0, 0.0),
|
||||
Vector2(1.0, 0.0)
|
||||
)
|
||||
orphan.element_group_id = "el-orphan"
|
||||
no_lead.segments = [orphan]
|
||||
_check(
|
||||
_contains_error(no_lead.validate(), "needs exactly one lead"),
|
||||
"a group without a lead is rejected"
|
||||
)
|
||||
_check(
|
||||
no_lead.get_elements().is_empty(),
|
||||
"an orphan group resolves to no element"
|
||||
)
|
||||
|
||||
|
||||
func _test_routine_validation() -> void:
|
||||
var routine: Routine = _make_routine()
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ extends SceneTree
|
|||
## godot --headless --path rinkplanner --script res://tests/run_playback_tests.gd
|
||||
|
||||
const WhiteboardScene := preload("res://scenes/whiteboard/whiteboard.tscn")
|
||||
const PLAY_ICON := preload("res://assets/icons/playback/play.svg")
|
||||
const PAUSE_ICON := preload("res://assets/icons/playback/pause.svg")
|
||||
|
||||
var _assertions: int = 0
|
||||
var _failures: PackedStringArray = PackedStringArray()
|
||||
|
|
@ -204,13 +206,13 @@ func _run() -> void:
|
|||
|
||||
controller.play()
|
||||
_check(controller.is_playing(), "play starts playback")
|
||||
_check(controller.play_button.text == "Pause", "play button switches to pause")
|
||||
_check(controller.play_button.icon == PAUSE_ICON, "play button switches to pause")
|
||||
controller.advance_playback(0.5)
|
||||
_check_approx(controller.get_playback_time(), 5.5, "playback advances by delta")
|
||||
controller.advance_playback(1.0)
|
||||
_check(not controller.is_playing(), "playback stops at the end")
|
||||
_check_approx(controller.get_playback_time(), 6.0, "playback ends at the total duration")
|
||||
_check(controller.play_button.text == "Start", "play button switches back after the end")
|
||||
_check(controller.play_button.icon == PLAY_ICON, "play button switches back after the end")
|
||||
|
||||
controller.play()
|
||||
_check_approx(
|
||||
|
|
@ -270,7 +272,7 @@ func _run() -> void:
|
|||
)
|
||||
_check_approx(
|
||||
spin_marker.element_duration_seconds,
|
||||
8.0,
|
||||
4.0,
|
||||
"spin marker gets a default stand time"
|
||||
)
|
||||
var zero_marker := controller.add_element_marker(
|
||||
|
|
@ -287,7 +289,7 @@ func _run() -> void:
|
|||
controller._update_status()
|
||||
_check_approx(
|
||||
controller.get_playback_duration(),
|
||||
14.7,
|
||||
10.7,
|
||||
"timeline duration includes the element stand times"
|
||||
)
|
||||
|
||||
|
|
@ -298,11 +300,47 @@ func _run() -> void:
|
|||
"timeline stops at the jump marker"
|
||||
)
|
||||
var jump_heading := controller.get_playback_heading()
|
||||
var jump_takeoff := controller.get_playback_position()
|
||||
controller.seek_playback(jump_start + 0.35)
|
||||
_check(
|
||||
jump_heading.dot(controller.get_playback_heading()) > 0.99,
|
||||
"jump marker keeps the arrival heading"
|
||||
jump_heading.dot(controller.get_playback_heading()) < -0.9,
|
||||
"jump marker turns half of its air revolutions"
|
||||
)
|
||||
_check(
|
||||
controller.rink_canvas.get_playback_marker_scale() > 1.5,
|
||||
"jump marker grows while the skater is in the air"
|
||||
)
|
||||
var jump_travel := controller.get_playback_position() - jump_takeoff
|
||||
_check_approx(
|
||||
jump_travel.length(),
|
||||
1.5,
|
||||
"jump marker travels half of the jump distance mid-air"
|
||||
)
|
||||
_check(
|
||||
jump_travel.normalized().dot(jump_heading) > 0.99,
|
||||
"jump marker follows the jump vector"
|
||||
)
|
||||
controller.seek_playback(jump_start + 0.699)
|
||||
_check(
|
||||
jump_heading.dot(controller.get_playback_heading()) > 0.99,
|
||||
"the jump ends in the arrival heading after whole revolutions"
|
||||
)
|
||||
|
||||
jump_marker.set_element_jump_vector(Vector2(0.0, 2.0))
|
||||
controller.seek_playback(jump_start)
|
||||
var explicit_takeoff := controller.get_playback_position()
|
||||
controller.seek_playback(jump_start + 0.35)
|
||||
var explicit_travel := controller.get_playback_position() - explicit_takeoff
|
||||
_check_approx(
|
||||
explicit_travel.length(),
|
||||
1.0,
|
||||
"an explicit jump vector defines the travelled distance"
|
||||
)
|
||||
_check(
|
||||
explicit_travel.normalized().dot(Vector2(0.0, 1.0)) > 0.99,
|
||||
"the jump follows the dragged vector direction"
|
||||
)
|
||||
jump_marker.set_element_jump_vector(Vector2.ZERO)
|
||||
|
||||
var spin_start := jump_start + 0.7
|
||||
controller.seek_playback(spin_start)
|
||||
|
|
@ -311,11 +349,51 @@ func _run() -> void:
|
|||
"timeline stops at the spin marker"
|
||||
)
|
||||
var spin_arrival := controller.get_playback_heading()
|
||||
controller.seek_playback(spin_start + 1.0 / 3.0)
|
||||
var spin_turn_seconds := 1.0 / WhiteboardController.SPIN_REVOLUTIONS_PER_SECOND
|
||||
controller.seek_playback(spin_start + spin_turn_seconds * 0.5)
|
||||
_check(
|
||||
spin_arrival.dot(controller.get_playback_heading()) < -0.9,
|
||||
"spin marker rotates the playback dot in place"
|
||||
)
|
||||
controller.seek_playback(spin_start + spin_turn_seconds)
|
||||
_check(
|
||||
spin_arrival.dot(controller.get_playback_heading()) > 0.99,
|
||||
"one spin revolution returns to the arrival heading"
|
||||
)
|
||||
|
||||
# Direction: counterclockwise turns left (negative screen angle), clockwise
|
||||
# turns right.
|
||||
var quarter_turn := spin_turn_seconds * 0.25
|
||||
spin_marker.element_rotation_direction = (
|
||||
PathSegment.RotationDirection.COUNTERCLOCKWISE
|
||||
)
|
||||
controller.seek_playback(spin_start)
|
||||
var ccw_arrival := controller.get_playback_heading()
|
||||
controller.seek_playback(spin_start + quarter_turn)
|
||||
_check(
|
||||
ccw_arrival.cross(controller.get_playback_heading()) < -0.5,
|
||||
"counterclockwise spin turns left"
|
||||
)
|
||||
spin_marker.element_rotation_direction = PathSegment.RotationDirection.CLOCKWISE
|
||||
controller.seek_playback(spin_start)
|
||||
var cw_arrival := controller.get_playback_heading()
|
||||
controller.seek_playback(spin_start + quarter_turn)
|
||||
_check(
|
||||
cw_arrival.cross(controller.get_playback_heading()) > 0.5,
|
||||
"clockwise spin turns right"
|
||||
)
|
||||
|
||||
# The planned revolution count drives the rate: 4 revolutions in 8 s are
|
||||
# 0.5 rev/s, so a half turn takes one second.
|
||||
spin_marker.set_element_revolutions(2.0)
|
||||
controller.seek_playback(spin_start)
|
||||
var slow_spin_arrival := controller.get_playback_heading()
|
||||
controller.seek_playback(spin_start + 1.0)
|
||||
_check(
|
||||
slow_spin_arrival.dot(controller.get_playback_heading()) < -0.9,
|
||||
"planned revolutions scale the spin rotation in playback"
|
||||
)
|
||||
spin_marker.set_element_revolutions(10.0)
|
||||
|
||||
# Timeline labels: element labels are drawn read-only and a click on the
|
||||
# lane creates an editable custom label at that time.
|
||||
|
|
|
|||
|
|
@ -53,6 +53,49 @@ func _run() -> void:
|
|||
var drawn := section.segments[section.segments.size() - 1]
|
||||
_check(drawn.get_length_m() > 9.5, "touch-drawn segment has the drag length")
|
||||
|
||||
# Freehand touch drawing keeps multiple sampled points.
|
||||
controller.set_tool(WhiteboardController.Tool.FREELINE)
|
||||
var freehand_count_before := section.segments.size()
|
||||
var freehand_points: Array[Vector2] = [
|
||||
Vector2(10.0, -8.0),
|
||||
Vector2(14.0, -6.0),
|
||||
Vector2(18.0, -9.0),
|
||||
Vector2(22.0, -7.0),
|
||||
]
|
||||
var previous := view.model_to_screen(freehand_points[0])
|
||||
_touch(canvas, 0, previous, true)
|
||||
for index: int in range(1, freehand_points.size()):
|
||||
var current := view.model_to_screen(freehand_points[index])
|
||||
_drag(canvas, 0, current, current - previous)
|
||||
previous = current
|
||||
_touch(canvas, 0, previous, false)
|
||||
_check(
|
||||
section.segments.size() == freehand_count_before + 1,
|
||||
"touch freehand creates one segment"
|
||||
)
|
||||
var freehand := section.segments[section.segments.size() - 1]
|
||||
_check(freehand.is_freehand(), "touch freehand keeps its template")
|
||||
_check(
|
||||
freehand.curve.point_count >= freehand_points.size(),
|
||||
"touch freehand keeps multiple sampled points"
|
||||
)
|
||||
controller.set_tool(WhiteboardController.Tool.SELECT)
|
||||
controller.select_segment(freehand.segment_id)
|
||||
var interior_index := 2
|
||||
var interior_before := freehand.curve.get_point_position(interior_index)
|
||||
var interior_target := interior_before + Vector2(0.0, 1.5)
|
||||
var interior_screen := view.model_to_screen(interior_before)
|
||||
var target_screen := view.model_to_screen(interior_target)
|
||||
_touch(canvas, 0, interior_screen, true)
|
||||
_drag(canvas, 0, target_screen, target_screen - interior_screen)
|
||||
_touch(canvas, 0, target_screen, false)
|
||||
_check_vec(
|
||||
freehand.curve.get_point_position(interior_index),
|
||||
interior_target,
|
||||
"touch drags a freehand interior point"
|
||||
)
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
|
||||
# Chrome emits a synthetic mouse press immediately before the touch press.
|
||||
# The touch press must cancel that stray mouse segment.
|
||||
canvas._ignore_mouse_until_msec = 0
|
||||
|
|
@ -93,9 +136,11 @@ func _run() -> void:
|
|||
section.segments.size() == count_before_marker + 1,
|
||||
"one tap places an element marker"
|
||||
)
|
||||
var placed_marker := section.segments[section.segments.size() - 1]
|
||||
# The marker is inserted along the path, not necessarily appended, so the
|
||||
# newly selected segment is the marker that was just placed.
|
||||
var placed_marker := controller.get_selected_segment()
|
||||
_check(
|
||||
placed_marker.is_element_marker(),
|
||||
placed_marker != null and placed_marker.is_element_marker(),
|
||||
"tapped marker is a zero-length element"
|
||||
)
|
||||
_check(
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ func _init() -> void:
|
|||
_validator = RoutineValidatorScript.new(_catalog, _rules)
|
||||
|
||||
_test_clean_routine()
|
||||
_test_sequence_group_counts_once()
|
||||
_test_unknown_code()
|
||||
_test_type_mismatch()
|
||||
_test_unavailable_level()
|
||||
|
|
@ -107,6 +108,58 @@ func _test_clean_routine() -> void:
|
|||
)
|
||||
|
||||
|
||||
func _test_sequence_group_counts_once() -> void:
|
||||
var routine := _make_routine()
|
||||
var section := routine.sections[0]
|
||||
var group_id := "el-001"
|
||||
for index: int in range(3):
|
||||
var segment: PathSegment = PathSegmentModel.new()
|
||||
segment.segment_id = "seq-%d" % index
|
||||
var curve := Curve2D.new()
|
||||
curve.add_point(Vector2(0.0, float(index) * 2.0))
|
||||
curve.add_point(Vector2(5.0, float(index) * 2.0))
|
||||
segment.curve = curve
|
||||
segment.set_speed_mps(4.3)
|
||||
segment.element_group_id = group_id
|
||||
if index == 0:
|
||||
segment.set_element(PathSegment.ElementType.SEQUENCE, "StSq", 0)
|
||||
section.segments.append(segment)
|
||||
|
||||
var elements := section.get_elements()
|
||||
_check(elements.size() == 1, "a sequence group resolves to one element")
|
||||
if not elements.is_empty():
|
||||
_check(
|
||||
elements[0].segments.size() == 3,
|
||||
"the resolved sequence keeps all member segments"
|
||||
)
|
||||
_check(
|
||||
elements[0].get_lead() == section.segments[0],
|
||||
"the tagged segment is the sequence lead"
|
||||
)
|
||||
_check_approx(
|
||||
elements[0].get_duration_seconds(),
|
||||
section.segments[0].duration_seconds
|
||||
+ section.segments[1].duration_seconds
|
||||
+ section.segments[2].duration_seconds,
|
||||
"the element duration sums all group segments"
|
||||
)
|
||||
|
||||
var report := _validator.validate_report(routine)
|
||||
_check(report.element_count == 1, "a sequence group counts as one element")
|
||||
_check(report.scored_elements == 1, "the sequence is scored once")
|
||||
_check(report.element_values.size() == 1, "the report keeps one value entry")
|
||||
_check(report.get_check("code").passed == 1, "the sequence code is checked once")
|
||||
_check_approx(
|
||||
report.base_value_total,
|
||||
_catalog.get_base_value(
|
||||
"StSq",
|
||||
0,
|
||||
PathSegment.ElementType.SEQUENCE
|
||||
),
|
||||
"the sequence base value is counted once"
|
||||
)
|
||||
|
||||
|
||||
func _test_unknown_code() -> void:
|
||||
var report := _report_one(
|
||||
PathSegment.ElementType.SPIN,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ func _run() -> void:
|
|||
_finish()
|
||||
return
|
||||
|
||||
_check(
|
||||
controller.get_tool() == WhiteboardController.Tool.SELECT,
|
||||
"the select tool is active at startup"
|
||||
)
|
||||
|
||||
var routine := controller.get_routine()
|
||||
var section := controller.get_active_section()
|
||||
_check(routine != null, "controller owns a routine")
|
||||
|
|
@ -133,6 +138,7 @@ func _run() -> void:
|
|||
|
||||
var view := canvas.get_view_transform()
|
||||
var segment_count_before := section.segments.size()
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
_mouse_button(canvas, view.model_to_screen(Vector2(-15.0, 5.0)), true)
|
||||
_mouse_motion(canvas, view.model_to_screen(Vector2(-5.0, 5.0)))
|
||||
_mouse_button(canvas, view.model_to_screen(Vector2(-5.0, 5.0)), false)
|
||||
|
|
@ -224,6 +230,76 @@ func _run() -> void:
|
|||
controller.get_tool() == WhiteboardController.Tool.ARC_LEFT,
|
||||
"tool can be selected programmatically"
|
||||
)
|
||||
|
||||
# The tool palette is a row of toggle buttons: clicking one switches the
|
||||
# tool and exactly one icon stays highlighted.
|
||||
var tool_buttons: Array[Button] = [
|
||||
controller.get_node("%SelectToolButton"),
|
||||
controller.get_node("%LineToolButton"),
|
||||
controller.get_node("%ArcLeftToolButton"),
|
||||
controller.get_node("%ArcRightToolButton"),
|
||||
controller.get_node("%FreeLineToolButton"),
|
||||
controller.get_node("%JumpToolButton"),
|
||||
controller.get_node("%SpinToolButton"),
|
||||
controller.get_node("%SequenceToolButton"),
|
||||
]
|
||||
var arc_right_button: Button = controller.get_node("%ArcRightToolButton")
|
||||
arc_right_button.pressed.emit()
|
||||
_check(
|
||||
controller.get_tool() == WhiteboardController.Tool.ARC_RIGHT,
|
||||
"clicking a tool icon selects that tool"
|
||||
)
|
||||
controller.set_tool(WhiteboardController.Tool.ARC_LEFT)
|
||||
var highlighted := 0
|
||||
for button: Button in tool_buttons:
|
||||
if button.button_pressed:
|
||||
highlighted += 1
|
||||
_check(
|
||||
highlighted == 1
|
||||
and (controller.get_node("%ArcLeftToolButton") as Button).button_pressed,
|
||||
"exactly the active tool icon is highlighted"
|
||||
)
|
||||
|
||||
# Jump and spin pick a point-marker type and share the element tool.
|
||||
var element_buttons := [
|
||||
["%JumpToolButton", PathSegment.ElementType.JUMP],
|
||||
["%SpinToolButton", PathSegment.ElementType.SPIN],
|
||||
]
|
||||
for entry: Array in element_buttons:
|
||||
var button: Button = controller.get_node(entry[0])
|
||||
button.pressed.emit()
|
||||
_check(
|
||||
controller.get_tool() == WhiteboardController.Tool.ELEMENT
|
||||
and controller.get_element_type() == entry[1],
|
||||
"%s picks its element type" % entry[0]
|
||||
)
|
||||
var pressed_count := 0
|
||||
for candidate: Array in element_buttons:
|
||||
if (controller.get_node(candidate[0]) as Button).button_pressed:
|
||||
pressed_count += 1
|
||||
_check(
|
||||
pressed_count == 1 and button.button_pressed,
|
||||
"%s is the only highlighted element icon" % entry[0]
|
||||
)
|
||||
|
||||
# The sequence icon starts drawing mode instead of placing a point marker.
|
||||
controller.set_tool(WhiteboardController.Tool.ARC_LEFT)
|
||||
var sequence_button: Button = controller.get_node("%SequenceToolButton")
|
||||
sequence_button.pressed.emit()
|
||||
_check(
|
||||
controller.is_sequence_mode()
|
||||
and controller.get_element_type() == PathSegment.ElementType.SEQUENCE,
|
||||
"the sequence icon starts sequence drawing mode"
|
||||
)
|
||||
_check(
|
||||
sequence_button.button_pressed
|
||||
and (controller.get_node("%ArcLeftToolButton") as Button).button_pressed,
|
||||
"sequence mode keeps the current path tool active"
|
||||
)
|
||||
sequence_button.pressed.emit()
|
||||
_check(not controller.is_sequence_mode(), "the sequence icon finishes sequence mode")
|
||||
controller.set_element_type(PathSegment.ElementType.JUMP)
|
||||
controller.set_tool(WhiteboardController.Tool.ARC_LEFT)
|
||||
_mouse_button(canvas, view.model_to_screen(Vector2(-15.0, 5.0)), true)
|
||||
_mouse_motion(canvas, view.model_to_screen(Vector2(-5.0, 5.0)))
|
||||
_mouse_button(canvas, view.model_to_screen(Vector2(-5.0, 5.0)), false)
|
||||
|
|
@ -241,6 +317,97 @@ func _run() -> void:
|
|||
"dragged left arc bulges below its chord"
|
||||
)
|
||||
|
||||
# Freehand tool: the drag path is sampled into a multi-point curve.
|
||||
var freehand_count_before := section.segments.size()
|
||||
controller.set_tool(WhiteboardController.Tool.FREELINE)
|
||||
var freehand_path: Array[Vector2] = [
|
||||
Vector2(-26.0, 6.0),
|
||||
Vector2(-22.0, 8.0),
|
||||
Vector2(-18.0, 6.0),
|
||||
Vector2(-14.0, 8.0),
|
||||
Vector2(-12.0, 6.0),
|
||||
]
|
||||
_mouse_button(
|
||||
canvas,
|
||||
view.model_to_screen(freehand_path[0]),
|
||||
true
|
||||
)
|
||||
for index: int in range(1, freehand_path.size()):
|
||||
_mouse_motion(canvas, view.model_to_screen(freehand_path[index]))
|
||||
_mouse_button(
|
||||
canvas,
|
||||
view.model_to_screen(freehand_path[freehand_path.size() - 1]),
|
||||
false
|
||||
)
|
||||
_check(
|
||||
section.segments.size() == freehand_count_before + 1,
|
||||
"freehand mode creates a segment"
|
||||
)
|
||||
var freehand := section.segments[section.segments.size() - 1]
|
||||
_check(freehand.is_freehand(), "freehand path keeps its template")
|
||||
_check(
|
||||
freehand.curve.point_count == freehand_path.size(),
|
||||
"freehand path keeps the sampled points"
|
||||
)
|
||||
_check(
|
||||
freehand.get_length_m() > 10.0,
|
||||
"freehand length follows the drawn path"
|
||||
)
|
||||
_check(
|
||||
freehand.duration_seconds > 0.0,
|
||||
"freehand duration is derived from the path length"
|
||||
)
|
||||
_check(not freehand.is_marker(), "freehand is a path segment, not a marker")
|
||||
|
||||
# Endpoint handles reshape the curve without collapsing it to a line.
|
||||
controller.set_tool(WhiteboardController.Tool.SELECT)
|
||||
controller.select_segment(freehand.segment_id)
|
||||
var freehand_start := freehand.curve.get_point_position(0)
|
||||
controller._apply_handle_drag(
|
||||
freehand,
|
||||
RinkCanvas.Handle.START,
|
||||
freehand_start + Vector2(1.0, 0.5)
|
||||
)
|
||||
_check(
|
||||
freehand.curve.point_count == freehand_path.size(),
|
||||
"freehand handle drag keeps all sampled points"
|
||||
)
|
||||
_check_vec(
|
||||
freehand.curve.get_point_position(0),
|
||||
freehand_start + Vector2(1.0, 0.5),
|
||||
"freehand start handle moves the first point"
|
||||
)
|
||||
|
||||
# Interior freehand points get their own small handles.
|
||||
var interior_index := 2
|
||||
var interior_before := freehand.curve.get_point_position(interior_index)
|
||||
var interior_target := interior_before + Vector2(0.0, 1.5)
|
||||
_mouse_button(
|
||||
canvas,
|
||||
view.model_to_screen(interior_before),
|
||||
true
|
||||
)
|
||||
_mouse_motion(canvas, view.model_to_screen(interior_target))
|
||||
_mouse_button(
|
||||
canvas,
|
||||
view.model_to_screen(interior_target),
|
||||
false
|
||||
)
|
||||
_check(
|
||||
freehand.curve.point_count == freehand_path.size(),
|
||||
"freehand point drag keeps the sampled points"
|
||||
)
|
||||
_check_vec(
|
||||
freehand.curve.get_point_position(interior_index),
|
||||
interior_target,
|
||||
"freehand interior point can be dragged"
|
||||
)
|
||||
_check_vec(
|
||||
freehand.curve.get_point_position(0),
|
||||
freehand_start + Vector2(1.0, 0.5),
|
||||
"dragging one freehand point leaves the others alone"
|
||||
)
|
||||
|
||||
# Selection and handle editing.
|
||||
controller.set_tool(WhiteboardController.Tool.SELECT)
|
||||
var apex_before := arc_left.curve.sample_baked(arc_left.get_length_m() * 0.5)
|
||||
|
|
@ -621,6 +788,7 @@ func _run() -> void:
|
|||
|
||||
# Element markers (D3): a jump point/spin centre is a zero-length segment.
|
||||
controller.set_tool(WhiteboardController.Tool.ELEMENT)
|
||||
controller.set_element_type(PathSegment.ElementType.JUMP)
|
||||
_check(
|
||||
canvas.is_marker_placement_enabled(),
|
||||
"element tool enables marker placement"
|
||||
|
|
@ -661,6 +829,15 @@ func _run() -> void:
|
|||
controller.status_label.text.contains("Sprung"),
|
||||
"status bar names the placed element"
|
||||
)
|
||||
_check_approx(
|
||||
jump.get_jump_distance_m(),
|
||||
1.0,
|
||||
"a jump without a code gets a one metre vector"
|
||||
)
|
||||
_check(
|
||||
controller.status_label.text.contains("1,0 m"),
|
||||
"status bar shows the jump distance"
|
||||
)
|
||||
_check_approx(
|
||||
controller.get_playback_duration(),
|
||||
controller.get_routine().get_duration_seconds(),
|
||||
|
|
@ -672,6 +849,39 @@ func _run() -> void:
|
|||
"routine duration includes the jump air time"
|
||||
)
|
||||
|
||||
controller.element_button.pressed.emit()
|
||||
_check(
|
||||
controller.element_rotation_box.visible,
|
||||
"jump dialog shows the rotation direction"
|
||||
)
|
||||
_check(
|
||||
not controller.element_revolutions_box.visible,
|
||||
"jump dialog hides the spin revolution field"
|
||||
)
|
||||
controller.element_dialog.hide()
|
||||
|
||||
# Dragging the arrow tip stores an explicit jump vector (direction and
|
||||
# distance) instead of the code-derived default.
|
||||
controller._apply_handle_drag(
|
||||
jump,
|
||||
RinkCanvas.Handle.JUMP_TIP,
|
||||
jump_point + Vector2(0.0, 2.0)
|
||||
)
|
||||
_check(
|
||||
jump.element_jump_vector.is_equal_approx(Vector2(0.0, 2.0)),
|
||||
"jump tip drag stores the vector"
|
||||
)
|
||||
_check_approx(
|
||||
jump.get_jump_distance_m(),
|
||||
2.0,
|
||||
"jump tip drag updates the distance"
|
||||
)
|
||||
_check(
|
||||
canvas._handle_at(view.model_to_screen(jump_point + Vector2(0.0, 2.0)))
|
||||
== RinkCanvas.Handle.JUMP_TIP,
|
||||
"the arrow tip is a drag handle"
|
||||
)
|
||||
|
||||
# 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
|
||||
|
|
@ -707,9 +917,24 @@ func _run() -> void:
|
|||
)
|
||||
_check_approx(
|
||||
spin.element_duration_seconds,
|
||||
8.0,
|
||||
4.0,
|
||||
"spin gets the default stand time"
|
||||
)
|
||||
_check_approx(
|
||||
spin.element_revolutions,
|
||||
10.0,
|
||||
"spin starts with the ISU combination minimum"
|
||||
)
|
||||
_check_approx(
|
||||
spin.get_spin_revolutions_per_second(),
|
||||
2.5,
|
||||
"default spin rotates with 2.5 revolutions per second"
|
||||
)
|
||||
_check(
|
||||
spin.element_rotation_direction
|
||||
== PathSegment.RotationDirection.COUNTERCLOCKWISE,
|
||||
"new spins rotate counterclockwise by default"
|
||||
)
|
||||
|
||||
_check(
|
||||
controller.set_selected_element(
|
||||
|
|
@ -729,7 +954,7 @@ func _run() -> void:
|
|||
)
|
||||
_check_approx(
|
||||
spin.element_duration_seconds,
|
||||
8.0,
|
||||
4.0,
|
||||
"editing code keeps the stand time"
|
||||
)
|
||||
_check(controller.undo(), "element edit can be undone")
|
||||
|
|
@ -772,6 +997,25 @@ func _run() -> void:
|
|||
controller.select_segment(spin.segment_id)
|
||||
controller.element_button.pressed.emit()
|
||||
_check(controller.element_dialog.visible, "element button opens the dialog")
|
||||
_check(
|
||||
controller.element_revolutions_box.visible,
|
||||
"spin dialog shows the revolution field"
|
||||
)
|
||||
_check(
|
||||
controller.element_rotation_box.visible,
|
||||
"spin dialog shows the rotation direction"
|
||||
)
|
||||
_check(
|
||||
controller.element_rotation_option.get_item_id(
|
||||
controller.element_rotation_option.selected
|
||||
) == PathSegment.RotationDirection.COUNTERCLOCKWISE,
|
||||
"spin dialog defaults to counterclockwise"
|
||||
)
|
||||
_check_approx(
|
||||
controller.element_revolutions_spin.value,
|
||||
10.0,
|
||||
"spin dialog starts with the default revolution count"
|
||||
)
|
||||
_check(
|
||||
controller.element_code_edit.text == "CCoSp",
|
||||
"element dialog is prefilled with the normalized code"
|
||||
|
|
@ -903,6 +1147,15 @@ func _run() -> void:
|
|||
)
|
||||
|
||||
controller.element_duration_spin.value = 6.5
|
||||
controller.element_revolutions_spin.value = 12.0
|
||||
var clockwise_index := controller.element_rotation_option.get_item_index(
|
||||
PathSegment.RotationDirection.CLOCKWISE
|
||||
)
|
||||
controller.element_rotation_option.select(clockwise_index)
|
||||
_check(
|
||||
controller.element_revolutions_label.text.contains("1,8 U/s"),
|
||||
"dialog shows the rate derived from revolutions and stand time"
|
||||
)
|
||||
controller.element_dialog.confirmed.emit()
|
||||
_check(
|
||||
controller.get_selected_element_caption() == "CCoSp L3",
|
||||
|
|
@ -917,6 +1170,21 @@ func _run() -> void:
|
|||
6.5,
|
||||
"element dialog applies the stand time"
|
||||
)
|
||||
_check_approx(
|
||||
controller.get_selected_segment().element_revolutions,
|
||||
12.0,
|
||||
"element dialog applies the revolution count"
|
||||
)
|
||||
_check_approx(
|
||||
controller.get_selected_segment().get_spin_revolutions_per_second(),
|
||||
12.0 / 6.5,
|
||||
"the spin rate follows revolutions per stand time"
|
||||
)
|
||||
_check(
|
||||
controller.get_selected_segment().element_rotation_direction
|
||||
== PathSegment.RotationDirection.CLOCKWISE,
|
||||
"element dialog applies the rotation direction"
|
||||
)
|
||||
|
||||
_check(controller.undo(), "element dialog change can be undone")
|
||||
spin = controller.get_active_section().get_segment_by_id(spin.segment_id)
|
||||
|
|
@ -924,6 +1192,16 @@ func _run() -> void:
|
|||
spin != null and spin.element_features.size() == 2 and spin.element_level == 2,
|
||||
"undo restores features and the derived level"
|
||||
)
|
||||
_check_approx(
|
||||
spin.element_revolutions,
|
||||
10.0,
|
||||
"undo restores the previous revolution count"
|
||||
)
|
||||
_check(
|
||||
spin.element_rotation_direction
|
||||
== PathSegment.RotationDirection.COUNTERCLOCKWISE,
|
||||
"undo restores the previous rotation direction"
|
||||
)
|
||||
controller.select_segment(spin.segment_id)
|
||||
_check(controller.redo(), "element dialog change can be redone")
|
||||
spin = controller.get_active_section().get_segment_by_id(spin.segment_id)
|
||||
|
|
@ -1619,6 +1897,594 @@ func _run() -> void:
|
|||
if FileAccess.file_exists(path):
|
||||
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
|
||||
|
||||
# Element markers take their chronological position from the drawn path:
|
||||
# taps at the start or between segments insert instead of appending.
|
||||
controller.new_routine()
|
||||
var insert_section := controller.get_active_section()
|
||||
var first_path := controller.add_segment(
|
||||
Vector2(-20.0, 0.0),
|
||||
Vector2(-10.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
var second_path := controller.add_segment(
|
||||
Vector2(-10.0, 0.0),
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
var start_marker := controller.add_element_marker(
|
||||
Vector2(-19.5, 0.0),
|
||||
PathSegment.ElementType.JUMP,
|
||||
"1T",
|
||||
0
|
||||
)
|
||||
_check(
|
||||
insert_section.segments.find(start_marker) == 0,
|
||||
"a tap at the path start inserts the marker at the beginning"
|
||||
)
|
||||
var middle_marker := controller.add_element_marker(
|
||||
Vector2(-10.0, 0.0),
|
||||
PathSegment.ElementType.SPIN,
|
||||
"CCoSp",
|
||||
0
|
||||
)
|
||||
_check(
|
||||
insert_section.segments.find(middle_marker) == 2,
|
||||
"a tap between two segments inserts the marker there"
|
||||
)
|
||||
_check(
|
||||
insert_section.segments.find(first_path)
|
||||
< insert_section.segments.find(middle_marker)
|
||||
and insert_section.segments.find(middle_marker)
|
||||
< insert_section.segments.find(second_path),
|
||||
"the inserted marker keeps the path order"
|
||||
)
|
||||
var end_marker := controller.add_element_marker(
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.ElementType.SEQUENCE,
|
||||
"StSq",
|
||||
0
|
||||
)
|
||||
_check(
|
||||
insert_section.segments.find(end_marker)
|
||||
== insert_section.segments.size() - 1,
|
||||
"a tap behind the last segment appends the marker"
|
||||
)
|
||||
|
||||
# Sequence drawing mode: consecutive drags become one sequence range.
|
||||
controller.new_routine()
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
var sequence_view := canvas.get_view_transform()
|
||||
var range_sequence_button: Button = controller.get_node("%SequenceToolButton")
|
||||
range_sequence_button.pressed.emit()
|
||||
_check(controller.is_sequence_mode(), "sequence drawing mode can be started")
|
||||
var sequence_section := controller.get_active_section()
|
||||
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
_mouse_button(canvas, sequence_view.model_to_screen(Vector2(-15.0, 0.0)), true)
|
||||
_mouse_motion(canvas, sequence_view.model_to_screen(Vector2(-5.0, 0.0)))
|
||||
_mouse_button(canvas, sequence_view.model_to_screen(Vector2(-5.0, 0.0)), false)
|
||||
_mouse_button(canvas, sequence_view.model_to_screen(Vector2(-5.0, 0.0)), true)
|
||||
_mouse_motion(canvas, sequence_view.model_to_screen(Vector2(5.0, 0.0)))
|
||||
_mouse_button(canvas, sequence_view.model_to_screen(Vector2(5.0, 0.0)), false)
|
||||
|
||||
var sequence_elements := sequence_section.get_elements()
|
||||
_check(
|
||||
sequence_elements.size() == 1,
|
||||
"two drawn segments resolve to one sequence element"
|
||||
)
|
||||
if sequence_elements.size() == 1:
|
||||
var sequence_element: ResolvedElement = sequence_elements[0]
|
||||
_check(
|
||||
sequence_element.segments.size() == 2,
|
||||
"the sequence group contains both drawn segments"
|
||||
)
|
||||
_check(
|
||||
sequence_element.get_lead() == sequence_section.segments[0],
|
||||
"the first drawn segment is the sequence lead"
|
||||
)
|
||||
_check(
|
||||
sequence_element.get_code() == "StSq",
|
||||
"a new sequence starts with the StSq code"
|
||||
)
|
||||
_check(
|
||||
sequence_element.is_sequence_range(),
|
||||
"the drawn group is a sequence range, not a point marker"
|
||||
)
|
||||
_check(
|
||||
controller.timeline_label_lane.get_element_label_count() == 1,
|
||||
"the sequence group shows one timeline label"
|
||||
)
|
||||
|
||||
# Finish the group, then continue it from a member at the section tail.
|
||||
range_sequence_button.pressed.emit()
|
||||
_check(not controller.is_sequence_mode(), "the sequence button finishes the group")
|
||||
var tail_member := sequence_section.segments[1]
|
||||
controller.select_segment(tail_member.segment_id)
|
||||
range_sequence_button.pressed.emit()
|
||||
_check(
|
||||
controller.is_sequence_mode(),
|
||||
"sequence mode continues a group that ends at the section tail"
|
||||
)
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
_mouse_button(canvas, sequence_view.model_to_screen(Vector2(-15.0, 5.0)), true)
|
||||
_mouse_motion(canvas, sequence_view.model_to_screen(Vector2(-5.0, 5.0)))
|
||||
_mouse_button(canvas, sequence_view.model_to_screen(Vector2(-5.0, 5.0)), false)
|
||||
_check(
|
||||
sequence_section.get_elements().size() == 1
|
||||
and sequence_section.get_elements()[0].segments.size() == 3,
|
||||
"a drawn segment continues the selected sequence group"
|
||||
)
|
||||
range_sequence_button.pressed.emit()
|
||||
|
||||
# Leaving sequence mode must not pull later path segments into the group.
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
_mouse_button(canvas, sequence_view.model_to_screen(Vector2(-15.0, 10.0)), true)
|
||||
_mouse_motion(canvas, sequence_view.model_to_screen(Vector2(-5.0, 10.0)))
|
||||
_mouse_button(canvas, sequence_view.model_to_screen(Vector2(-5.0, 10.0)), false)
|
||||
_check(
|
||||
sequence_section.segments.size() == 4,
|
||||
"a segment drawn after the group is added to the section"
|
||||
)
|
||||
_check(
|
||||
sequence_section.get_elements().size() == 1
|
||||
and sequence_section.get_elements()[0].segments.size() == 3,
|
||||
"a segment after sequence mode stays outside the group"
|
||||
)
|
||||
|
||||
# Selecting a member shows and edits the lead element.
|
||||
var sequence_member := sequence_section.segments[1]
|
||||
controller.select_segment(sequence_member.segment_id)
|
||||
_check(
|
||||
controller.get_selected_element() != null
|
||||
and controller.get_selected_element().segments.size() == 3,
|
||||
"selecting a member resolves the whole sequence"
|
||||
)
|
||||
controller.element_button.pressed.emit()
|
||||
_check(controller.element_dialog.visible, "the element dialog opens from a member")
|
||||
_check(
|
||||
controller.element_dialog_type_option.get_item_id(
|
||||
controller.element_dialog_type_option.selected
|
||||
) == PathSegment.ElementType.SEQUENCE,
|
||||
"the dialog shows the sequence type of the group"
|
||||
)
|
||||
controller.element_dialog.hide()
|
||||
|
||||
# Deleting the lead promotes the next member and keeps the element data.
|
||||
var old_lead := sequence_section.get_elements()[0].get_lead()
|
||||
controller.select_segment(old_lead.segment_id)
|
||||
_check(controller.delete_selected_segment(), "the sequence lead can be deleted")
|
||||
var promoted := sequence_section.get_elements()
|
||||
_check(
|
||||
promoted.size() == 1 and promoted[0].get_lead() != old_lead,
|
||||
"deleting the lead promotes another member"
|
||||
)
|
||||
if promoted.size() == 1:
|
||||
_check(
|
||||
promoted[0].get_code() == "StSq",
|
||||
"the promoted member keeps the sequence code"
|
||||
)
|
||||
|
||||
# Clearing the element dissolves the group but keeps the path segments.
|
||||
controller.select_segment(promoted[0].segments[0].segment_id)
|
||||
_check(
|
||||
controller.set_selected_element(PathSegment.ElementType.NONE, "", 0),
|
||||
"the element can be cleared from a group"
|
||||
)
|
||||
_check(
|
||||
promoted[0].segments[0].element_group_id.is_empty(),
|
||||
"clearing the element removes the group id"
|
||||
)
|
||||
_check(
|
||||
sequence_section.get_elements().is_empty(),
|
||||
"a cleared group resolves to no elements"
|
||||
)
|
||||
|
||||
# A marker placed near a group must not split the group in two.
|
||||
controller.new_routine()
|
||||
var group_section := controller.get_active_section()
|
||||
var group_a := controller.add_segment(
|
||||
Vector2(-10.0, 0.0),
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
var group_b := controller.add_segment(
|
||||
Vector2(0.0, 0.0),
|
||||
Vector2(10.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
_check(
|
||||
controller.group_segments_as_sequence(
|
||||
PackedStringArray([group_a.segment_id, group_b.segment_id]),
|
||||
"StSq",
|
||||
0
|
||||
) != null,
|
||||
"existing segments can be grouped as a sequence"
|
||||
)
|
||||
var group_marker := controller.add_element_marker(
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.ElementType.JUMP,
|
||||
"1T",
|
||||
0
|
||||
)
|
||||
_check(
|
||||
group_section.get_elements().size() == 2
|
||||
and group_section.get_elements()[0].segments.size() == 2,
|
||||
"a marker near the group does not split the sequence"
|
||||
)
|
||||
_check(
|
||||
group_section.segments.find(group_marker) > group_section.segments.find(group_b),
|
||||
"the marker is inserted behind the group"
|
||||
)
|
||||
_check(group_section.is_valid(), "the section stays valid with marker and group")
|
||||
|
||||
# A legacy single-segment sequence becomes a group when it is continued.
|
||||
controller.new_routine()
|
||||
var legacy_section := controller.get_active_section()
|
||||
var legacy_range := controller.add_segment(
|
||||
Vector2(-10.0, 0.0),
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
controller.select_segment(legacy_range.segment_id)
|
||||
_check(
|
||||
controller.set_selected_element(
|
||||
PathSegment.ElementType.SEQUENCE,
|
||||
"StSq",
|
||||
0
|
||||
),
|
||||
"a single segment can be tagged as a sequence range"
|
||||
)
|
||||
_check(
|
||||
legacy_range.element_group_id.is_empty(),
|
||||
"a single tagged segment needs no group id yet"
|
||||
)
|
||||
var legacy_button: Button = controller.get_node("%SequenceToolButton")
|
||||
legacy_button.pressed.emit()
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
var legacy_view := canvas.get_view_transform()
|
||||
_mouse_button(canvas, legacy_view.model_to_screen(Vector2(0.0, 0.0)), true)
|
||||
_mouse_motion(canvas, legacy_view.model_to_screen(Vector2(10.0, 0.0)))
|
||||
_mouse_button(canvas, legacy_view.model_to_screen(Vector2(10.0, 0.0)), false)
|
||||
var legacy_elements := legacy_section.get_elements()
|
||||
_check(
|
||||
legacy_elements.size() == 1 and legacy_elements[0].segments.size() == 2,
|
||||
"drawing after a legacy range turns it into a group"
|
||||
)
|
||||
if legacy_elements.size() == 1:
|
||||
_check(
|
||||
not legacy_elements[0].get_group_id().is_empty(),
|
||||
"the continued legacy range gets a group id"
|
||||
)
|
||||
_check(
|
||||
legacy_elements[0].segments[0].element_group_id
|
||||
== legacy_elements[0].segments[1].element_group_id,
|
||||
"both continued segments share the group id"
|
||||
)
|
||||
legacy_button.pressed.emit()
|
||||
|
||||
# Undo removes one drawn part at a time and keeps the group consistent.
|
||||
controller.new_routine()
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
var undo_sequence_button: Button = controller.get_node("%SequenceToolButton")
|
||||
undo_sequence_button.pressed.emit()
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
var undo_view := canvas.get_view_transform()
|
||||
_mouse_button(canvas, undo_view.model_to_screen(Vector2(-10.0, 0.0)), true)
|
||||
_mouse_motion(canvas, undo_view.model_to_screen(Vector2(0.0, 0.0)))
|
||||
_mouse_button(canvas, undo_view.model_to_screen(Vector2(0.0, 0.0)), false)
|
||||
_mouse_button(canvas, undo_view.model_to_screen(Vector2(0.0, 0.0)), true)
|
||||
_mouse_motion(canvas, undo_view.model_to_screen(Vector2(10.0, 0.0)))
|
||||
_mouse_button(canvas, undo_view.model_to_screen(Vector2(10.0, 0.0)), false)
|
||||
var undo_section := controller.get_active_section()
|
||||
_check(
|
||||
undo_section.get_elements().size() == 1
|
||||
and undo_section.get_elements()[0].segments.size() == 2,
|
||||
"the undo fixture has one two-part sequence"
|
||||
)
|
||||
_check(controller.undo(), "the last sequence part can be undone")
|
||||
var undone_section := controller.get_active_section()
|
||||
_check(
|
||||
undone_section.get_elements().size() == 1
|
||||
and undone_section.get_elements()[0].segments.size() == 1,
|
||||
"undo leaves a valid one-part sequence"
|
||||
)
|
||||
_check(controller.undo(), "the first sequence part can be undone")
|
||||
undone_section = controller.get_active_section()
|
||||
_check(
|
||||
undone_section.get_elements().is_empty(),
|
||||
"undo removes the empty sequence group"
|
||||
)
|
||||
|
||||
# Sequence drawing mode also accepts freehand strokes.
|
||||
controller.set_tool(WhiteboardController.Tool.SELECT)
|
||||
var freehand_sequence_button: Button = controller.get_node("%SequenceToolButton")
|
||||
freehand_sequence_button.pressed.emit()
|
||||
controller.set_tool(WhiteboardController.Tool.FREELINE)
|
||||
_check(
|
||||
controller.is_sequence_mode(),
|
||||
"sequence mode stays active when switching to freeline"
|
||||
)
|
||||
freehand_sequence_button.pressed.emit()
|
||||
|
||||
# Multi-selection groups existing segments into a sequence.
|
||||
controller.new_routine()
|
||||
controller.set_tool(WhiteboardController.Tool.SELECT)
|
||||
var group_view := canvas.get_view_transform()
|
||||
var multi_a := controller.add_segment(
|
||||
Vector2(-10.0, 0.0),
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
var multi_b := controller.add_segment(
|
||||
Vector2(0.0, 0.0),
|
||||
Vector2(10.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
var multi_c := controller.add_segment(
|
||||
Vector2(10.0, 0.0),
|
||||
Vector2(20.0, 0.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
)
|
||||
controller.set_multi_select_enabled(true)
|
||||
_check(
|
||||
controller.multi_select_button.button_pressed,
|
||||
"multi-select mode is reflected by the toggle button"
|
||||
)
|
||||
controller.clear_selection()
|
||||
var multi_taps: Array[Vector2] = [
|
||||
Vector2(-5.0, 0.0),
|
||||
Vector2(5.0, 0.0),
|
||||
Vector2(15.0, 0.0),
|
||||
]
|
||||
for point: Vector2 in multi_taps:
|
||||
_mouse_button(canvas, group_view.model_to_screen(point), true)
|
||||
_mouse_button(canvas, group_view.model_to_screen(point), false)
|
||||
_check(
|
||||
controller.get_selected_segment_ids().size() == 3,
|
||||
"multi-select mode adds tapped segments to the selection"
|
||||
)
|
||||
_mouse_button(canvas, group_view.model_to_screen(Vector2(0.0, 12.0)), true)
|
||||
_mouse_button(canvas, group_view.model_to_screen(Vector2(0.0, 12.0)), false)
|
||||
_check(
|
||||
controller.get_selected_segment_ids().size() == 3,
|
||||
"tapping empty ice in multi-select mode keeps the selection"
|
||||
)
|
||||
_check(
|
||||
controller.can_group_selected_as_sequence(),
|
||||
"a contiguous multi-selection can become a sequence"
|
||||
)
|
||||
_check(
|
||||
not controller.group_sequence_button.disabled,
|
||||
"the group button is enabled for a valid selection"
|
||||
)
|
||||
_check(
|
||||
controller.group_sequence_button.text.contains("3"),
|
||||
"the group button shows the selection count"
|
||||
)
|
||||
controller.group_sequence_button.pressed.emit()
|
||||
var grouped_elements := controller.get_active_section().get_elements()
|
||||
_check(
|
||||
grouped_elements.size() == 1
|
||||
and grouped_elements[0].segments.size() == 3,
|
||||
"the group button creates one sequence element"
|
||||
)
|
||||
_check(
|
||||
not controller.is_multi_select_enabled()
|
||||
and controller.get_selected_segment_ids().size() == 1,
|
||||
"grouping leaves one selected lead and ends multi-select mode"
|
||||
)
|
||||
if grouped_elements.size() == 1:
|
||||
_check(
|
||||
grouped_elements[0].get_lead() == multi_a,
|
||||
"grouping starts at the first selected segment"
|
||||
)
|
||||
_check(
|
||||
controller.group_sequence_button.disabled,
|
||||
"the group button disables after grouping"
|
||||
)
|
||||
|
||||
_check(controller.undo(), "grouping can be undone")
|
||||
var ungrouped_section := controller.get_active_section()
|
||||
_check(
|
||||
ungrouped_section.get_elements().is_empty(),
|
||||
"undo restores the plain segments"
|
||||
)
|
||||
|
||||
# A selection with a gap cannot be grouped.
|
||||
controller.set_multi_select_enabled(true)
|
||||
controller.clear_selection()
|
||||
for point: Vector2 in [Vector2(-5.0, 0.0), Vector2(15.0, 0.0)]:
|
||||
_mouse_button(canvas, group_view.model_to_screen(point), true)
|
||||
_mouse_button(canvas, group_view.model_to_screen(point), false)
|
||||
_check(
|
||||
controller.get_selected_segment_ids().size() == 2,
|
||||
"the gap fixture selects two segments"
|
||||
)
|
||||
_check(
|
||||
not controller.can_group_selected_as_sequence()
|
||||
and controller.group_sequence_button.disabled,
|
||||
"a non-contiguous selection cannot be grouped"
|
||||
)
|
||||
controller.set_multi_select_enabled(false)
|
||||
|
||||
# Smoothing a jagged freehand keeps endpoints and point count, is
|
||||
# undoable and is exposed through the timing-bar button.
|
||||
controller.new_routine()
|
||||
var smooth_section := controller.get_active_section()
|
||||
var smooth_segment := PathSegment.new()
|
||||
smooth_segment.segment_id = "seg-smooth"
|
||||
smooth_segment.template = PathSegment.Template.FREEHAND
|
||||
smooth_segment.curve = Curve2D.new()
|
||||
var smooth_points: Array[Vector2] = [
|
||||
Vector2(-10.0, 0.0),
|
||||
Vector2(-8.0, 2.0),
|
||||
Vector2(-6.0, -2.0),
|
||||
Vector2(-4.0, 2.0),
|
||||
Vector2(-2.0, 0.0),
|
||||
]
|
||||
for point: Vector2 in smooth_points:
|
||||
smooth_segment.curve.add_point(point)
|
||||
smooth_segment.set_speed_mps(4.3)
|
||||
smooth_section.segments.append(smooth_segment)
|
||||
controller.select_segment(smooth_segment.segment_id)
|
||||
_check(
|
||||
controller.smooth_button.visible
|
||||
and not controller.smooth_button.disabled,
|
||||
"the smooth button is available for a selected freehand"
|
||||
)
|
||||
_check(
|
||||
controller.can_smooth_selected_freehand(),
|
||||
"a multi-point freehand can be smoothed"
|
||||
)
|
||||
var before_jitter := smooth_segment.curve.get_point_position(2)
|
||||
var before_length := smooth_segment.get_length_m()
|
||||
controller.smooth_button.pressed.emit()
|
||||
_check(
|
||||
smooth_segment.curve.point_count == smooth_points.size(),
|
||||
"smoothing keeps the point count"
|
||||
)
|
||||
_check_vec(
|
||||
smooth_segment.curve.get_point_position(0),
|
||||
smooth_points[0],
|
||||
"smoothing keeps the first freehand point"
|
||||
)
|
||||
_check_vec(
|
||||
smooth_segment.curve.get_point_position(smooth_points.size() - 1),
|
||||
smooth_points[smooth_points.size() - 1],
|
||||
"smoothing keeps the last freehand point"
|
||||
)
|
||||
_check_vec(
|
||||
smooth_segment.curve.get_point_position(2),
|
||||
Vector2(-6.0, 0.25),
|
||||
"smoothing moves the interior point between its neighbours"
|
||||
)
|
||||
_check(
|
||||
absf(smooth_segment.get_length_m() - before_length) > 0.01,
|
||||
"smoothing updates the freehand length"
|
||||
)
|
||||
_check(controller.undo(), "smoothing can be undone")
|
||||
var restored := controller.get_active_section().get_segment_by_id(
|
||||
"seg-smooth"
|
||||
)
|
||||
_check(restored != null, "the smoothed freehand survives undo")
|
||||
if restored != null:
|
||||
_check_vec(
|
||||
restored.curve.get_point_position(2),
|
||||
before_jitter,
|
||||
"undo restores the original freehand points"
|
||||
)
|
||||
|
||||
# Freehand strokes are simplified automatically at the end of the drag.
|
||||
controller.new_routine()
|
||||
controller.set_tool(WhiteboardController.Tool.FREELINE)
|
||||
var simplify_view := canvas.get_view_transform()
|
||||
var dense_points: Array[Vector2] = []
|
||||
for index: int in range(24):
|
||||
dense_points.append(
|
||||
Vector2(-20.0 + float(index), 0.02 * float(index % 2))
|
||||
)
|
||||
_mouse_button(
|
||||
canvas,
|
||||
simplify_view.model_to_screen(dense_points[0]),
|
||||
true
|
||||
)
|
||||
for index: int in range(1, dense_points.size()):
|
||||
_mouse_motion(
|
||||
canvas,
|
||||
simplify_view.model_to_screen(dense_points[index])
|
||||
)
|
||||
_mouse_button(
|
||||
canvas,
|
||||
simplify_view.model_to_screen(dense_points[dense_points.size() - 1]),
|
||||
false
|
||||
)
|
||||
var dense_section := controller.get_active_section()
|
||||
var dense_freehand := dense_section.segments[
|
||||
dense_section.segments.size() - 1
|
||||
]
|
||||
_check(
|
||||
dense_freehand.curve.point_count < dense_points.size(),
|
||||
"freehand drawing simplifies dense points automatically"
|
||||
)
|
||||
_check_vec(
|
||||
dense_freehand.curve.get_point_position(0),
|
||||
dense_points[0],
|
||||
"automatic simplification keeps the start point"
|
||||
)
|
||||
_check_vec(
|
||||
dense_freehand.curve.get_point_position(
|
||||
dense_freehand.curve.point_count - 1
|
||||
),
|
||||
dense_points[dense_points.size() - 1],
|
||||
"automatic simplification keeps the end point"
|
||||
)
|
||||
_check(
|
||||
dense_freehand.duration_seconds > 0.0,
|
||||
"automatic simplification keeps a valid duration"
|
||||
)
|
||||
|
||||
# The manual button reduces an existing freehand and is undoable.
|
||||
controller.new_routine()
|
||||
var simplify_section := controller.get_active_section()
|
||||
var simplify_segment := PathSegment.new()
|
||||
simplify_segment.segment_id = "seg-simplify"
|
||||
simplify_segment.template = PathSegment.Template.FREEHAND
|
||||
simplify_segment.curve = Curve2D.new()
|
||||
var simplify_points: Array[Vector2] = []
|
||||
for index: int in range(30):
|
||||
var point := Vector2(
|
||||
-18.0 + float(index),
|
||||
0.02 * float(index % 2)
|
||||
)
|
||||
simplify_points.append(point)
|
||||
simplify_segment.curve.add_point(point)
|
||||
simplify_segment.set_speed_mps(4.3)
|
||||
simplify_section.segments.append(simplify_segment)
|
||||
controller.select_segment(simplify_segment.segment_id)
|
||||
_check(
|
||||
controller.simplify_button.visible
|
||||
and not controller.simplify_button.disabled,
|
||||
"the simplify button is available for a selected freehand"
|
||||
)
|
||||
_check(
|
||||
controller.can_simplify_selected_freehand(),
|
||||
"a multi-point freehand can be simplified"
|
||||
)
|
||||
controller.simplify_button.pressed.emit()
|
||||
_check(
|
||||
simplify_segment.curve.point_count < simplify_points.size(),
|
||||
"the simplify button reduces the point count"
|
||||
)
|
||||
_check_vec(
|
||||
simplify_segment.curve.get_point_position(0),
|
||||
simplify_points[0],
|
||||
"manual simplification keeps the start point"
|
||||
)
|
||||
_check_vec(
|
||||
simplify_segment.curve.get_point_position(
|
||||
simplify_segment.curve.point_count - 1
|
||||
),
|
||||
simplify_points[simplify_points.size() - 1],
|
||||
"manual simplification keeps the end point"
|
||||
)
|
||||
_check(controller.undo(), "manual simplification can be undone")
|
||||
var restored_simplify := controller.get_active_section().get_segment_by_id(
|
||||
"seg-simplify"
|
||||
)
|
||||
_check(
|
||||
restored_simplify != null
|
||||
and restored_simplify.curve.point_count == simplify_points.size(),
|
||||
"undo restores the dense freehand points"
|
||||
)
|
||||
|
||||
scene.queue_free()
|
||||
await process_frame
|
||||
_finish()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue