OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / scenes / test / gate_save_banner.gd

81 lines · gd ref:
extends SceneTree
## Gate H8 (docs/home-world-design.md §4): when the keet-daemon is gone, the game
## SAYS it is not saving instead of keeping edits in memory and losing them on quit.
##
##   1. daemon running, in a room: no banner
##   2. daemon disconnects while in a room: banner, says edits are not saved
##   3. daemon back: banner gone
##   4. no room selected: no banner even with the daemon down (nothing to save to)
##   5. a durable write REFUSED: the banner names it
##   6. Game adds the banner to its HUD
##
## Signals are emitted by hand; no daemon is touched. Run with
## HYPERTPS_DAEMON_TCP=127.0.0.1:1 so KeetService's own client stays harmless.

const ROOM := "gatebannerroom0000000000000000000000000000000000000000"

var ok := true
var _ran := false
var _finished := false


func _p(c: bool, m: String) -> void:
	print(("ok   " if c else "FAIL: ") + m)
	if not c:
		ok = false


func _process(_delta: float) -> bool:
	if _ran:
		return true
	_ran = true
	_run()
	_p(_finished, "the gate ran to the end (no script error aborted it)")
	print("GATE save_banner: %s" % ("PASS" if ok else "FAIL"))
	quit(0 if ok else 1)
	return true


func _run() -> void:
	var keet: Node = root.get_node_or_null("KeetService")
	var gs: Node = root.get_node_or_null("GameState")
	_p(keet != null and gs != null, "KeetService + GameState autoloads present")
	if keet == null or gs == null:
		return
	var script := load("res://scenes/game/save_banner.gd") as GDScript
	_p(script != null, "scenes/game/save_banner.gd exists")
	if script == null:
		return
	var banner: Label = script.new()
	root.add_child(banner)

	keet.current_room_id = ROOM
	keet.daemon_status_changed.emit("running")
	_p(not banner.visible, "daemon running in a room: no banner")

	keet.daemon_status_changed.emit("disconnected")
	_p(banner.visible, "daemon down in a room: banner shown")
	_p(banner.text.to_lower().contains("not saved") or banner.text.to_lower().contains("not saving"),
			"it says edits are not saved (text=%s)" % banner.text)

	keet.daemon_status_changed.emit("running")
	_p(not banner.visible, "daemon back: banner gone")

	keet.current_room_id = ""
	keet.daemon_status_changed.emit("disconnected")
	_p(not banner.visible, "no room: no banner")

	keet.current_room_id = ROOM
	keet.daemon_status_changed.emit("running")
	gs.write_rejected.emit("world:level:me:op:1", "Not allowed to write world:level:me:op:1")
	_p(banner.visible and banner.text.contains("world:level:me:op:1"),
			"a refused write is named (text=%s)" % banner.text)

	banner.queue_free()
	keet.current_room_id = ""

	# 6. Game puts it in its HUD
	var src := FileAccess.get_file_as_string("res://scenes/game/game.gd")
	_p(src.contains("save_banner.gd"), "game.gd adds the banner to its HUD")
	_finished = true