OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / scenes / test / gate_curve_overlay.gd

109 lines · gd ref:
extends Node
## GATE — CURVES ARE AN EDITOR OVERLAY (user 2026-10-18: "the cable points seem
## permanently visualized, they dont go away when you press f4").
##   V1  in build mode a curve's wire + points are drawn
##   V2  F4 to play: hidden; back to build: shown again
##   V3  the Curves overlay (Shift+Alt+K) hides them in build mode; again shows them
##   V4  the master switch (Shift+Alt+Z) hides them too, and brings them back
##   V5  a curve made while in PLAY mode is not drawn
##
## RUN AS A SCENE: CI=true "$HYPER_TPS_GODOT" --headless res://scenes/test/gate_curve_overlay.tscn

var fails := 0
var checks := 0
var map: Node3D


func _ok(what: String, cond: bool, note: Variant = "") -> void:
	checks += 1
	if not cond:
		fails += 1
	print("  %-64s %s  %s" % [what, "OK" if cond else "**FAIL**", str(note)])


func _ready() -> void:
	var gs: Node = get_tree().root.get_node_or_null("/root/GameState")
	gs.route("world:level:*", 1, "peer")
	var keet: Node = get_tree().root.get_node_or_null("/root/KeetService")
	if keet != null:
		keet.current_member_id = "gate-author"
	get_tree().root.get_node("/root/GameMode").set_mode("build")
	map = (load("res://scenes/maps/map_dev_test.tscn") as PackedScene).instantiate()
	add_child(map)
	for i in 6:
		await get_tree().process_frame
	await _run()
	get_tree().root.get_node("/root/GameMode").set_mode("play")
	if checks < 8:
		print("  **FAIL** only %d checks ran -- setup died before the assertions" % checks)
		fails += 1
	print("\nGATE curve_overlay: %s (%d checks, %d failed)" % ["PASS" if fails == 0 else "FAIL", checks, fails])
	get_tree().quit(0 if fails == 0 else 1)


func _frames(n: int) -> void:
	for i in n:
		await get_tree().process_frame


func _view() -> Node3D:
	return map.get("_curve_view") as Node3D


func _shown() -> bool:
	var v := _view()
	return v != null and is_instance_valid(v) and v.is_visible_in_tree() and int(map.curve_view_surfaces()) > 0


func _mode(m: String) -> void:
	get_tree().root.get_node("/root/GameMode").set_mode(m)
	await _frames(2)


func _run() -> void:
	var was_curves: bool = map.overlay_on("curves") if map.get("OVERLAYS").has("curves") else true
	var was_all: bool = map.overlays_all_on()
	map.set_overlays_all(true)
	if map.get("OVERLAYS").has("curves"):
		map.set_overlay("curves", true)
	map.create_curve([CurveMath.point(Vector3(0, 1, 0)), CurveMath.point(Vector3(4, 1, 0))])
	await _frames(2)

	# ---- V1 ----
	_ok("V1 build mode: the curve is drawn", _shown(), int(map.curve_view_surfaces()))

	# ---- V2 ----
	await _mode("play")
	_ok("V2 play mode (F4): hidden", not _shown())
	await _mode("build")
	_ok("V2 back in build mode: shown", _shown())

	# ---- V3 ----
	_ok("V3 there is a Curves overlay", map.get("OVERLAYS").has("curves"), (map.get("OVERLAYS") as Dictionary).keys())
	if map.get("OVERLAYS").has("curves"):
		Keymap.run("builder.curves_view")
		await _frames(2)
		_ok("V3 Shift+Alt+K hides the curves in build mode", not _shown())
		Keymap.run("builder.curves_view")
		await _frames(2)
		_ok("V3 again: shown", _shown())

	# ---- V4 ----
	Keymap.run("builder.overlays_all")
	await _frames(2)
	_ok("V4 the master switch hides them", not _shown())
	Keymap.run("builder.overlays_all")
	await _frames(2)
	_ok("V4 and brings them back", _shown())

	# ---- V5 ----
	await _mode("play")
	map.create_curve([CurveMath.point(Vector3(0, 2, 5)), CurveMath.point(Vector3(4, 2, 5))])
	await _frames(2)
	_ok("V5 a curve made in play mode is not drawn", not _shown())
	await _mode("build")

	map.set_overlays_all(was_all)
	if map.get("OVERLAYS").has("curves"):
		map.set_overlay("curves", was_curves)