Files
TheTree_mock/tests/ui/test_layer_presentation.gd
Takeshi 5dde0c5ec2 Record original-alignment implementation and traceability checkpoint
Capture current source, content data, tests, asset licenses, and original-specification traceability. Original implementation remains incomplete. The accepted matching UI generation passed 154 suites and 12,253 checks, with eight rendered staff-contract screens reviewed. Latest native Windows and full-original acceptance remain outstanding.
2026-09-30 23:52:24 +09:00

94 lines
6.3 KiB
GDScript

extends SceneTree
var checks := 0
var failures := 0
func expect(ok: bool, message: String) -> void:
checks += 1
if not ok: failures += 1;push_error(message)
func _initialize() -> void: call_deferred("run")
func run() -> void:
var runtime: Variant=root.get_node("SimulationRuntime")
var clock: Variant=root.get_node("GameClock")
var state: Variant=root.get_node("GameState")
clock.reset(1,6,0);state.reset();runtime.initialize(clock,state,42509);clock.set_paused(true)
var ids := {}
for spec in [[&"reception",Vector3i(-6,0,0)],[&"warehouse",Vector3i(-6,0,1)],[&"staff_waiting_room",Vector3i(-1,0,1)]]:
var result: CommandResult=runtime.submit_command(&"build_facility",{&"definition_id":spec[0],&"origin":spec[1]})
expect(result.is_success(),"build layer fixture %s" % spec[0])
clock.advance_minutes(runtime.definition_registry.get_facility(spec[0]).build_minutes)
for room: Dictionary in runtime.construction_service.get_facilities(): ids[room[&"definition_id"]]=room[&"instance_id"]
var before: Dictionary=runtime.create_snapshot()
root.size=Vector2i(1280,720)
var preview:=WorldPreview.new()
preview.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
preview.set_runtime(runtime)
preview.set_visual_theme(load("res://assets/themes/japanese_fantasy/visual-theme-v1.tres"))
root.add_child(preview);preview.set_process(false)
await process_frame;await process_frame
preview.set_zoom(2)
preview.pan_offset += preview.size*0.5-preview.cell_to_canvas(Vector3i(-3,1,0))
var point:=preview.cell_to_canvas(Vector3i(-5,0,0))
expect(preview._other_layer_rooms().size()==2,"front view includes both visible backyard footprints")
expect(preview.facility_at_canvas(point)==ids[&"reception"],"overlapping backyard ghost does not replace front hit target")
expect(preview.facility_at_canvas(preview.cell_to_canvas(Vector3i(-1,0,0))).is_empty(),"backyard-only ghost cannot be selected from front")
await capture("front")
preview.layer_mode=WorldPreview.LayerMode.BACK
var lens: ColorRect=preview.get_node("LayerLens")
expect(lens.visible and lens.mouse_filter==Control.MOUSE_FILTER_IGNORE,"switch starts noninteractive lens overlay")
expect(preview._other_layer_rooms().size()==1,"back view shows front footprint as wireframe")
expect(preview.facility_at_canvas(point)==ids[&"warehouse"],"switch changes hit target to actual backyard occupant")
expect(preview.cell_to_canvas(Vector3i(-5,0,1))==point,"layer switch preserves zoom and coordinate alignment")
var actor_time: float=preview.get("_animation_time")
preview._process(0.2)
expect(lens.visible and preview.get("_animation_time")==actor_time,"paused game animates lens without animating actors")
await capture("ripple")
preview._process(1.0)
expect(not lens.visible,"transition disables screen-sampling overlay after completion")
await capture("back")
for i in 16:
preview.layer_mode=1-preview.layer_mode
preview._process(0.02)
expect(preview.get_node("LayerLens")==lens,"rapid toggles reuse a single lens instead of accumulating overlays")
preview._process(1)
expect(not lens.visible,"rapid toggles settle into the final layer")
expect(runtime.create_snapshot()==before,"layer visualization and animation leave full simulation snapshot unchanged")
for spec in [[&"premium_room",Vector3i(-6,2,0)],[&"staff_dormitory",Vector3i(-6,2,1)]]:
expect(runtime.submit_command(&"build_facility",{&"definition_id":spec[0],&"origin":spec[1]}).is_success(),"start opposite-layer construction %s" % spec[0])
clock.advance_minutes(5)
var construction_snapshot: Dictionary=runtime.create_snapshot()
preview.layer_mode=WorldPreview.LayerMode.FRONT;preview._process(1)
var back_job := {}
for item: Dictionary in preview._other_layer_rooms():
if item.get(&"building",false): back_job=item
expect(not back_job.is_empty() and back_job[&"definition_id"]==&"staff_dormitory" and back_job[&"progress"]>0,"front view exposes real backyard construction progress")
if back_job.is_empty(): quit(1);return
var back_cells: Array[Vector3i]=runtime.construction_service.get_job(back_job[&"id"]).reserved_cells
expect(back_job[&"rect"]==preview._cell_bounds_rect(back_cells),"ghost construction uses exact reserved geometry")
expect(preview.facility_at_canvas(preview.cell_to_canvas(Vector3i(-6,2,0))).is_empty(),"opposite construction does not become a completed selectable facility")
await capture("front-construction")
preview.layer_mode=WorldPreview.LayerMode.BACK;preview._process(1)
var front_job := {}
for item: Dictionary in preview._other_layer_rooms():
if item.get(&"building",false):front_job=item
expect(not front_job.is_empty() and front_job[&"definition_id"]==&"premium_room","back view exposes front construction")
await capture("back-construction")
expect(runtime.create_snapshot()==construction_snapshot,"construction overlays leave simulation unchanged")
expect(runtime.restore_snapshot(construction_snapshot),"partially built opposite layers restore")
preview.layer_mode=WorldPreview.LayerMode.FRONT;preview._process(1)
expect(preview._other_layer_rooms().any(func(item: Dictionary) -> bool: return item==back_job),"restored construction presentation matches exact prior state")
expect(runtime.submit_command(&"cancel_construction",{&"job_id":back_job[&"id"]}).is_success(),"cancel opposite construction normally")
expect(not preview._other_layer_rooms().any(func(item: Dictionary) -> bool: return item[&"id"]==back_job[&"id"]),"cancelled opposite construction vanishes")
clock.advance_minutes(150)
preview.layer_mode=WorldPreview.LayerMode.BACK;preview._process(1)
var completed_premium:=false
var still_building:=false
for item: Dictionary in preview._other_layer_rooms():
if item[&"definition_id"]==&"premium_room":
completed_premium=true;still_building=bool(item.get(&"building",false))
expect(completed_premium and not still_building,"completion replaces job hatch with finished facility outline")
preview.queue_free();await process_frame
print("Layer presentation: %d checks, %d failures" % [checks,failures]);quit(failures)
func capture(suffix: String) -> void:
if OS.get_environment("THE_TREE_LAYER_CAPTURE")!="1":return
await process_frame;await RenderingServer.frame_post_draw
expect(root.get_texture().get_image().save_png(ProjectSettings.globalize_path("res://artifacts/facility-dimensions-2026-09-29/layer-%s.png" % suffix))==OK,"capture %s layer presentation" % suffix)