extends RefCounted var check_number=0 var failures=0 func check(condition): check_number+=1 if not condition: failures+=1 push_error('QA check failed #%d: ' % check_number+str(get_stack())) Engine.get_main_loop().quit(1) func tick(g,seconds): for i in range(ceili(seconds*60)): g.time+=1.0/60 g.workshop.update(1.0/60) func clear_souls(g): for s in g.souls:s.node.queue_free() g.souls.clear();g.held=-1;g.workshop.losses.reset() func run(g): g.set_process(false) var w=g.workshop check(g.paused and g.menu.current_page=="main") g.start_game() check(g.coins==240 and w.stations.is_empty() and g.souls.size()==1) w.upgrade("hire");check(w.helpers.is_empty()) g.essence=6;w.upgrade("hire");w.upgrade("hire") check(w.helpers.size()==1 and g.coins==240 and g.essence==0) w.reset() w.toggle_build();check(w.grid.visible and g.paused) w.begin_purchase(0) var before_sound=w.build_player.stream check(is_instance_valid(w.ghost) and w.stations.is_empty()) check(w.ghost_material.render_priority>g.stage_effects.bokeh.material_override.render_priority) w.pointer_position=g.camera.unproject_position(Vector3(0,.18,0));w.update_preview() check(w.ghost.position==Vector3.ZERO and w.ghost_material.albedo_color.g>.8) w.pointer_position=g.camera.unproject_position(Vector3(-6,.18,-4));w.update_preview() check(w.ghost_material.albedo_color.r>.9 and g.coins==240) check(not w.place(Vector3(-7,0,-3))) check(w.build_player.stream==before_sound) check(g.coins==240) check(w.place(Vector3(0,0,0))) check(w.build_player.stream==w.PLACE_SOUND) check(g.coins==200 and w.stations.size()==1) w.begin_purchase(0);check(not w.place(Vector3(0,0,0))) check(w.place(Vector3(3,0,0))) check(g.coins==160 and w.accessible()) check(not w.valid_position(Vector3(6,0,-4),0)) check(w.snap_to_grid(Vector3(.2,0,.2),0)==w.snap_to_grid(Vector3(.3,0,.3),0)) w.selected=0;w.begin_move();check(w.moving==0) check(is_instance_valid(w.ghost) and not w.stations[0].device.visible) w.cancel_placement() check(w.stations[0].device.visible and w.stations[0].device.position==Vector3.ZERO and not is_instance_valid(w.ghost)) w.selected=0;w.begin_move() check(w.place(Vector3(0,0,3))) check(g.coins==160 and w.stations[0].device.position==Vector3(0,0,3)) var count=g.souls.size();tick(g,5);check(g.souls.size()==count) w.toggle_build();check(not w.grid.visible and not g.paused) print("PASS: starting budget, grid, snapping, bounded placement, overlap rejection, approach paths, free move, construction freezes time") tick(g,32.1) check(w.waiting().size()>0 and w.waiting().size()<7 and w.penalty_gold_lost>0) clear_souls(g) for i in range(7): w.spawn();var queued=g.souls.back();queued.entering=false;queued.entry_time=1;queued.node.position=w.queue_target(i,7) w.spawn_clock=5 check(g.souls.size()==7 and w.waiting().size()==7) for i in range(7):check(g.souls[i].node.position.is_equal_approx(w.queue_target(i,7))) check(not w.spawn()) g.held=g.souls[0].id;g.souls[0].state="held" check(w.queue_load()==7 and not w.spawn()) w.drop_held();check(w.waiting().size()==7) tick(g,3.1);check(w.darkness>0 and w.waiting().size()==7) var darkness=w.darkness g.set_pause(true);tick(g,10);check(w.waiting().size()==7 and is_equal_approx(w.darkness,darkness));g.set_pause(false) clear_souls(g);tick(g,1);check(w.darkness=0 and w.stations[1].soul>=0) check(g.souls.all(func(s):return s.state=="mounted")) check(w.helpers.all(func(h):return h.state=="idle")) w.selected=0;w.begin_move();check(not w.build_mode) w.delete_selected();check(w.stations.size()==2) print("PASS: helpers walk navigable paths, reserve FIFO souls and distinct free devices, deliver; occupied/reserved devices cannot move or delete") var before=g.done for s in w.stations: w.step_station(s,1,false) for i in range(5):w.step_station(s,.5,true) check(g.done==before+2 and g.coins==1024) check(w.stations.all(func(s):return s.cooldown>0)) for s in w.stations:w.step_station(s,3,false) w.toggle_build();w.selected=1;w.delete_selected();w.toggle_build();check(w.stations.size()==1 and g.coins==1044) check(w.build_player.stream==w.REMOVE_SOUND) print("PASS: independent apparatus completion, rewards, burn cooldown, half-price deletion refund") clear_souls(g) for s in w.stations:w.dispose_station(s) w.stations.clear();w.bars.clear() for kind in [1,2,3]: g.development.xp=0 var d=w.add_station(kind,Vector3(1,0,0)) w.spawn();var s=g.souls.back();s.entering=false w.attach(s,0);w.step_station(d,1,false) if kind==1: w.step_station(d,1.1,true);check(d.stage==1) w.step_station(d,1,true);w.step_station(d,.1,false);check(d.elapsed==0) w.step_station(d,2.01,true) elif kind==2:w.step_station(d,5.01,true) else: w.step_station(d,.36,true);check(d.stage==1) w.step_station(d,3.01,true);check(d.cooldown>2) check(d.soul==-1) w.dispose_station(d);w.stations.clear();w.bars.clear() print("PASS: rack tension and continuous hold, wheel rotation, maiden closing/heating and locked burning") g.essence=9;w.upgrade("haste");w.upgrade("auto");check(w.helper_speed==1 and w.automation) var dev=w.add_station(0,Vector3(0,0,0));w.rebuild_nav() w.spawn();g.souls.back().entering=false;g.souls.back().entry_time=1 for h in w.helpers:h.state="idle";h.soul=-1;h.station=-1 await g.get_tree().physics_frame await g.get_tree().physics_frame for i in range(2400): w.update_helpers(1.0/60);w.step_station(dev,1.0/60,dev.operator>=0) check(dev.soul==-1 and g.souls.is_empty()) var snap=g.progress_snapshot();check(snap.workshop.stations.size()==1 and snap.workshop.helpers==2 and snap.workshop.automation) check(g.Progression.decode(snap,g.build_id).workshop.helpers==2) check(g.Progression.write_save("user://qa_workshop_v013.json",snap)==OK) var restored=g.Progression.read_save("user://qa_workshop_v013.json",g.build_id) DirAccess.remove_absolute(ProjectSettings.globalize_path("user://qa_workshop_v013.json")) w.reset();w.restore(restored.workshop) check(w.stations.size()==1 and w.helpers.size()==2 and w.automation and w.helper_speed==1) w.toggle_tree();check(w.tree.visible and g.paused and w.node_buttons.size()==14 and w.node_buttons.all(func(n):return not n.key.begins_with("tool"))) w.toggle_tree();check(not g.paused) test_rotation(g) g.reset_shift();check(w.stations.is_empty() and w.helpers.is_empty() and g.coins==240 and w.unlock==0) print("PASS: soul-funded helper upgrades, autonomous operation after training, layout save schema, three-column skill tree, clean new game") if failures==0:print("ALL WORKSHOP TESTS PASSED — DEMON 0.19") g.get_tree().quit(1 if failures else 0) func test_rotation(g): var w=g.workshop w.reset();g.coins=1000;w.unlock=3;w.toggle_build();w.begin_purchase(1) var coins=g.coins for i in range(4):w.rotate_pending(1) check(w.pending_turns==0 and g.coins==coins) w.rotate_pending(1) check(w.footprint(1,1)==Vector2i(4,3) and is_equal_approx(w.ghost.rotation.y,PI/2)) var p=w.snap_to_grid(Vector3(1,0,.5),1,w.pending_turns) check(w.place(p)) var d=w.stations[0] check(d.turns==1 and is_equal_approx(d.device.rotation.y,PI/2)) check(w.approach(d).is_equal_approx(p+Vector3(2.55,0,0))) check(w.station_rect(d).size==Vector2(4,3) and w.accessible()) w.selected=0;w.begin_move();w.rotate_pending(-1);w.cancel_placement() check(d.turns==1 and is_equal_approx(d.device.rotation.y,PI/2) and d.device.visible) w.selected=0;w.begin_move();w.rotate_pending(1) check(w.place(Vector3(1.5,0,0))) check(d.turns==2 and w.station_rect(d).size==Vector2(3,4)) var saved=w.snapshot() w.toggle_build();w.reset();w.restore(saved) check(w.stations[0].turns==2 and is_equal_approx(w.stations[0].device.rotation.y,PI)) print("PASS: four wheel orientations, rotated footprint and approach, navigation, cancel/commit, saved orientation; placement/deletion sound routing") func click(g,control): await g.get_tree().process_frame var p=control.get_global_rect().get_center() var motion=InputEventMouseMotion.new();motion.position=p;motion.global_position=p;Input.parse_input_event(motion) var event=InputEventMouseButton.new();event.position=p;event.global_position=p;event.button_mask=MOUSE_BUTTON_MASK_LEFT;event.button_index=MOUSE_BUTTON_LEFT;event.pressed=true Input.parse_input_event(event) await g.get_tree().process_frame event=InputEventMouseButton.new();event.position=p;event.global_position=p;event.button_index=MOUSE_BUTTON_LEFT;event.pressed=false;Input.parse_input_event(event) await g.get_tree().process_frame func run_ui(g): await g.get_tree().create_timer(.3).timeout await click(g,g.menu.main_start) check(g.game_started and not g.paused) await click(g,g.workshop.build_button) check(g.workshop.build_mode and g.workshop.grid.visible) await click(g,g.workshop.buy_buttons[0]);check(g.workshop.pending==0) var p=g.camera.unproject_position(Vector3(0,.18,0)) var zoom=g.camera.size var wheel=InputEventMouseButton.new();wheel.position=p;wheel.global_position=p;wheel.button_index=MOUSE_BUTTON_WHEEL_UP;wheel.pressed=true Input.parse_input_event(wheel);await g.get_tree().process_frame check(g.workshop.pending_turns==1 and is_equal_approx(g.camera.size,zoom)) var motion=InputEventMouseMotion.new();motion.position=p;motion.global_position=p;Input.parse_input_event(motion) var e=InputEventMouseButton.new();e.position=p;e.global_position=p;e.button_mask=MOUSE_BUTTON_MASK_LEFT;e.button_index=MOUSE_BUTTON_LEFT;e.pressed=true Input.parse_input_event(e);await g.get_tree().process_frame e=InputEventMouseButton.new();e.position=p;e.button_index=MOUSE_BUTTON_LEFT;e.pressed=false;Input.parse_input_event(e);await g.get_tree().process_frame check(g.workshop.stations.size()==1) p=g.camera.unproject_position(Vector3(0,.18,0));g.get_viewport().warp_mouse(p) await g.get_tree().process_frame motion=InputEventMouseMotion.new();motion.position=p;motion.global_position=p;Input.parse_input_event(motion) e=InputEventMouseButton.new();e.position=p;e.global_position=p;e.button_index=MOUSE_BUTTON_LEFT;e.pressed=true;Input.parse_input_event(e) await g.get_tree().create_timer(1.1).timeout check(g.workshop.moving==0 and g.workshop.drag.strip.visible) check(is_instance_valid(g.workshop.ghost) and not g.workshop.stations[0].device.visible) var motion_target=g.camera.unproject_position(Vector3(2,.18,3)) var movement=InputEventMouseMotion.new();movement.position=motion_target;movement.global_position=motion_target Input.parse_input_event(movement);await g.get_tree().process_frame check(g.workshop.ghost.position==g.workshop.snap_to_grid(Vector3(2,0,3),0)) var key=InputEventKey.new();key.keycode=KEY_ESCAPE;key.pressed=true;Input.parse_input_event(key);await g.get_tree().process_frame check(g.workshop.pending==-1 and g.workshop.stations.size()==1) check(g.workshop.stations[0].device.visible and not is_instance_valid(g.workshop.ghost)) e=InputEventMouseButton.new();e.position=p;e.button_index=MOUSE_BUTTON_LEFT;e.pressed=false;Input.parse_input_event(e);await g.get_tree().process_frame await click(g,g.workshop.build_button) var w=g.workshop;var d=w.stations[0] w.click_station(0);check(not w.context.visible) w.attach(g.souls[0],0);d.placement=0;g.souls[0].node.position=d.device.position g.player.position=w.approach(d) for i in range(5): await click_world(g,g.camera.unproject_position(d.device.position+Vector3(0,1,0))) check(not w.context.visible and not w.build_mode and not g.paused and w.pending<0) w.step_station(d,.5,false) check(g.done==1 and d.soul==-1) w.step_station(d,3,false) await click(g,w.build_button) g.workshop.click_station(0) var build_mouse=preload("res://building_tests.gd").new() await build_mouse.mouse(g,g.camera.unproject_position(d.device.position+Vector3(0,.18,0)),true) w.update(1.01) await build_mouse.mouse(g,Vector2(800,g.get_viewport().get_visible_rect().size.y-4),false) check(g.workshop.stations.is_empty() and g.coins==232) await click(g,g.workshop.build_button);check(not g.paused) g.essence=6;g.workshop.toggle_tree();await g.get_tree().process_frame check(g.workshop.tree.visible) await click(g,g.workshop.node_buttons.filter(func(n):return n.key=="hire")[0].button) check(g.workshop.helpers.size()==1) g.workshop.toggle_tree() g.set_pause(true);check(g.menu.current_page=="pause") print("PASS: actual mouse input buys/places a device, one-second hold moves, Esc cancels, build button resumes, grimoire recruits helper, pause opens") print("PASS: five clicks on mounted soul complete work without construction/context UI; mesh follows pointer, cancellation restores original") g.get_tree().quit() func click_world(g,p): var motion=InputEventMouseMotion.new();motion.position=p;motion.global_position=p;Input.parse_input_event(motion) for pressed in [true,false]: var event=InputEventMouseButton.new();event.position=p;event.global_position=p;event.button_index=MOUSE_BUTTON_LEFT;event.pressed=pressed event.button_mask=MOUSE_BUTTON_MASK_LEFT if pressed else 0 Input.parse_input_event(event) await g.get_tree().process_frame