extends SceneTree const Library=preload("res://runtime/asset_library.gd") const Placement=preload("res://designer/scripts/placement.gd") const Types=preload("res://runtime/chute_types.gd") const Output="res://playtest/artifacts/styled/surface_alignment_report.json" var lib=Library.new() var placement=Placement.new(lib) var results:Array=[] var failures:=0 var pointer_inside:=false func _initialize() -> void: root.mouse_entered.connect(func():pointer_inside=true) root.mouse_exited.connect(func():pointer_inside=false) call_deferred("run") func check(name:String,ok:bool,detail:Dictionary={}) -> void: results.append({"name":name,"passed":ok,"detail":detail}) if not ok:failures+=1 print(("PASS " if ok else "FAIL ")+name+" "+JSON.stringify(detail)) func frames(count:int) -> void: for i in range(count):await physics_frame func click(point:Vector2) -> void: if not pointer_inside:root.notify_mouse_entered();pointer_inside=true for pressed in [true,false]: var event:=InputEventMouseButton.new();event.position=point event.button_index=MOUSE_BUTTON_LEFT;event.pressed=pressed event.button_mask=MOUSE_BUTTON_MASK_LEFT if pressed else 0 root.push_input(event,true) await frames(2) func record(kind:String,position:Vector3,quarter:=0,id:="piece") -> Dictionary: return placement.record_at(kind,position,quarter,id) func seam(candidate:Dictionary,support:Dictionary) -> float: var matches:=placement.connections(candidate,[support]) var error:=INF for match in matches:error=minf(error,absf(match.offset)) return error func run() -> void: # Both ends of both slopes, rotated in every direction, touching a flat top. for kind in ["gentle","steep"]: for quarter in range(4): var base:=record(kind,Vector3(0,2,0),quarter) for port in placement.ports(base): var at:Vector3=port.surface+port.normal*.5;at.y=2 var support:=record("directional_boost",at,0,"launch") var hit:Vector3=port.surface;hit.y=2.7 var bottom:=placement.on_face(support,hit,-port.normal,kind,quarter) var candidate:=record(kind,bottom,quarter) check("%s_q%d_end_%s_flat_join"%[kind,quarter,str(port.normal)],seam(candidate,support)<.00001 and candidate.position.x==0 and candidate.position.z==0,{"bottom_y":bottom.y,"seam_error":seam(candidate,support)}) # Catalog-driven seams include straight, bends, slopes and all three Y ports. var pairs:=0;var pair_failures:Array=[] for kind in Types.IDS: for quarter in range(4): var candidate:=record(kind,Vector3(0,3,0),quarter) for own in placement.ports(candidate): for other_kind in Types.IDS: for other_quarter in range(4): var other:=record(other_kind,Vector3.ZERO,other_quarter,"neighbor") for target in placement.ports(other): if own.normal.dot(target.normal)>-.999:continue var support:Dictionary=other.duplicate(true) support.position=own.surface-target.surface+Vector3.UP*.5 var solved:Dictionary=placement.align_surfaces(candidate,[support]) pairs+=1 if seam(solved,support)>.00001 or solved.quarter!=quarter or solved.kind!=kind: pair_failures.append([kind,quarter,other_kind,other_quarter]) check("all_chute_ports_and_quarters",pair_failures.is_empty(),{"pairs":pairs,"failures":pair_failures}) var launcher:=record("directional_boost",Vector3(-1,2,0),0,"launcher") var slope:=placement.align_surfaces(record("steep",Vector3(0,2,0),2),[launcher]) check("screenshot_reproduces_old_018_lip",absf(seam(record("steep",Vector3(0,2,0),2),launcher)-.18)<.00001) check("screenshot_exact_y_182",absf(slope.position.y-1.82)<.00001 and seam(slope,launcher)<.00001) var reverse_join := placement.align_surfaces(record("directional_boost",launcher.position+Vector3.UP*.5,0,"launcher"),[slope]) check("placing_launcher_second_joins_same_surface",reverse_join.position.is_equal_approx(launcher.position)) var wall:=record("wall",Vector3(-1,2,0),0,"wall") check("top_click_still_stacks",placement.on_face(wall,Vector3(-1,3,0),Vector3.UP,"steep",2)==Vector3(-1,3,0)) check("wall_side_still_bottom_aligned",placement.on_face(wall,Vector3(-.5,2.5,0),Vector3.RIGHT,"wall",0)==Vector3(0,2,0)) check("unconnected_orientation_not_auto_rotated",placement.align_surfaces(record("steep",Vector3(0,2,0),1),[launcher]).position==Vector3(0,2,0)) var tail:=placement.align_surfaces(record("straight",Vector3(1,2,0),0,"tail"),[slope]) check("following_flat_joins_slope_low_end",absf(tail.position.y-1.32)<.00001 and seam(tail,slope)<.00001) check("neighbor_order_does_not_change_height",placement.align_surfaces(slope,[launcher,tail])==placement.align_surfaces(slope,[tail,launcher])) await check_interfaces(launcher) # No direct initial velocity or test-only material overrides: normal iron, # real launcher top contact, real imported solid meshes, all four rotations. for kind in ["gentle","steep"]: for quarter in range(4): for offset in [0.0,-.05,.05]:await roll_across(kind,quarter,offset) var file:=FileAccess.open(Output,FileAccess.WRITE) file.store_string(JSON.stringify({"engine":Engine.get_version_info().string,"passed":results.size()-failures,"failed":failures,"results":results}," "));file.close() quit(1 if failures else 0) func check_interfaces(launcher:Dictionary) -> void: var app=load("res://designer/scenes/workshop.tscn").instantiate();root.add_child(app);await frames(3) app.records=[launcher];app.rebuild() var meshes:Array=app.pieces[0].find_children("*","MeshInstance3D",true,false) check("standalone_launcher_has_rims_and_arrow",meshes.any(func(m):return not str(m.name).begins_with("ink_") and absf(m.mesh.get_aabb().size.y-1.32)<.001) and meshes.any(func(m):return str(m.name).begins_with("ink_boost_arrow_fill"))) app.select_category("chutes");app.kind="steep";app.quarter=2 app.target=Vector3(0,2,0);app.camera_size=8;app.update_camera();await frames(3) await click(app.camera.unproject_position(Vector3(-.499,2.7,0))) check("workshop_mouse_side_pick_aligns",not app.face_pick.is_empty() and absf(app.cursor.y-1.82)<.00001,{"cursor":str(app.cursor)}) app.rotate_current();app.rotate_current() check("rotation_recomputes_same_join",app.quarter==0 and absf(app.cursor.y-2.82)<.00001) app.rotate_current();app.rotate_current() await click(app.place_button.get_global_rect().get_center()) check("workshop_preview_matches_committed_height",app.records.size()==2 and absf(app.records[-1].position.y-1.82)<.00001) var expected:Dictionary=app.records[-1].duplicate(true) var data:Dictionary=app.encode() check("fractional_height_save_load_valid",app.validate_level(data).is_empty(),{"error":app.validate_level(data)}) var path:="res://playtest/artifacts/styled/surface_alignment_saved.json" app.save_level(path);app.load_level(path) check("fractional_height_roundtrip_exact",app.records[app.index_for(expected.id)]==expected) app.select_record(expected.id) check("coordinate_field_keeps_exact_height",absf(app.position_fields[1].value-1.82)<.00001) app.position_fields[1].value=2.17;app.apply_selected() check("manual_coordinates_remain_explicit",absf(app.records[app.index_for(expected.id)].position.y-2.17)<.00001) app.undo();check("undo_preserves_surface_join",absf(app.records[app.index_for(expected.id)].position.y-1.82)<.00001) root.remove_child(app);app.queue_free();await frames(3) app=load("res://playtest/tutorial/scenes/tutorial.tscn").instantiate();root.add_child(app);await frames(3) app.unlocked=4;app.open_lesson(3) app.records=[launcher];app.spawn_specs=[];app.rebuild();app.reset_simulation() app.kind="steep";app.quarter=2;app.refresh_slots() app.target=Vector3(0,2,0);app.camera_size=8;app.update_camera();await frames(3) var screen:Vector2=app.camera.unproject_position(Vector3(0,1.834,0)) app.hover_at(screen) var preview:Vector3=app.preview_view.get_child(0).position await click(screen) var index:int=app.records.size()-1 if app.records.size()>1 else -1 check("player_grid_click_uses_same_algorithm",index>=0 and app.records[index].position.is_equal_approx(expected.position),{"records":app.records.size(),"status":app.status}) check("player_preview_matches_commit",index>=0 and app.records[index].position.is_equal_approx(preview)) root.remove_child(app);app.queue_free();await frames(3) func roll_across(kind:String,quarter:int,offset:float) -> void: var basis:=Basis(Vector3.UP,-quarter*PI/2) var direction:Vector3=basis*Vector3.LEFT # local high end to low end var launch:=record("directional_boost",-direction+Vector3.UP*2,(quarter+2)%4,"launch") var slope:=placement.align_surfaces(record(kind,Vector3.UP*2,quarter,"slope"),[launch]) var tail:=placement.align_surfaces(record("straight",direction+Vector3.UP*2,quarter,"tail"),[slope]) var arena:=Node3D.new();root.add_child(arena) var pieces := [launch,slope,tail] var across := direction.cross(Vector3.UP) for item in pieces: var piece:Node3D=lib.create_piece(item.kind,lib.record_center(item),item.quarter) piece.set_meta("record_id",item.id);arena.add_child(piece) var ball=lib.create_ball();ball.freeze=true;arena.add_child(ball) ball.position=launch.position+Vector3.UP*(1+lib.ball_radius()+.02)+across*offset await frames(3) var mouth:Vector3 = launch.position + Vector3.UP + direction*.5 if offset==0: # Compare both sides 1 mm from the joint, across floor, curved sides and rims. var max_step := 0.0 for z in [-.45,-.32,-.25,-.15,0,.15,.25,.32,.45]: var heights:Array[float]=[] for side in [-1,1]: var sample:Vector3=mouth+across*z+direction*.001*side var ray:=PhysicsRayQueryParameters3D.create(sample+Vector3.UP,sample-Vector3.UP,1) var hit:=arena.get_world_3d().direct_space_state.intersect_ray(ray) heights.append(hit.position.y if not hit.is_empty() else INF) max_step=maxf(max_step,absf(heights[0]-heights[1])) check("%s_q%d_full_mouth" % [kind,quarter],max_step<.003,{"max_step_m":max_step}) ball.freeze=false var entry_speed := -1.0 var contacts:Array=[];var crossed:=false;var time:=0.0 for tick in range(480): await physics_frame;time=(tick+1)/120.0 if entry_speed<0 and (ball.position-mouth).dot(direction)>.06: entry_speed=ball.linear_velocity.dot(direction) for collider in ball.get_colliding_bodies(): var node:Node=collider while node!=null and not node.has_meta("record_id"):node=node.get_parent() if node!=null and node.get_meta("record_id") not in contacts:contacts.append(node.get_meta("record_id")) if ball.position.dot(direction)>1.3 and "tail" in contacts:crossed=true;break if ball.position.y<0:break check("%s_q%d_offset_%.2f_real_ball"%[kind,quarter,offset],entry_speed>lib.Booster.SPEED_GAIN*.5 and crossed and "slope" in contacts and ball.boost_controller.events.size()==1,{"entry_speed_mps":entry_speed,"contacts":contacts,"time":time,"final":str(ball.position),"slope_y":slope.position.y,"tail_y":tail.position.y,"boosts":ball.boost_controller.events.size()}) root.remove_child(arena);arena.queue_free();await frames(3)