feat: SVG- und PNG-Export für Kürläufe hinzufügen
- SVG direkt aus dem Modell mit Rink, Section-Nummern und Legende - PNG über eine eigene Export-Szene in 2560 x 1600 - Export der Gesamtkür oder des aktiven Abschnitts - Export-Dialog im Datei-Menü, Ablage unter user://exports - Tests auf 417 Assertions erweitert
This commit is contained in:
parent
43da04b3cc
commit
ff6ca2de0f
14 changed files with 838 additions and 20 deletions
|
|
@ -35,6 +35,9 @@ $GODOT --headless --path rinkplanner --script res://tests/run_playback_tests.gd
|
|||
|
||||
# Run segment timing/presets/calibration tests
|
||||
$GODOT --headless --path rinkplanner --script res://tests/run_timing_tests.gd
|
||||
|
||||
# Run SVG export tests
|
||||
$GODOT --headless --path rinkplanner --script res://tests/run_export_tests.gd
|
||||
```
|
||||
|
||||
Exit code `0` means all assertions passed. Failures are printed to stderr.
|
||||
|
|
|
|||
191
rinkplanner/tests/run_export_tests.gd
Normal file
191
rinkplanner/tests/run_export_tests.gd
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
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")
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
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
|
||||
section_one.segments = [
|
||||
_make_segment(
|
||||
"seg-1",
|
||||
Vector2(-20.0, -8.0),
|
||||
Vector2(-10.0, -8.0),
|
||||
PathSegment.Direction.FORWARD,
|
||||
PathSegment.Edge.OUTSIDE
|
||||
),
|
||||
_make_segment(
|
||||
"seg-2",
|
||||
Vector2(-10.0, -8.0),
|
||||
Vector2(0.0, 0.0),
|
||||
PathSegment.Direction.BACKWARD,
|
||||
PathSegment.Edge.INSIDE
|
||||
),
|
||||
]
|
||||
|
||||
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))
|
||||
section_two.segments = [arc]
|
||||
|
||||
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 _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)
|
||||
1
rinkplanner/tests/run_export_tests.gd.uid
Normal file
1
rinkplanner/tests/run_export_tests.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c1qprqtpa0oyy
|
||||
Loading…
Add table
Add a link
Reference in a new issue