- 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
260 lines
6.4 KiB
GDScript
260 lines
6.4 KiB
GDScript
extends SceneTree
|
|
|
|
## Headless tests for SVG export and the export plumbing.
|
|
##
|
|
## Run with:
|
|
## godot --headless --path rinkplanner --script res://tests/run_export_tests.gd
|
|
|
|
const WhiteboardScene := preload("res://scenes/whiteboard/whiteboard.tscn")
|
|
|
|
var _assertions: int = 0
|
|
var _failures: PackedStringArray = PackedStringArray()
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _run() -> void:
|
|
var routine := _make_routine()
|
|
|
|
var svg := RoutineSvgExporter.build(routine)
|
|
_check(svg.contains("<?xml version=\"1.0\""), "SVG has an XML declaration")
|
|
_check(svg.contains("<svg "), "SVG root is present")
|
|
_check(svg.contains("viewBox=\"0 0 1600.00 1000.00\""), "SVG has the page viewBox")
|
|
_check(svg.contains("Test & <Kür>"), "SVG escapes the title")
|
|
_check(svg.contains(">1</text>"), "SVG contains the first section badge")
|
|
_check(svg.contains(">2</text>"), "SVG contains the second section badge")
|
|
_check(svg.contains("#DC2626"), "SVG contains outside-edge color")
|
|
_check(svg.contains("#2563EB"), "SVG contains inside-edge color")
|
|
_check(svg.contains("stroke-dasharray="), "SVG encodes backward segments as dashes")
|
|
_check(_count(svg, "<polyline") == 3, "SVG contains all routine segments")
|
|
_check(
|
|
svg.contains(">3Lz & <Spin></text>"),
|
|
"SVG contains and escapes segment labels"
|
|
)
|
|
_check(
|
|
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(
|
|
_count(section_svg, "<polyline") == 2,
|
|
"section export only contains the selected section"
|
|
)
|
|
_check(
|
|
section_svg.contains("Abschnitt 1"),
|
|
"section export names the selected section"
|
|
)
|
|
_check(
|
|
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
|
|
if controller != null:
|
|
controller.restore_autosave = false
|
|
controller.autosave_enabled = false
|
|
root.add_child(scene)
|
|
await process_frame
|
|
|
|
_check(controller != null, "export scene has a controller")
|
|
if controller == null:
|
|
_finish()
|
|
return
|
|
|
|
controller.add_segment(
|
|
Vector2(-10.0, 0.0),
|
|
Vector2(0.0, 0.0),
|
|
PathSegment.Direction.FORWARD,
|
|
PathSegment.Edge.OUTSIDE
|
|
)
|
|
var export_path := "user://test_export.svg"
|
|
_check(
|
|
controller.export_svg_to_path(export_path),
|
|
"controller writes an SVG file"
|
|
)
|
|
_check(FileAccess.file_exists(export_path), "exported SVG exists on disk")
|
|
if FileAccess.file_exists(export_path):
|
|
var file := FileAccess.open(export_path, FileAccess.READ)
|
|
var content := file.get_as_text()
|
|
file.close()
|
|
_check(content.contains("<svg "), "exported SVG file has SVG content")
|
|
DirAccess.remove_absolute(export_path)
|
|
|
|
scene.queue_free()
|
|
await process_frame
|
|
_finish()
|
|
|
|
|
|
func _make_routine() -> Routine:
|
|
var routine := Routine.new()
|
|
routine.routine_id = "export-test"
|
|
routine.title = "Test & <Kür>"
|
|
routine.rink = RinkDimensions.new()
|
|
|
|
var section_one := RoutineSection.new()
|
|
section_one.section_id = "section-1"
|
|
section_one.title = "Abschnitt 1"
|
|
section_one.sequence_order = 0
|
|
var labelled := _make_segment(
|
|
"seg-1",
|
|
Vector2(-20.0, -8.0),
|
|
Vector2(-10.0, -8.0),
|
|
PathSegment.Direction.FORWARD,
|
|
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(
|
|
"seg-2",
|
|
Vector2(-10.0, -8.0),
|
|
Vector2(0.0, 0.0),
|
|
PathSegment.Direction.BACKWARD,
|
|
PathSegment.Edge.INSIDE
|
|
),
|
|
spin_marker,
|
|
]
|
|
|
|
var section_two := RoutineSection.new()
|
|
section_two.section_id = "section-2"
|
|
section_two.title = "Abschnitt 2"
|
|
section_two.sequence_order = 1
|
|
var arc := _make_segment(
|
|
"seg-3",
|
|
Vector2(0.0, 0.0),
|
|
Vector2(10.0, 0.0),
|
|
PathSegment.Direction.FORWARD,
|
|
PathSegment.Edge.OUTSIDE
|
|
)
|
|
arc.template = PathSegment.Template.ARC
|
|
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))
|
|
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
|
|
|
|
|
|
func _make_segment(
|
|
segment_id: String,
|
|
from: Vector2,
|
|
to: Vector2,
|
|
direction: PathSegment.Direction,
|
|
edge: PathSegment.Edge
|
|
) -> PathSegment:
|
|
var segment := PathSegment.new()
|
|
segment.segment_id = segment_id
|
|
segment.direction = direction
|
|
segment.edge = edge
|
|
segment.curve = Curve2D.new()
|
|
segment.curve.add_point(from)
|
|
segment.curve.add_point(to)
|
|
segment.set_speed_mps(4.3)
|
|
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(
|
|
from,
|
|
to,
|
|
true,
|
|
0.4,
|
|
RinkDimensions.new()
|
|
)
|
|
for point: Vector2 in points:
|
|
curve.add_point(point)
|
|
return curve
|
|
|
|
|
|
func _count(text: String, needle: String) -> int:
|
|
var count := 0
|
|
var start := 0
|
|
while true:
|
|
var index := text.find(needle, start)
|
|
if index < 0:
|
|
break
|
|
count += 1
|
|
start = index + needle.length()
|
|
return count
|
|
|
|
|
|
func _check(condition: bool, message: String) -> void:
|
|
_assertions += 1
|
|
if not condition:
|
|
_failures.append(message)
|
|
|
|
|
|
func _finish() -> void:
|
|
if _failures.is_empty():
|
|
print("PASS: %d assertions" % _assertions)
|
|
quit(0)
|
|
return
|
|
|
|
for failure: String in _failures:
|
|
printerr("FAIL: %s" % failure)
|
|
printerr("%d of %d assertions failed" % [_failures.size(), _assertions])
|
|
quit(1)
|