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
|
|
@ -173,9 +173,13 @@ standardmäßig bleibt es aus.
|
|||
|
||||
## 6. Export und Persistenz
|
||||
|
||||
- **SVG** wird direkt aus dem Modell serialisiert (Kurven als Pfade), nicht
|
||||
aus einem Screenshot. Damit bleibt der Export auflösungsunabhängig.
|
||||
- **PNG** entsteht über einen Viewport-Render in hoher Auflösung.
|
||||
- **SVG** wird direkt aus dem Modell serialisiert (Kurven als Pfade,
|
||||
Section-Nummern, Legende, Rink), nicht aus einem Screenshot. Damit bleibt
|
||||
der Export auflösungsunabhängig.
|
||||
- **PNG** entsteht über eine eigene Export-Szene in einem `SubViewport`
|
||||
(2560 × 1600) mit Titel, Section-Nummern und Legende.
|
||||
- **Umfang:** Gesamte Kür oder aktiver Abschnitt; Dateien landen unter
|
||||
`user://exports/`.
|
||||
- **PDF** ist nicht nativ in Godot. Erste Stufe: Browser-Druck aus SVG;
|
||||
eine echte PDF-Ausgabe ist ein separates Arbeitspaket.
|
||||
- **Persistenz** erfolgt lokal als `.tres`-Ressourcen unter
|
||||
|
|
@ -219,6 +223,8 @@ Aktueller Stand:
|
|||
Button-Verdrahtung, Scrubbing und Geschwindigkeitswechsel.
|
||||
- **Timing:** 41 Assertions für Dauer-/Tempo-Kopplung, Level-Presets,
|
||||
Kalibrierung, Undo, Persistenz und Schema-1-Migration.
|
||||
- **Export:** 17 Assertions für SVG-Struktur, Titel-Escaping, Section-Filter,
|
||||
Segmentfarben/-strichelung und das Schreiben der Exportdatei.
|
||||
|
||||
Autosave/Restore wird zusätzlich in einem isolierten `XDG_DATA_HOME`
|
||||
end-to-end geprüft.
|
||||
|
|
|
|||
|
|
@ -41,15 +41,16 @@ Voraussetzung für Phase 1.
|
|||
- [x] Timing in Playback, Timeline, Undo/Redo und Speichern/Laden integriert
|
||||
- [x] 6-m/s-Platzhalter durch bewusste Profile ersetzt
|
||||
|
||||
### Nächster Schritt: Export
|
||||
### Erledigt: Export
|
||||
|
||||
- [ ] PNG in hoher Auflösung für Tablet-Weitergabe
|
||||
- [ ] SVG direkt aus dem Modell (Kurven, Sections, Legende, Rink)
|
||||
- [ ] Export der aktiven Section und des gesamten Programms
|
||||
- [ ] PDF zunächst über Browser-Druck aus SVG
|
||||
- [ ] Export-Tests: Geometrie, Section-Reihenfolge, Sichtbarkeit
|
||||
- [x] PNG in hoher Auflösung für Tablet-Weitergabe (2560 × 1600)
|
||||
- [x] SVG direkt aus dem Modell (Kurven, Sections, Legende, Rink)
|
||||
- [x] Export der aktiven Section und des gesamten Programms
|
||||
- [x] SVG als Grundlage für Browser-Druck (PDF)
|
||||
- [x] Export-Tests: Geometrie, Section-Reihenfolge, Sichtbarkeit
|
||||
- [x] Export-Dialog mit Dateiname, Format und Umfang
|
||||
|
||||
### Danach: Touch-/Tablet-/Web-Härtung
|
||||
### Nächster Schritt: Touch-/Tablet-/Web-Härtung
|
||||
|
||||
- [ ] Test auf echtem Tablet
|
||||
- [ ] Web-Export mit Compatibility-Renderer
|
||||
|
|
|
|||
70
rinkplanner/scenes/export/export_sheet.tscn
Normal file
70
rinkplanner/scenes/export/export_sheet.tscn
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
[gd_scene load_steps=3 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://src/whiteboard/io/export_sheet.gd" id="1_sheet"]
|
||||
[ext_resource type="Script" path="res://src/whiteboard/view/rink_canvas.gd" id="2_canvas"]
|
||||
|
||||
[node name="ExportSheet" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_sheet")
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(1, 1, 1, 1)
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="Margin" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 48
|
||||
theme_override_constants/margin_top = 36
|
||||
theme_override_constants/margin_right = 48
|
||||
theme_override_constants/margin_bottom = 28
|
||||
|
||||
[node name="Layout" type="VBoxContainer" parent="Margin"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 12
|
||||
|
||||
[node name="Header" type="VBoxContainer" parent="Margin/Layout"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 2
|
||||
|
||||
[node name="ExportTitle" type="Label" parent="Margin/Layout/Header"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.0588235, 0.0901961, 0.164706, 1)
|
||||
theme_override_font_sizes/font_size = 46
|
||||
text = "Rinkplanner"
|
||||
|
||||
[node name="ExportSubtitle" type="Label" parent="Margin/Layout/Header"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.392157, 0.454902, 0.545098, 1)
|
||||
theme_override_font_sizes/font_size = 20
|
||||
text = ""
|
||||
|
||||
[node name="ExportCanvas" type="Control" parent="Margin/Layout"]
|
||||
unique_name_in_owner = true
|
||||
clip_contents = true
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("2_canvas")
|
||||
|
||||
[node name="Footer" type="Label" parent="Margin/Layout"]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.392157, 0.454902, 0.545098, 1)
|
||||
theme_override_font_sizes/font_size = 15
|
||||
text = "Vorwärts: durchgezogen · Rückwärts: gestrichelt · Außen: rot · Innen: blau"
|
||||
|
|
@ -323,7 +323,7 @@ custom_minimum_size = Vector2(64, 48)
|
|||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.85098, 0.890196, 0.941176, 1)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "–"
|
||||
text = "…"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
|
|
@ -361,7 +361,7 @@ custom_minimum_size = Vector2(78, 48)
|
|||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.85098, 0.890196, 0.941176, 1)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "–"
|
||||
text = "…"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
|
|
@ -618,3 +618,50 @@ layout_mode = 2
|
|||
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "Geschwindigkeit = Strecke / Zeit"
|
||||
|
||||
[node name="ExportDialog" type="ConfirmationDialog" parent="."]
|
||||
unique_name_in_owner = true
|
||||
title = "Kür exportieren"
|
||||
size = Vector2i(480, 360)
|
||||
ok_button_text = "Exportieren"
|
||||
cancel_button_text = "Abbrechen"
|
||||
|
||||
[node name="ExportBox" type="VBoxContainer" parent="ExportDialog"]
|
||||
offset_left = 8.0
|
||||
offset_top = 8.0
|
||||
offset_right = 472.0
|
||||
offset_bottom = 280.0
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="ExportNameLabel" type="Label" parent="ExportDialog/ExportBox"]
|
||||
layout_mode = 2
|
||||
text = "Dateiname"
|
||||
|
||||
[node name="ExportNameEdit" type="LineEdit" parent="ExportDialog/ExportBox"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(0, 48)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ExportFormatLabel" type="Label" parent="ExportDialog/ExportBox"]
|
||||
layout_mode = 2
|
||||
text = "Format"
|
||||
|
||||
[node name="ExportFormatOption" type="OptionButton" parent="ExportDialog/ExportBox"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(0, 48)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ExportScopeLabel" type="Label" parent="ExportDialog/ExportBox"]
|
||||
layout_mode = 2
|
||||
text = "Umfang"
|
||||
|
||||
[node name="ExportScopeOption" type="OptionButton" parent="ExportDialog/ExportBox"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(0, 48)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ExportHint" type="Label" parent="ExportDialog/ExportBox"]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "Ziel: user://exports"
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ enum FileAction {
|
|||
OPEN,
|
||||
SAVE,
|
||||
SAVE_AS,
|
||||
EXPORT,
|
||||
}
|
||||
|
||||
const DEFAULT_SPEED_MPS := 4.3
|
||||
|
|
@ -37,6 +38,9 @@ const PROFILE_NAMES := [
|
|||
]
|
||||
const PROFILE_SPEEDS := [3.0, 3.8, 4.3, 5.0, 6.0]
|
||||
const ROUTINES_DIR := "user://routines"
|
||||
const EXPORTS_DIR := "user://exports"
|
||||
const EXPORT_SHEET_SCENE := preload("res://scenes/export/export_sheet.tscn")
|
||||
const EXPORT_IMAGE_SIZE := Vector2i(2560, 1600)
|
||||
const AUTOSAVE_PATH := "user://autosave.tres"
|
||||
const AUTOSAVE_DELAY_SECONDS := 1.5
|
||||
const MAX_HISTORY := 50
|
||||
|
|
@ -91,6 +95,10 @@ const MAX_HISTORY := 50
|
|||
@onready var calibration_dialog: ConfirmationDialog = %CalibrationDialog
|
||||
@onready var calibration_distance_edit: LineEdit = %CalibrationDistanceEdit
|
||||
@onready var calibration_time_edit: LineEdit = %CalibrationTimeEdit
|
||||
@onready var export_dialog: ConfirmationDialog = %ExportDialog
|
||||
@onready var export_name_edit: LineEdit = %ExportNameEdit
|
||||
@onready var export_format_option: OptionButton = %ExportFormatOption
|
||||
@onready var export_scope_option: OptionButton = %ExportScopeOption
|
||||
|
||||
var _routine: Routine
|
||||
var _active_section: RoutineSection
|
||||
|
|
@ -128,6 +136,7 @@ func _ready() -> void:
|
|||
_setup_file_menu()
|
||||
_setup_playback_controls()
|
||||
_setup_timing_controls()
|
||||
_setup_export_controls()
|
||||
|
||||
tool_option.item_selected.connect(_on_tool_selected)
|
||||
forward_button.pressed.connect(
|
||||
|
|
@ -176,6 +185,7 @@ func _ready() -> void:
|
|||
calibrate_button.pressed.connect(_open_calibration_dialog)
|
||||
reset_timing_button.pressed.connect(_reset_selected_timing)
|
||||
calibration_dialog.confirmed.connect(_on_calibration_confirmed)
|
||||
export_dialog.confirmed.connect(_on_export_confirmed)
|
||||
|
||||
_ensure_routines_dir()
|
||||
if not (restore_autosave and _try_load_autosave()):
|
||||
|
|
@ -1183,8 +1193,8 @@ func _update_timing_ui() -> void:
|
|||
var selected := get_selected_segment()
|
||||
if selected == null:
|
||||
timing_selection_label.text = "Kein Segment ausgewählt"
|
||||
duration_value_label.text = "–"
|
||||
speed_value_label.text = "–"
|
||||
duration_value_label.text = "…"
|
||||
speed_value_label.text = "…"
|
||||
_set_timing_controls_enabled(false)
|
||||
_select_profile_for_speed(_preset_speed)
|
||||
return
|
||||
|
|
@ -1327,6 +1337,8 @@ func _setup_file_menu() -> void:
|
|||
popup.add_separator()
|
||||
popup.add_item("Speichern", FileAction.SAVE)
|
||||
popup.add_item("Speichern unter…", FileAction.SAVE_AS)
|
||||
popup.add_separator()
|
||||
popup.add_item("Exportieren…", FileAction.EXPORT)
|
||||
popup.id_pressed.connect(_on_file_menu_pressed)
|
||||
|
||||
|
||||
|
|
@ -1340,6 +1352,8 @@ func _on_file_menu_pressed(action: int) -> void:
|
|||
_save_or_prompt()
|
||||
FileAction.SAVE_AS:
|
||||
_open_save_as_dialog()
|
||||
FileAction.EXPORT:
|
||||
_open_export_dialog()
|
||||
|
||||
|
||||
func _set_routine(routine: Routine, path: String) -> void:
|
||||
|
|
@ -1562,6 +1576,111 @@ func _on_save_as_confirmed() -> void:
|
|||
save_to_path(ROUTINES_DIR.path_join(stem + ".tres"))
|
||||
|
||||
|
||||
func _setup_export_controls() -> void:
|
||||
export_format_option.clear()
|
||||
export_format_option.add_item("SVG (Vektor)", 0)
|
||||
export_format_option.add_item("PNG (hochauflösend)", 1)
|
||||
export_scope_option.clear()
|
||||
export_scope_option.add_item("Gesamte Kür", 0)
|
||||
export_scope_option.add_item("Aktiver Abschnitt", 1)
|
||||
export_format_option.select(0)
|
||||
export_scope_option.select(0)
|
||||
|
||||
|
||||
func _open_export_dialog() -> void:
|
||||
if _routine == null:
|
||||
return
|
||||
|
||||
export_name_edit.text = _routine.title
|
||||
if export_name_edit.text.strip_edges().is_empty():
|
||||
export_name_edit.text = "kuer"
|
||||
export_format_option.select(0)
|
||||
export_scope_option.select(0)
|
||||
export_dialog.popup_centered(Vector2i(480, 360))
|
||||
export_name_edit.grab_focus()
|
||||
export_name_edit.select_all()
|
||||
|
||||
|
||||
func _on_export_confirmed() -> void:
|
||||
var name := export_name_edit.text.strip_edges()
|
||||
if name.is_empty():
|
||||
_show_message("Bitte einen Dateinamen eingeben.")
|
||||
return
|
||||
|
||||
var stem := _normalize_file_stem(name)
|
||||
var scope_section_id := ""
|
||||
var scope_suffix := ""
|
||||
if export_scope_option.selected == 1:
|
||||
if _active_section == null:
|
||||
_show_message("Kein aktiver Abschnitt vorhanden.")
|
||||
return
|
||||
scope_section_id = _active_section.section_id
|
||||
scope_suffix = "_" + _normalize_file_stem(_active_section.title)
|
||||
|
||||
var is_svg := export_format_option.selected == 0
|
||||
var extension := "svg" if is_svg else "png"
|
||||
var path := EXPORTS_DIR.path_join(stem + scope_suffix + "." + extension)
|
||||
_ensure_exports_dir()
|
||||
|
||||
var success := false
|
||||
if is_svg:
|
||||
success = export_svg_to_path(path, scope_section_id)
|
||||
else:
|
||||
success = await export_png_to_path(path, scope_section_id)
|
||||
|
||||
if success:
|
||||
_show_message("Exportiert nach:\n%s" % path)
|
||||
else:
|
||||
_show_message("Export fehlgeschlagen.")
|
||||
|
||||
|
||||
func export_svg_to_path(path: String, section_id: String = "") -> bool:
|
||||
if _routine == null:
|
||||
return false
|
||||
var svg := RoutineSvgExporter.build(_routine, section_id)
|
||||
if svg.is_empty():
|
||||
return false
|
||||
|
||||
var file := FileAccess.open(path, FileAccess.WRITE)
|
||||
if file == null:
|
||||
return false
|
||||
file.store_string(svg)
|
||||
file.close()
|
||||
return true
|
||||
|
||||
|
||||
func export_png_to_path(path: String, section_id: String = "") -> bool:
|
||||
if _routine == null:
|
||||
return false
|
||||
|
||||
var viewport := SubViewport.new()
|
||||
viewport.size = EXPORT_IMAGE_SIZE
|
||||
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
|
||||
add_child(viewport)
|
||||
|
||||
var sheet := EXPORT_SHEET_SCENE.instantiate() as ExportSheet
|
||||
if sheet == null:
|
||||
viewport.queue_free()
|
||||
return false
|
||||
viewport.add_child(sheet)
|
||||
|
||||
await get_tree().process_frame
|
||||
sheet.setup(_routine, section_id)
|
||||
await get_tree().process_frame
|
||||
await RenderingServer.frame_post_draw
|
||||
|
||||
var image := viewport.get_texture().get_image()
|
||||
viewport.queue_free()
|
||||
if image.is_empty():
|
||||
return false
|
||||
return image.save_png(path) == OK
|
||||
|
||||
|
||||
func _ensure_exports_dir() -> void:
|
||||
if not DirAccess.dir_exists_absolute(EXPORTS_DIR):
|
||||
DirAccess.make_dir_recursive_absolute(EXPORTS_DIR)
|
||||
|
||||
|
||||
func _open_open_dialog() -> void:
|
||||
_refresh_open_list()
|
||||
open_dialog.popup_centered(Vector2i(520, 460))
|
||||
|
|
|
|||
43
rinkplanner/src/whiteboard/io/export_sheet.gd
Normal file
43
rinkplanner/src/whiteboard/io/export_sheet.gd
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
class_name ExportSheet
|
||||
extends Control
|
||||
|
||||
## Printable export sheet used by the PNG renderer. The SVG exporter builds the
|
||||
## same content independently from the model.
|
||||
|
||||
@onready var title_label: Label = %ExportTitle
|
||||
@onready var subtitle_label: Label = %ExportSubtitle
|
||||
@onready var export_canvas: RinkCanvas = %ExportCanvas
|
||||
|
||||
|
||||
func setup(routine: Routine, section_id: String = "") -> void:
|
||||
if routine == null:
|
||||
return
|
||||
|
||||
var title := routine.title.strip_edges()
|
||||
if title.is_empty():
|
||||
title = "Unbenannte Kür"
|
||||
title_label.text = title
|
||||
|
||||
if section_id.is_empty():
|
||||
subtitle_label.text = "%d Abschnitte · %s s" % [
|
||||
routine.sections.size(),
|
||||
_format_seconds(routine.get_duration_seconds()),
|
||||
]
|
||||
else:
|
||||
var section := routine.get_section_by_id(section_id)
|
||||
if section != null:
|
||||
subtitle_label.text = "%s · %s s" % [
|
||||
section.title,
|
||||
_format_seconds(section.get_duration_seconds()),
|
||||
]
|
||||
else:
|
||||
subtitle_label.text = ""
|
||||
|
||||
export_canvas.fit_padding_px = 24.0
|
||||
export_canvas.set_presentation_mode(true)
|
||||
export_canvas.set_presentation_section_filter(section_id)
|
||||
export_canvas.set_routine(routine)
|
||||
|
||||
|
||||
func _format_seconds(seconds: float) -> String:
|
||||
return ("%.1f" % seconds).replace(".", ",")
|
||||
1
rinkplanner/src/whiteboard/io/export_sheet.gd.uid
Normal file
1
rinkplanner/src/whiteboard/io/export_sheet.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://0n1co8b7ex10
|
||||
259
rinkplanner/src/whiteboard/io/svg_exporter.gd
Normal file
259
rinkplanner/src/whiteboard/io/svg_exporter.gd
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
class_name RoutineSvgExporter
|
||||
extends RefCounted
|
||||
|
||||
## Builds a printable SVG sheet directly from the routine model. No viewport
|
||||
## screenshot is involved, so the output stays vector-based.
|
||||
|
||||
const PAGE_WIDTH := 1600.0
|
||||
const PAGE_HEIGHT := 1000.0
|
||||
const MARGIN := 48.0
|
||||
const HEADER_HEIGHT := 118.0
|
||||
const FOOTER_HEIGHT := 72.0
|
||||
const CURVE_SAMPLE_STEP_M := 0.2
|
||||
const MAX_CURVE_SAMPLES := 3000
|
||||
|
||||
const ICE_COLOR := "#eef6fb"
|
||||
const BOARDS_COLOR := "#1e293b"
|
||||
const OUTSIDE_COLOR := "#DC2626"
|
||||
const INSIDE_COLOR := "#2563EB"
|
||||
const TEXT_COLOR := "#0f172a"
|
||||
const MUTED_TEXT_COLOR := "#64748b"
|
||||
|
||||
|
||||
static func build(routine: Routine, section_id: String = "") -> String:
|
||||
if routine == null:
|
||||
return ""
|
||||
|
||||
var rink: RinkDimensions = routine.rink
|
||||
if rink == null or not rink.is_valid():
|
||||
rink = RinkDimensions.new()
|
||||
|
||||
var sections: Array[RoutineSection] = []
|
||||
for section: RoutineSection in routine.sections:
|
||||
if section == null:
|
||||
continue
|
||||
if section_id.is_empty() or section.section_id == section_id:
|
||||
sections.append(section)
|
||||
|
||||
var title := routine.title.strip_edges()
|
||||
if title.is_empty():
|
||||
title = "Unbenannte Kür"
|
||||
|
||||
var subtitle := _build_subtitle(routine, sections, section_id)
|
||||
var area := Rect2(
|
||||
MARGIN,
|
||||
HEADER_HEIGHT,
|
||||
PAGE_WIDTH - 2.0 * MARGIN,
|
||||
PAGE_HEIGHT - HEADER_HEIGHT - FOOTER_HEIGHT
|
||||
)
|
||||
var scale := minf(
|
||||
area.size.x / maxf(rink.length_m, 0.001),
|
||||
area.size.y / maxf(rink.width_m, 0.001)
|
||||
)
|
||||
var center := area.position + area.size * 0.5
|
||||
|
||||
var lines := PackedStringArray()
|
||||
lines.append('<?xml version="1.0" encoding="UTF-8"?>')
|
||||
lines.append(
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" width="%s" height="%s" viewBox="0 0 %s %s">'
|
||||
% [_n(PAGE_WIDTH), _n(PAGE_HEIGHT), _n(PAGE_WIDTH), _n(PAGE_HEIGHT)]
|
||||
)
|
||||
lines.append(
|
||||
'<rect x="0" y="0" width="%s" height="%s" fill="#ffffff"/>'
|
||||
% [_n(PAGE_WIDTH), _n(PAGE_HEIGHT)]
|
||||
)
|
||||
lines.append(
|
||||
'<text x="%s" y="%s" font-family="sans-serif" font-size="34" font-weight="bold" fill="%s">%s</text>'
|
||||
% [_n(MARGIN), _n(58.0), TEXT_COLOR, _escape(title)]
|
||||
)
|
||||
lines.append(
|
||||
'<text x="%s" y="%s" font-family="sans-serif" font-size="16" fill="%s">%s</text>'
|
||||
% [_n(MARGIN), _n(88.0), MUTED_TEXT_COLOR, _escape(subtitle)]
|
||||
)
|
||||
|
||||
var outline := _transform_points(rink.get_outline_points(16), scale, center)
|
||||
if outline.size() >= 3:
|
||||
lines.append(
|
||||
'<polygon points="%s" fill="%s" stroke="%s" stroke-width="%s" stroke-linejoin="round"/>'
|
||||
% [
|
||||
_points(outline),
|
||||
ICE_COLOR,
|
||||
BOARDS_COLOR,
|
||||
_n(maxf(2.0, 0.14 * scale)),
|
||||
]
|
||||
)
|
||||
|
||||
var half_width := rink.get_half_width()
|
||||
lines.append(
|
||||
'<line x1="%s" y1="%s" x2="%s" y2="%s" stroke="%s" stroke-opacity="0.35" stroke-width="%s"/>'
|
||||
% [
|
||||
_n(center.x),
|
||||
_n(center.y - half_width * scale),
|
||||
_n(center.x),
|
||||
_n(center.y + half_width * scale),
|
||||
OUTSIDE_COLOR,
|
||||
_n(maxf(1.0, 0.09 * scale)),
|
||||
]
|
||||
)
|
||||
lines.append(
|
||||
'<circle cx="%s" cy="%s" r="%s" fill="none" stroke="#94a3b8" stroke-width="%s"/>'
|
||||
% [
|
||||
_n(center.x),
|
||||
_n(center.y),
|
||||
_n(4.5 * scale),
|
||||
_n(maxf(1.0, 0.05 * scale)),
|
||||
]
|
||||
)
|
||||
|
||||
for section: RoutineSection in sections:
|
||||
for segment: PathSegment in section.segments:
|
||||
if segment == null or segment.curve == null:
|
||||
continue
|
||||
var points := _transform_points(
|
||||
_sample_curve(segment.curve),
|
||||
scale,
|
||||
center
|
||||
)
|
||||
if points.size() < 2:
|
||||
continue
|
||||
|
||||
var color := (
|
||||
OUTSIDE_COLOR
|
||||
if segment.edge == PathSegment.Edge.OUTSIDE
|
||||
else INSIDE_COLOR
|
||||
)
|
||||
var dash := ""
|
||||
if segment.direction == PathSegment.Direction.BACKWARD:
|
||||
dash = ' stroke-dasharray="%s %s"' % [
|
||||
_n(maxf(8.0, 0.35 * scale)),
|
||||
_n(maxf(6.0, 0.2 * scale)),
|
||||
]
|
||||
|
||||
lines.append(
|
||||
'<polyline points="%s" fill="none" stroke="%s" stroke-width="%s" stroke-linecap="round" stroke-linejoin="round"%s/>'
|
||||
% [
|
||||
_points(points),
|
||||
color,
|
||||
_n(maxf(2.0, 0.12 * scale)),
|
||||
dash,
|
||||
]
|
||||
)
|
||||
|
||||
_add_section_badges(lines, sections, scale, center)
|
||||
|
||||
lines.append(
|
||||
'<text x="%s" y="%s" font-family="sans-serif" font-size="14" fill="%s">Vorwärts: durchgezogen · Rückwärts: gestrichelt · Außen: rot · Innen: blau</text>'
|
||||
% [_n(MARGIN), _n(PAGE_HEIGHT - 34.0), MUTED_TEXT_COLOR]
|
||||
)
|
||||
lines.append(
|
||||
'<text x="%s" y="%s" font-family="sans-serif" font-size="14" fill="%s" text-anchor="end">Rinkplanner</text>'
|
||||
% [
|
||||
_n(PAGE_WIDTH - MARGIN),
|
||||
_n(PAGE_HEIGHT - 34.0),
|
||||
MUTED_TEXT_COLOR,
|
||||
]
|
||||
)
|
||||
lines.append("</svg>")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
static func _build_subtitle(
|
||||
routine: Routine,
|
||||
sections: Array[RoutineSection],
|
||||
section_id: String
|
||||
) -> String:
|
||||
if not section_id.is_empty():
|
||||
var section := routine.get_section_by_id(section_id)
|
||||
if section != null:
|
||||
return "%s · %s s" % [
|
||||
section.title,
|
||||
_format_seconds(section.get_duration_seconds()),
|
||||
]
|
||||
return "Abschnitt"
|
||||
|
||||
return "%d Abschnitte · %s s" % [
|
||||
sections.size(),
|
||||
_format_seconds(routine.get_duration_seconds()),
|
||||
]
|
||||
|
||||
|
||||
static func _add_section_badges(
|
||||
lines: PackedStringArray,
|
||||
sections: Array[RoutineSection],
|
||||
scale: float,
|
||||
center: Vector2
|
||||
) -> void:
|
||||
for index: int in range(sections.size()):
|
||||
var section := sections[index]
|
||||
var first_point := Vector2.INF
|
||||
for segment: PathSegment in section.segments:
|
||||
if segment != null and segment.curve != null and segment.curve.point_count > 0:
|
||||
first_point = segment.curve.get_point_position(0)
|
||||
break
|
||||
if first_point == Vector2.INF:
|
||||
continue
|
||||
var point := center + first_point * scale
|
||||
lines.append(
|
||||
'<circle cx="%s" cy="%s" r="12" fill="%s"/>'
|
||||
% [_n(point.x), _n(point.y), TEXT_COLOR]
|
||||
)
|
||||
lines.append(
|
||||
'<text x="%s" y="%s" font-family="sans-serif" font-size="13" font-weight="bold" fill="#ffffff" text-anchor="middle" dominant-baseline="central">%d</text>'
|
||||
% [_n(point.x), _n(point.y), index + 1]
|
||||
)
|
||||
|
||||
|
||||
static func _sample_curve(curve: Curve2D) -> PackedVector2Array:
|
||||
var length := curve.get_baked_length()
|
||||
if length <= 0.0:
|
||||
if curve.point_count == 0:
|
||||
return PackedVector2Array()
|
||||
return PackedVector2Array([curve.get_point_position(0)])
|
||||
|
||||
var steps: int = clampi(
|
||||
ceili(length / CURVE_SAMPLE_STEP_M),
|
||||
2,
|
||||
MAX_CURVE_SAMPLES
|
||||
)
|
||||
var points := PackedVector2Array()
|
||||
points.resize(steps + 1)
|
||||
for index: int in range(steps + 1):
|
||||
points[index] = curve.sample_baked(length * float(index) / float(steps))
|
||||
return points
|
||||
|
||||
|
||||
static func _transform_points(
|
||||
points: PackedVector2Array,
|
||||
scale: float,
|
||||
center: Vector2
|
||||
) -> PackedVector2Array:
|
||||
var transformed := PackedVector2Array()
|
||||
transformed.resize(points.size())
|
||||
for index: int in range(points.size()):
|
||||
transformed[index] = center + points[index] * scale
|
||||
return transformed
|
||||
|
||||
|
||||
static func _points(points: PackedVector2Array) -> String:
|
||||
var parts := PackedStringArray()
|
||||
for point: Vector2 in points:
|
||||
parts.append("%s,%s" % [_n(point.x), _n(point.y)])
|
||||
return " ".join(parts)
|
||||
|
||||
|
||||
static func _n(value: float) -> String:
|
||||
return "%.2f" % value
|
||||
|
||||
|
||||
static func _format_seconds(seconds: float) -> String:
|
||||
return ("%.1f" % seconds).replace(".", ",")
|
||||
|
||||
|
||||
static func _escape(text: String) -> String:
|
||||
return (
|
||||
text
|
||||
.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace('"', """)
|
||||
)
|
||||
1
rinkplanner/src/whiteboard/io/svg_exporter.gd.uid
Normal file
1
rinkplanner/src/whiteboard/io/svg_exporter.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c8no01y5njvnj
|
||||
|
|
@ -47,6 +47,9 @@ const HANDLE_RADIUS_PX := 7.0
|
|||
|
||||
@export var fit_padding_px: float = 32.0
|
||||
@export var drawing_enabled: bool = true
|
||||
@export var presentation_mode: bool = false
|
||||
|
||||
var _presentation_section_filter: String = ""
|
||||
|
||||
var _rink: RinkDimensions = RinkDimensions.new()
|
||||
var _routine: Routine
|
||||
|
|
@ -124,6 +127,16 @@ func set_drawing_enabled(enabled: bool) -> void:
|
|||
_cancel_drawing()
|
||||
|
||||
|
||||
func set_presentation_mode(enabled: bool) -> void:
|
||||
presentation_mode = enabled
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func set_presentation_section_filter(section_id: String) -> void:
|
||||
_presentation_section_filter = section_id
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func set_selection_enabled(enabled: bool) -> void:
|
||||
if _selection_enabled == enabled:
|
||||
return
|
||||
|
|
@ -195,7 +208,8 @@ func fit_rink() -> void:
|
|||
|
||||
|
||||
func _draw() -> void:
|
||||
draw_rect(Rect2(Vector2.ZERO, size), BACKGROUND_COLOR)
|
||||
var background := Color("#ffffff") if presentation_mode else BACKGROUND_COLOR
|
||||
draw_rect(Rect2(Vector2.ZERO, size), background)
|
||||
if _rink == null:
|
||||
return
|
||||
|
||||
|
|
@ -205,7 +219,8 @@ func _draw() -> void:
|
|||
|
||||
_draw_center_line()
|
||||
_draw_center_circle()
|
||||
_draw_selection_highlight()
|
||||
if not presentation_mode:
|
||||
_draw_selection_highlight()
|
||||
_draw_routine()
|
||||
|
||||
if outline.size() >= 3:
|
||||
|
|
@ -219,10 +234,12 @@ func _draw() -> void:
|
|||
true
|
||||
)
|
||||
|
||||
_draw_selection_handles()
|
||||
|
||||
if _playback_visible:
|
||||
_draw_playback_marker()
|
||||
if presentation_mode:
|
||||
_draw_section_badges()
|
||||
else:
|
||||
_draw_selection_handles()
|
||||
if _playback_visible:
|
||||
_draw_playback_marker()
|
||||
|
||||
|
||||
func _draw_center_line() -> void:
|
||||
|
|
@ -261,6 +278,18 @@ func _draw_routine() -> void:
|
|||
if _routine == null:
|
||||
return
|
||||
|
||||
if presentation_mode:
|
||||
for section: RoutineSection in _routine.sections:
|
||||
if section == null:
|
||||
continue
|
||||
if (
|
||||
not _presentation_section_filter.is_empty()
|
||||
and section.section_id != _presentation_section_filter
|
||||
):
|
||||
continue
|
||||
_draw_section(section, 1.0)
|
||||
return
|
||||
|
||||
var highlight_id := _active_section_id
|
||||
if _playback_visible and not _playback_section_id.is_empty():
|
||||
highlight_id = _playback_section_id
|
||||
|
|
@ -275,6 +304,50 @@ func _draw_routine() -> void:
|
|||
_draw_section(highlighted, 1.0)
|
||||
|
||||
|
||||
func _draw_section_badges() -> void:
|
||||
if _routine == null:
|
||||
return
|
||||
|
||||
var font := ThemeDB.fallback_font
|
||||
var font_size := 14
|
||||
for index: int in range(_routine.sections.size()):
|
||||
var section := _routine.sections[index]
|
||||
if section == null:
|
||||
continue
|
||||
if (
|
||||
not _presentation_section_filter.is_empty()
|
||||
and section.section_id != _presentation_section_filter
|
||||
):
|
||||
continue
|
||||
|
||||
var first_point := Vector2.INF
|
||||
for segment: PathSegment in section.segments:
|
||||
if segment != null and segment.curve != null and segment.curve.point_count > 0:
|
||||
first_point = segment.curve.get_point_position(0)
|
||||
break
|
||||
if first_point == Vector2.INF:
|
||||
continue
|
||||
|
||||
var center := _transform.model_to_screen(first_point)
|
||||
draw_circle(center, 12.0, HANDLE_BORDER_COLOR)
|
||||
var text := str(index + 1)
|
||||
var text_size := font.get_string_size(
|
||||
text,
|
||||
HORIZONTAL_ALIGNMENT_LEFT,
|
||||
-1,
|
||||
font_size
|
||||
)
|
||||
draw_string(
|
||||
font,
|
||||
center + Vector2(-text_size.x * 0.5, text_size.y * 0.35),
|
||||
text,
|
||||
HORIZONTAL_ALIGNMENT_LEFT,
|
||||
-1,
|
||||
font_size,
|
||||
Color.WHITE
|
||||
)
|
||||
|
||||
|
||||
func _draw_playback_marker() -> void:
|
||||
var center := _transform.model_to_screen(_playback_position)
|
||||
var radius := clampf(0.45 * _transform.pixels_per_meter, 8.0, 20.0)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -36,3 +36,6 @@ fi
|
|||
|
||||
"$GODOT" --headless --path "$PROJECT_DIR" \
|
||||
--script res://tests/run_timing_tests.gd
|
||||
|
||||
"$GODOT" --headless --path "$PROJECT_DIR" \
|
||||
--script res://tests/run_export_tests.gd
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue