Files

135 lines
6.0 KiB
GDScript

extends SceneTree
const State = preload("res://workshop_state.gd")
const Audio = preload("res://lab_audio.gd")
var passed: int = 0
var failures: Array[String] = []
var layouts: Array[Dictionary] = []
func _initialize() -> void:
call_deferred("run")
func check(condition: bool, label: String) -> void:
if condition:
passed += 1
else:
failures.append(label)
printerr("CHECK FAIL: " + label)
func run() -> void:
var state := State.new()
check(state.collect() and state.stock == 1, "manual action changes authoritative stock")
state.stock = state.capacity
check(not state.collect() and state.stock == state.capacity, "full storage rejects collection")
check(state.sell() and state.coins == 10 and state.stock == 0, "selling clears storage and pays once")
check(not state.sell() and state.coins == 10, "empty sale cannot duplicate reward")
check(state.hire() and state.coins == 3 and state.workers == 1, "hire spends resources")
check(not state.hire() and state.workers == 1, "insufficient hire leaves state unchanged")
state.advance(1.0)
check(state.stock == 1, "automation changes stock")
state.stock = 10
state.advance(1.0)
check(state.stock == 10, "automation respects capacity")
state.stock = 6
check(state.craft() and state.coins == 12 and state.stock == 0 and state.heat == 2, "craft commits yield and heat together")
state.stock = 6
check(state.craft() and state.heat == 4, "second craft reaches heat bottleneck")
state.stock = 6
var old := state.snapshot()
check(not state.craft() and state.snapshot() == old, "overheated craft is transactional")
check(state.sell() and state.stock == 0, "sale remains a recovery option during heat bottleneck")
state.advance(1.0)
state.advance(1.0)
state.advance(1.0)
check(state.heat == 3, "five seconds cool one heat")
state.coins = 4
check(state.expand() and state.capacity == 20 and state.coins == 0, "storage expansion costs resources")
state.crafted = 3
check(state.transform() and state.chapter == 1 and state.craft_cost() == 8 and state.workers == 1 and state.capacity == 20, "transformation changes recipe and preserves investment")
check(not state.transform(), "transformation cannot be claimed twice")
var saved := state.snapshot()
var loaded := State.new()
check(loaded.restore(JSON.parse_string(JSON.stringify(saved))) and loaded.snapshot() == saved, "JSON round trip")
for invalid in [null, {}, {"version": 99}, "not a save"]:
check(not loaded.restore(invalid) and loaded.snapshot() == saved, "invalid save is rejected without partial mutation")
for key in ["stock", "coins", "workers", "capacity", "heat", "crafted", "chapter"]:
var bad := saved.duplicate()
bad[key] = -1
check(not loaded.restore(bad) and loaded.snapshot() == saved, "negative field rejected: " + key)
var fractional := saved.duplicate()
fractional.coins = 2.5
check(not loaded.restore(fractional), "fractional resource rejected")
var inconsistent := saved.duplicate()
inconsistent.stock = 21
check(not loaded.restore(inconsistent), "stock above capacity rejected")
var before := loaded.snapshot()
loaded.advance(-100.0)
loaded.advance(NAN)
check(loaded.snapshot() == before, "invalid time cannot grant income")
var wave: AudioStreamWAV = Audio.tone(660.0)
var peak: int = 0
for i in range(0, wave.data.size(), 2):
peak = maxi(peak, absi(wave.data.decode_s16(i)))
check(wave.data.size() == 5292 and peak > 0 and peak <= 6000, "PCM sample has bounded nonzero amplitude")
root.content_scale_size = Vector2i.ZERO
root.size = Vector2i(390, 844)
var ui: Control = load("res://main.tscn").instantiate()
ui.save_enabled = false
root.add_child(ui)
ui.set_process(false)
await process_frame
await process_frame
var collect_button: Button = ui.actions.collect
var point: Vector2 = collect_button.get_global_rect().get_center()
var touch := InputEventScreenTouch.new()
touch.position = point
touch.index = 0
touch.pressed = true
Input.parse_input_event(touch)
await process_frame
touch = InputEventScreenTouch.new()
touch.position = point
touch.index = 0
touch.pressed = false
Input.parse_input_event(touch)
await process_frame
check(ui.touch_events == 2, "parsed ScreenTouch press and release reach input path")
check(ui.model.stock == 1, "parsed touch activates actual GUI collect button")
check(ui.world.pulse > 0.0 and ui.notice.text.contains("Committed"), "accepted action requests visual feedback")
var drag := InputEventScreenDrag.new()
drag.index = 0
drag.position = ui.scroll.get_global_rect().get_center()
drag.relative = Vector2(0, -30)
Input.parse_input_event(drag)
await process_frame
check(ui.drag_events == 1, "parsed ScreenDrag reaches input path; scroll behavior is a separate exercise")
ui.audio.set_muted(true)
var played_before: int = ui.audio.played
ui.audio.emit_cue("collect")
check(ui.audio.played == played_before and ui.audio.pool.size() == 3, "mute suppresses play and voice pool is bounded")
for viewport in [Vector2i(320, 640), Vector2i(390, 844), Vector2i(430, 932)]:
root.size = viewport
for language in [false, true]:
for large in [false, true]:
ui.zh = language
ui.large_text = large
ui.refresh_text()
await process_frame
await process_frame
var bounds: Rect2 = root.get_visible_rect()
var footer_rect: Rect2 = ui.footer.get_global_rect()
var scroll_rect: Rect2 = ui.scroll.get_global_rect()
var fits: bool = bounds.encloses(footer_rect) and scroll_rect.end.y <= footer_rect.position.y + 1.0
for target in ui.actions.values():
fits = fits and target.size.x <= ui.body.size.x + 1.0 and target.size.y >= 48.0
var id := "%dx%d/%s/%s" % [viewport.x, viewport.y, "zh" if language else "en", "130" if large else "100"]
layouts.append({"id": id, "pass": fits, "logical_size": [bounds.size.x, bounds.size.y]})
check(fits, "headless container geometry: " + id)
ui.queue_free()
await process_frame
print("LAB_RESULT " + JSON.stringify({"passed": passed, "failures": failures, "layouts": layouts,
"scope": "headless domain/input/layout/PCM; no normal-render, physical touch, audible playback or human acceptance"}))
quit(0 if failures.is_empty() else 1)