117 lines
4.9 KiB
GDScript
117 lines
4.9 KiB
GDScript
extends SceneTree
|
|
## Editor-Test (headless): Spielmodus + Checkpoints (V21/V22) — Neu-Dialog,
|
|
## Katalog, Panel mit Undo/Redo, Speichern/Laden. Ausführen:
|
|
## godot --headless --path . --script res://tests/test_modus.gd
|
|
|
|
var failures := 0
|
|
var checks := 0
|
|
var main: Control
|
|
|
|
|
|
func _initialize() -> void:
|
|
_run_all.call_deferred()
|
|
|
|
|
|
func _check(cond: bool, label: String) -> void:
|
|
checks += 1
|
|
if cond:
|
|
print(" ok: %s" % label)
|
|
else:
|
|
failures += 1
|
|
print(" FAIL: %s" % label)
|
|
|
|
|
|
func _signed(d: Dictionary) -> Dictionary:
|
|
var c := d.duplicate(true)
|
|
SvmapIO.sign_map(c)
|
|
return c
|
|
|
|
|
|
func _run_all() -> void:
|
|
print("Testgruppe: Katalog + Neu-Map")
|
|
var tdm := SvmapDocument.create_new("T", 512.0, "mittag")
|
|
_check(not tdm.has("game_mode") and not tdm.has("checkpoints"), "TDM-Map ohne Zusatzfelder (altes Format)")
|
|
_check(SvmapIO.validate_map(_signed(tdm)).is_empty(), "TDM-Map gültig")
|
|
var cp := SvmapDocument.create_new("C", 512.0, "mittag", "checkpoints")
|
|
_check(cp["game_mode"] == "checkpoints" and (cp["checkpoints"] as Array).size() == 3, "Checkpoint-Map mit 3 Start-Zonen")
|
|
_check(SvmapIO.validate_map(_signed(cp)).is_empty(), "Checkpoint-Map gültig: " + str(SvmapIO.validate_map(_signed(cp))))
|
|
var bad := cp.duplicate(true)
|
|
bad["checkpoints"] = []
|
|
_check(not ModusKatalog.validate(bad, bad["bounds"]).is_empty(), "Modus ohne Zonen ungültig (V21)")
|
|
bad = cp.duplicate(true)
|
|
bad["checkpoints"][0]["pos"] = [9999.0, 0.0, 0.0]
|
|
_check(not ModusKatalog.validate(bad, bad["bounds"]).is_empty(), "Zone außerhalb ungültig (V22)")
|
|
bad = cp.duplicate(true)
|
|
bad["checkpoints"][1]["id"] = "C1"
|
|
_check(not ModusKatalog.validate(bad, bad["bounds"]).is_empty(), "doppelte ID ungültig (V22)")
|
|
bad = cp.duplicate(true)
|
|
bad["game_mode"] = "ctf"
|
|
_check(not ModusKatalog.validate(bad, bad["bounds"]).is_empty(), "unbekannter Modus ungültig (V21)")
|
|
|
|
print("Testgruppe: Neu-Dialog")
|
|
var dlg: ConfirmationDialog = preload("res://src/ui/new_map_dialog.gd").new()
|
|
root.add_child(dlg)
|
|
_check(dlg.get_game_mode() == "tdm", "Dialog-Default TDM")
|
|
dlg.mode_option.select(1)
|
|
_check(dlg.get_game_mode() == "checkpoints", "Dialog liefert Checkpoints")
|
|
|
|
print("Testgruppe: Panel")
|
|
var scene: PackedScene = load("res://scenes/main.tscn")
|
|
main = scene.instantiate()
|
|
root.add_child(main)
|
|
await process_frame
|
|
await process_frame
|
|
main.doc = SvmapDocument.create_new("ModusTest", 512.0, "mittag")
|
|
main.history.doc = main.doc
|
|
main.call("_refresh_all")
|
|
var panel: Node = main.map_mod.sections_host().get_node_or_null("modus")
|
|
_check(panel != null, "Modus-Panel hängt im Map-Tab")
|
|
if panel == null:
|
|
quit(1)
|
|
return
|
|
_check(not panel.cp_box.visible, "TDM: Checkpoint-Bereich verborgen")
|
|
panel.set_mode("checkpoints")
|
|
_check(main.doc["game_mode"] == "checkpoints" and main.doc["checkpoints"].size() == 3, "Wechsel auf Checkpoints setzt 3 Zonen")
|
|
_check(panel.cp_box.visible and panel.rows_box.get_child_count() == 3, "3 Zeilen im Panel")
|
|
_check(main.view_builder.checkpoint_root != null and main.view_builder.checkpoint_root.get_child_count() == 3, "3 Zonen im 3D-Bild")
|
|
var id: String = panel.add_checkpoint(50.0, -30.0)
|
|
_check(id == "C4" and main.doc["checkpoints"].size() == 4, "neue Zone C4")
|
|
panel.edit_checkpoint("C4", {"radius_m": 25.0})
|
|
panel.edit_checkpoint("C4", {"x": 80.0, "z": 10.0, "label": "Turm"})
|
|
var c4: Dictionary = main.doc["checkpoints"][3]
|
|
_check(c4["radius_m"] == 25.0 and c4["pos"][0] == 80.0 and c4["pos"][2] == 10.0, "Radius + Position geändert")
|
|
panel.edit_checkpoint("C4", {"radius_m": 500.0})
|
|
_check(main.doc["checkpoints"][3]["radius_m"] == ModusKatalog.MAX_RADIUS, "Radius wird begrenzt")
|
|
_check(SvmapIO.validate_map(_signed(main.doc)).is_empty(), "Map gültig nach Änderungen")
|
|
panel.remove_checkpoint("C4")
|
|
_check(main.doc["checkpoints"].size() == 3, "Zone gelöscht")
|
|
|
|
main.history.undo()
|
|
main.call("_refresh_all")
|
|
_check(main.doc["checkpoints"].size() == 4, "Undo: Zone zurück")
|
|
while main.history.can_undo():
|
|
main.history.undo()
|
|
main.call("_refresh_all")
|
|
_check(not main.doc.has("game_mode") and not main.doc.has("checkpoints") and not panel.cp_box.visible, "Undo bis Start: Felder weg, UI nachgezogen")
|
|
main.history.redo()
|
|
main.call("_refresh_all")
|
|
_check(main.doc.get("game_mode", "") == "checkpoints", "Redo: Modus wieder da")
|
|
|
|
panel.set_mode("tdm")
|
|
_check(not main.doc.has("game_mode"), "Zurück auf TDM entfernt game_mode")
|
|
_check(main.view_builder.checkpoint_root == null, "TDM: keine Zonen im Bild")
|
|
|
|
panel.set_mode("checkpoints")
|
|
var path := "user://modus_test.svmap"
|
|
var doc2 := _signed(main.doc)
|
|
var res := SvmapIO.save_to_file(path, doc2)
|
|
_check(res["ok"], "Speichern ok: " + str(res["errors"]))
|
|
var back := SvmapIO.load_from_file(path)
|
|
_check(back["ok"] and back["data"]["game_mode"] == "checkpoints" and back["data"]["checkpoints"].size() >= 3, "Laden: Modus + Zonen erhalten")
|
|
|
|
if failures == 0:
|
|
print("ALL OK: %d checks" % checks)
|
|
quit(0)
|
|
else:
|
|
print("FAILED: %d/%d checks" % [failures, checks])
|
|
quit(1)
|