extends SceneTree var results: Array=[] var failures:=0 var app func _initialize() -> void:call_deferred("run") func check(name: String,ok: bool,detail: Dictionary={}) -> void: results.append({"name":name,"passed":ok,"detail":detail.duplicate(true)}) 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(control: Control) -> void: var point:=control.get_global_rect().get_center() await click_point(point) func click_point(point: Vector2) -> void: for down in [true,false]: var e:=InputEventMouseButton.new();e.button_index=MOUSE_BUTTON_LEFT;e.pressed=down;e.position=point e.button_mask=MOUSE_BUTTON_MASK_LEFT if down else 0 root.push_input(e,true);await process_frame func block(id: String,at: Array=[0,0,0],quarter: int=0) -> Dictionary: return {"id":id,"kind":"directional_boost","position":at,"quarter":quarter} func ball(id: String,at: Array=[0,1.32,0]) -> Dictionary: return {"id":id,"ballTypeId":"iron_ball","position":at} func load_case(entities: Array,balls: Array) -> void: app.apply_data({"schemaVersion":2,"assetFamily":"railbound_inspired","pieces":[],"entities":entities,"balls":balls}) await frames(3) func first_event(body,limit: int=120) -> Dictionary: for i in range(limit): await physics_frame if not body.boost_controller.events.is_empty():return body.boost_controller.events[0] return {} func correct_effect(event: Dictionary,direction: Vector3) -> bool: if event.is_empty():return false var before: Vector3=event.before;var after: Vector3=event.after var expected: Vector3=direction*(Vector2(before.x,before.z).length()+5.0) return Vector3(after.x,0,after.z).distance_to(expected)<.0001 and is_equal_approx(before.y,after.y) func run() -> void: app=load("res://designer/scenes/workshop.tscn").instantiate();root.add_child(app) await frames(3);root.notify_mouse_entered() await click(app.category_buttons.interactive) check("interactive_palette_exposes_boost",app.kind=="directional_boost" and app.boost_controls.is_visible_in_tree()) check("editor_has_fixed_gain_label_and_no_speed_input",app.boost_controls.find_children("*","SpinBox",true,false).is_empty() and app.boost_controls.find_children("*","Label",true,false).any(func(l):return l.text=="固定增速:+5 m/s")) app.quarter=3;app.cursor=Vector3(2,0,-1);app.refresh_selection() var preview=app.selection check("standalone_preview_has_guide_and_arrow",preview.find_children("ink_boost_arrow_fill*","MeshInstance3D",true,false).size()==1 and preview.find_children("directional_boost*","MeshInstance3D",true,false).any(func(m):return is_equal_approx(m.mesh.get_aabb().size.y,1.32))) await click(app.place_button);await frames(3) var id: String=app.last_placed_id check("gui_places_boost_without_gain_override",app.records.size()==1 and not app.records[0].has("speedGain") and app.records[0].quarter==3) check("boost_includes_permanent_guide_bounds",app.lib.record_bounds(app.records[0]).size.is_equal_approx(Vector3(1,1.32,1)) and app.pieces[0].find_children("*","StaticBody3D",true,false).size()==1) app.select_record(id);app.cursor.y=1;await click(app.apply_button) check("gui_moves_selected_boost",app.records[0].position.y==1) app.undo();check("undo_restores_boost_position",app.records[0].position.y==0) app.redo();check("redo_restores_boost_position",app.records[0].position.y==1) app.select_record(id);app.rotate_current() check("rotation_does_not_add_gain_override",app.records[0].quarter==0 and not app.records[0].has("speedGain")) var saved: Dictionary=app.encode() var path: String="res://playtest/artifacts/styled/boost_roundtrip.json" app.save_level(path);app.clear_level() check("boost_save_load_roundtrip",app.load_level(path).is_empty() and JSON.stringify(app.encode())==JSON.stringify(saved)) for value in [0.1,3,10,999]: var old: Dictionary={"schemaVersion":2,"assetFamily":"railbound_inspired","pieces":[],"entities":[block("legacy")],"balls":[ball("test")]} old.entities[0].speedGain=value var legacy_path: String="res://playtest/artifacts/styled/legacy_boost.json" var file=FileAccess.open(legacy_path,FileAccess.WRITE);file.store_string(JSON.stringify(old));file.close() app.reset_simulation() var issue: String=app.load_level(legacy_path) check("legacy_gain_discarded_"+str(value),issue.is_empty() and not app.records[0].has("speedGain") and not app.encode().entities[0].has("speedGain")) await frames(3) # Old runtime metadata must not provide a second route to change the effect. app.pieces[0].set_meta("boost_speed",value) app.toggle_run() var legacy_event:=await first_event(app.balls[0]) check("legacy_gain_still_adds_five_"+str(value),correct_effect(legacy_event,Vector3.RIGHT),legacy_event) # The actual authoring flow: stack the new block, click its top, add a ball, start. await load_case([{"id":"base","kind":"wall","position":[0,0,0],"quarter":0}],[]) app.select_category("interactive");app.cursor=Vector3(0,1,0);app.quarter=1;app.refresh_selection() await click(app.place_button);await frames(3) check("boost_stacks_on_wall",app.records.size()==2 and is_equal_approx(app.lib.record_bounds(app.records[1]).end.y,2.32)) app.select_category("balls");await frames(3) await click_point(app.camera.unproject_position(Vector3(0,2.001,0))) check("mouse_places_ball_on_boost_top",app.ball_cursor.distance_to(Vector3(0,2.32,0))<.02) await click(app.add_ball_button);await frames(3);await click(app.run_button) var authored_event:=await first_event(app.balls[0]) check("authored_start_ball_receives_rotated_boost",correct_effect(authored_event,Vector3.BACK),authored_event) # Real contacts at nonzero position/height, all rotations and incoming directions. for quarter in range(4): var direction:=Basis(Vector3.UP,-quarter*PI/2)*Vector3.RIGHT for incoming in [Vector3.ZERO,direction*2,-direction*2,direction.cross(Vector3.UP)*2]: await load_case([block("launch",[2,1,-1],quarter)],[ball("test",[2,2.32,-1])]) var body=app.balls[0] app.toggle_run();body.linear_velocity=incoming var event:=await first_event(body) check("top_contact_rotation_%d_incoming_%s" % [quarter,incoming],correct_effect(event,direction),event) var at: Vector3=body.position await frames(8) check("moves_along_rotated_arrow_%d_%s" % [quarter,incoming],(body.position-at).dot(direction)>.03) # A wall keeps the fixed-speed ball on the top for prolonged-contact checks. await load_case([block("held"),{"id":"stopper","kind":"wall","position":[1,1,0],"quarter":0}],[ball("rest")]) app.toggle_run();var body=app.balls[0] await first_event(body);await frames(120) check("continuous_contact_does_not_repeat",body.boost_controller.events.size()==1 and absf(body.position.x)<.3 and absf(body.position.y-1.3)<.03,{"events":body.boost_controller.events.size(),"position":body.position}) app.toggle_run();var before: Vector3=body.position;await frames(10) check("pause_freezes_boost_ball",body.position.is_equal_approx(before)) app.toggle_run();await frames(20) check("resume_does_not_retrigger",body.boost_controller.events.size()==1) # Separate fully, then return to the same top as in a looped route. body.position=Vector3(3,3,0);body.linear_velocity=Vector3.ZERO;await frames(5) body.position=Vector3(0,1.32,0);body.linear_velocity=Vector3.ZERO;await frames(40) check("leave_and_reenter_triggers_again",body.boost_controller.events.size()==2) app.reset_simulation();await frames(3) check("reset_clears_trigger_history",app.balls[0].boost_controller.events.is_empty()) app.toggle_run();var reset_event:=await first_event(app.balls[0]) check("reset_allows_start_trigger_again",correct_effect(reset_event,Vector3.RIGHT)) check("running_has_no_speed_control",app.boost_controls.find_children("*","SpinBox",true,false).is_empty()) for config in [{"name":"side","at":[-.95,.5,0],"v":Vector3(3,0,0)}, {"name":"underside","at":[0,-.4,0],"v":Vector3(0,3,0)}, {"name":"hover","at":[0,1.7,0],"v":Vector3.ZERO}]: await load_case([block("solid")],[ball("test",config.at)]) body=app.balls[0];body.gravity_scale=0;app.toggle_run();body.linear_velocity=config.v await frames(90) check(config.name+"_does_not_trigger",body.boost_controller.events.is_empty()) if config.name=="side":check("side_collision_remains_solid",body.position.x<-.75) await load_case([block("shared")],[ball("a",[0,1.32,-.33]),ball("b",[0,1.32,.33])]) app.toggle_run();await frames(70) check("each_ball_triggers_independently",app.balls.all(func(b):return b.boost_controller.events.size()==1)) await load_case([block("first"),block("second",[1,0,0])],[ball("chain",[-.2,1.32,0])]) app.toggle_run();await frames(100) var boosts: Array=app.balls[0].boost_controller.events check("successive_blocks_each_add_five",boosts.size()==2 and correct_effect(boosts[0],Vector3.RIGHT) and correct_effect(boosts[1],Vector3.RIGHT),{"events":boosts}) await load_case([block("covered"),{"id":"cover","kind":"wall","position":[0,1,0],"quarter":0}],[ball("on_cover",[0,2.32,0])]) app.toggle_run();await frames(50) check("covered_top_does_not_trigger_through_wall",app.balls[0].boost_controller.events.is_empty()) app.reset_simulation();app.select_record("covered");app.remove_current();app.undo() check("delete_undo_restores_interactive_block",app.records.any(func(r):return r.id=="covered" and not r.has("speedGain"))) var report=FileAccess.open("res://playtest/artifacts/styled/boost_report.json",FileAccess.WRITE) report.store_string(JSON.stringify({"passed":results.size()-failures,"failed":failures,"results":results}," "));report.close() quit(1 if failures else 0)