Files

74 lines
5.7 KiB
GDScript
Raw Permalink Normal View History

extends RefCounted
var failures=0
var checks=0
func check(ok,label):
checks+=1
if not ok:failures+=1;push_error("BUILDING QA: "+label)
func mouse(g,point,pressed):
g.get_viewport().warp_mouse(point);await g.get_tree().process_frame
var motion=InputEventMouseMotion.new();motion.position=point;motion.global_position=point;Input.parse_input_event(motion)
var event=InputEventMouseButton.new();event.position=point;event.global_position=point;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
func key(code,pressed):
var event=InputEventKey.new();event.keycode=code;event.physical_keycode=code;event.pressed=pressed;Input.parse_input_event(event)
func run(g):
await g.get_tree().create_timer(.4).timeout
g.start_game();g.set_process(false);g.reset_shift();g.game_started=true;g.paused=false;g.hud.show();g.menu.show_page("")
var w=g.workshop;g.coins=1000
var d=w.add_station(0,Vector3.ZERO);w.rebuild_nav()
await g.get_tree().physics_frame;await g.get_tree().process_frame
w.toggle_build();var player=g.player.position;var camera=g.camera.position;var clock=w.spawn_clock
key(KEY_D,true);Input.flush_buffered_events();w.update(.2);key(KEY_D,false);Input.flush_buffered_events()
check(g.camera.position.distance_to(camera)>.1 and g.player.position==player,"WASD pans building camera without moving heroine")
check(g.paused and w.spawn_clock==clock,"camera movement does not advance paused simulation")
g.orbit.begin();var yaw=g.orbit.yaw
var motion=InputEventMouseMotion.new();motion.relative=Vector2(30,10);g.orbit.input(motion);w.update(.1);g.orbit.stop()
check(g.orbit.yaw!=yaw and not g.orbit.dragging,"middle mouse rotates while construction is paused")
var wheel=InputEventMouseButton.new();wheel.button_index=MOUSE_BUTTON_WHEEL_UP;wheel.pressed=true
var zoom=g.camera.size;w.input(wheel);check(g.camera.size==zoom-1,"wheel zooms with no selected tool")
w.begin_purchase(0);zoom=g.camera.size;w.input(wheel)
check(w.pending_turns==1 and g.camera.size==zoom,"wheel still rotates selected equipment")
wheel.ctrl_pressed=true;w.input(wheel);check(w.pending_turns==1 and g.camera.size==zoom-1,"Ctrl wheel zooms during placement");w.cancel_placement()
var point=g.camera.unproject_position(Vector3(0,.18,0))
await mouse(g,point,true);w.update(.99)
check(not w.drag.active and w.moving==-1,"short click does not start dragging")
check(not w.context.visible,"click shows no device title panel")
w.update(.02);check(w.drag.active and w.moving==0 and w.drag.strip.visible,"one-second hold starts drag and shows red strip")
check(not w.context.visible,"pickup shows no device title panel")
check(w.context.find_children("*","Button",true,false).all(func(button):return button.text not in ["Переместить","Удалить"]),"move and delete buttons removed")
var target=g.camera.unproject_position(Vector3(3,.18,3));var cash=g.coins
await mouse(g,target,false)
check(w.drag.active and w.moving==0 and w.stations[0].device.position==Vector3.ZERO,"releasing hold keeps device on cursor")
await mouse(g,target,true);await mouse(g,target,false)
check(w.stations.size()==1 and w.stations[0].device.position.distance_to(Vector3(3,0,3))<.01 and g.coins==cash,"release moves equipment without charging or duplicating")
check(not w.drag.active and not w.drag.strip.visible,"drop hides strip")
await g.get_tree().physics_frame;await g.get_tree().process_frame
point=g.camera.unproject_position(Vector3(3,.18,3));await mouse(g,point,true);w.update(1.01)
check(w.drag.active,"second hold starts deletion drag")
var trash=Vector2(800,g.get_viewport().get_visible_rect().size.y-4)
await mouse(g,trash,false)
check(w.stations.is_empty() and g.coins==cash+20,"moving into red strip sells without a click and refunds half of 40")
await mouse(g,Vector2(800,895),false);check(g.coins==cash+20,"extra release cannot duplicate refund")
d=w.add_station(0,Vector3.ZERO);w.rebuild_nav();w.spawn();var s=g.souls.back();s.required=[0];s.entering=false;w.attach(s,0)
w.drag.arm(0,point);check(w.drag.index<0,"occupied apparatus cannot be dragged")
w.selected=0;w.delete_selected();check(w.stations.size()==1,"occupied apparatus cannot be sold")
g.reset_shift();g.game_started=true;g.paused=false;g.coins=1000
d=w.add_station(1,Vector3(2,0,0));w.rebuild_nav()
await g.get_tree().physics_frame;await g.get_tree().process_frame
var imp=g.life.imps[0];imp.root.position=Vector3.ZERO
w.mesh_walking.move_actor(imp.root,Vector3(4,0,0),.20,1.0)
check(imp.root.position.x<1.2,"imp swept capsule cannot walk through apparatus mesh")
for i in range(350):
g.life.move_imp(imp,Vector3(4,0,0),1.0/30)
if i%30==0:await g.get_tree().physics_frame
check(imp.root.position.distance_to(Vector3(4,0,0))<.4,"imp routes around equipment instead of getting stuck")
w.reset();g.paused=false;g.coins=1000;w.unlock=1;imp.root.position=Vector3.ZERO;w.toggle_build();w.begin_purchase(1)
check(w.place(Vector3.ZERO),"apparatus can be placed over current imp location")
check(not w.mesh_walking.blocked(Vector2(imp.root.position.x,imp.root.position.z),.18),"placement relocates imp outside solid geometry")
var neighbour=g.life.neighbours[0];neighbour.root.position=neighbour.origin+Vector3(-.5,0,0)
await g.get_tree().physics_frame;await g.get_tree().process_frame
w.mesh_walking.move_actor(neighbour.root,Vector3(5,0,0),.20,1.0)
check(neighbour.root.position.x<neighbour.origin.x+1.8,"background imp also collides with its visible apparatus")
if failures==0:print("ALL BUILDING TESTS PASSED (%d): paused WASD/MMB camera, zoom/rotation, one-second drag, red-strip sale, half refund, locked devices, imp sweep/routing/placement and neighbour collision"%checks)
g.get_tree().quit(1 if failures else 0)