extends SceneTree const Library = preload("res://runtime/asset_library.gd") const Maps = preload("res://playtest/tutorial/scripts/maps.gd") var results: Array = [] var failures := 0 func _initialize() -> void:call_deferred("run") func check(name: String, passed: bool, detail: Dictionary = {}) -> void: results.append({"name":name,"passed":passed,"detail":detail}) if not passed:failures += 1 print(("PASS " if passed else "FAIL ") + name) func check_supported_workshop_goal() -> void: var workshop = load("res://designer/scenes/workshop.tscn").instantiate() root.add_child(workshop) workshop.apply_data({"schemaVersion":2, "pieces":[], "entities":[ {"id":"support", "kind":"wall", "position":[2,0,-1], "quarter":0}, {"id":"hole", "kind":"goal_hole", "position":[2,2,-1], "quarter":0} ], "balls":[{"id":"iron", "ballTypeId":"iron_ball", "position":[2.24,3.2,-1]}]}) await physics_frame workshop.toggle_run() for frame in range(360): await physics_frame var ball = workshop.balls[0] check("workshop_scores_inside_supported_goal", workshop.events.size()==1 and workshop.events[0].goalId=="hole" and workshop.entered.size()==1 and workshop.status.begins_with("全部入洞") and not ball.visible and ball.position.y>1.3, {"events":workshop.events.duplicate(true), "centerY":ball.position.y, "status":workshop.status}) root.remove_child(workshop) workshop.queue_free() func run() -> void: await check_supported_workshop_goal() var lib = Library.new() check("skimming_above_mouth_does_not_score", not lib.crossed_goal(Vector3(-.3,.4,0),Vector3(.3,.3,0),Vector3.ZERO,.3)) check("grazing_throat_edge_does_not_score", not lib.crossed_goal(Vector3(.08,.4,0),Vector3(.08,-1.2,0),Vector3.ZERO,.3)) check("rising_from_below_does_not_score", not lib.crossed_goal(Vector3.DOWN*1.2,Vector3.UP,Vector3.ZERO,.3)) var arena := Node3D.new();root.add_child(arena) var trials: Array = [] var offsets := [Vector2.ZERO,Vector2(.12,0),Vector2(.26,0),Vector2(.36,0), Vector2(-.36,0),Vector2(0,.36),Vector2(0,-.36),Vector2(.24,.24),Vector2(-.24,-.24)] for kind in lib.ball_type_ids(): for offset in offsets: var at := Vector3(trials.size()*3,2,0) arena.add_child(lib.create_piece("goal_hole",at)) var ball = lib.create_ball(kind);ball.freeze=true;arena.add_child(ball) ball.position=at+Vector3(offset.x,1.2,offset.y) trials.append({"name":"drop_%s_%s"%[kind,offset],"ball":ball,"at":at, "previous":ball.position,"entered":false,"contacts":0,"probe":"drop"}) for normal in [Vector3.RIGHT,Vector3.LEFT,Vector3.FORWARD,Vector3.BACK]: var at := Vector3(trials.size()*3,2,0) arena.add_child(lib.create_piece("goal_hole",at)) var ball = lib.create_ball();ball.freeze=true;arena.add_child(ball) ball.gravity_scale=0 ball.position=at-Vector3.UP*.5+normal*1.25+normal.cross(Vector3.UP)*.4 trials.append({"name":"solid_cube_side_%s"%normal,"ball":ball,"at":at, "normal":normal,"probe":"side","minDistance":1.25,"contacts":0}) for i in range(3):await physics_frame for trial in trials: trial.ball.freeze=false if trial.probe=="side":trial.ball.linear_velocity=-trial.normal*3 for frame in range(1200): await physics_frame for trial in trials: var ball = trial.ball if ball.contact_count>0:trial.contacts+=1 if trial.probe=="drop": if trial.entered:continue if lib.crossed_goal(trial.previous,ball.position,trial.at,ball.radius): trial.entered=true;ball.freeze=true trial.previous=ball.position else: trial.minDistance=minf(trial.minDistance,(ball.position-trial.at).dot(trial.normal)) for trial in trials: var passed: bool=trial.entered if trial.probe=="drop" else trial.minDistance>.77 and trial.contacts>0 check(trial.name,passed,{"contactFrames":trial.contacts,"end":str(trial.ball.position-trial.at)}) root.remove_child(arena);arena.queue_free();await process_frame # The larger, solid corners must not obstruct any existing tutorial approach. var app=load("res://playtest/tutorial/scenes/tutorial.tscn").instantiate();root.add_child(app) for index in range(5): app.started=false;app.unlocked=4;app.open_lesson(index) for r in Maps.solution(app.lesson): app.records.append({"id":r.id,"kind":r.kind,"position":app.lib.vector(r.position),"quarter":int(r.quarter)}) if index==0: # Exercise a rolling approach with the exit sealed, as in the workshop. var bottom: Vector3 = app.placement.bottom_of(app.goals[0]) app.records.append({"id":"support","kind":"wall","position":bottom-Vector3.UP,"quarter":0}) app.rebuild();app.reset_simulation() for i in range(3):await physics_frame app.toggle_run() for frame in range(3600): await physics_frame if app.solved or app.attempt_done or app.failed:break check("tutorial_%d_enters_once"%[index+1],app.solved and app.events.size()==1 and app.lost.is_empty(), {"time":app.elapsed,"events":app.events.duplicate(true)}) var file=FileAccess.open("res://playtest/artifacts/styled/goal_block/physics.json",FileAccess.WRITE) file.store_string(JSON.stringify({"passed":results.size()-failures,"failed":failures,"checks":results}," "));file.close() quit(1 if failures else 0)