- 物理规则:现行模型仅保留滚动阻力耗能与恢复系数碰撞,风力、空气阻力、静摩擦、动摩擦不再参与运行;确认三球质量 60/330/约890 kg 及水密度、流阻参数 - 定向加速改为真实顶面接触触发的一次性 +5 m/s 速度事件,模型新增渐进式 U 形导槽出口 - 更新球体、滑槽、水/冰/墙、球洞模型与 storybook 目录、物理、实体配置 - 工坊摆放、编辑器、运行适配与检查脚本同步;删除过时的 baseline 三组检查 - 新增谜题设计参考文档、关卡草稿与本轮实验产物
300 lines
19 KiB
GDScript
300 lines
19 KiB
GDScript
extends SceneTree
|
|
|
|
const Maps = preload("res://playtest/tutorial/scripts/maps.gd")
|
|
const OUTPUT = "res://playtest/artifacts/tutorial/"
|
|
var app
|
|
var results: Array = []
|
|
var runs: Array = []
|
|
var failures := 0
|
|
var capture := false
|
|
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(n: int) -> void:
|
|
for i in range(n):await physics_frame
|
|
func click_point(point: Vector2, shift:=false) -> void:
|
|
# Native OS cursor exit events can arrive between screenshots. Explicitly enter
|
|
# for this injected pointer before motion/down/up, just like a real pointer.
|
|
if not pointer_inside:
|
|
root.notify_mouse_entered();pointer_inside=true
|
|
# Dispatch one complete click before yielding: a real OS pointer outside this
|
|
# test window must not insert a mouse-exit between synthetic down and up.
|
|
var move:=InputEventMouseMotion.new();move.position=point;move.shift_pressed=shift;root.push_input(move,true)
|
|
for pressed in [true,false]:
|
|
var event:=InputEventMouseButton.new();event.button_index=MOUSE_BUTTON_LEFT;event.pressed=pressed
|
|
event.shift_pressed=shift;event.position=point;event.button_mask=MOUSE_BUTTON_MASK_LEFT if pressed else 0
|
|
root.push_input(event,true)
|
|
await process_frame;await process_frame
|
|
func click(control: Control) -> void:
|
|
await process_frame;await process_frame
|
|
await click_point(control.get_global_rect().get_center())
|
|
func key(code: Key) -> void:
|
|
for pressed in [true,false]:
|
|
var event:=InputEventKey.new();event.keycode=code;event.pressed=pressed
|
|
root.push_input(event,true);await process_frame
|
|
func snapshot(name: String) -> void:
|
|
if not capture:return
|
|
await process_frame
|
|
# A native window may be occluded while the agent inspects other files. Draw
|
|
# synchronously instead of waiting for a post-draw event that may never fire.
|
|
RenderingServer.force_draw(false)
|
|
RenderingServer.force_sync()
|
|
var picture:Image=root.get_texture().get_image()
|
|
check("capture_"+name,not picture.is_empty() and picture.save_png(ProjectSettings.globalize_path(OUTPUT+name+".png"))==OK)
|
|
func save_json(path: String, value: Variant) -> void:
|
|
var f:=FileAccess.open(OUTPUT+path,FileAccess.WRITE);f.store_string(JSON.stringify(value," "));f.close()
|
|
func await_outcome() -> void:
|
|
for i in range(3600):
|
|
await physics_frame
|
|
if app.solved or app.attempt_done or app.failed:break
|
|
func fresh(index: int) -> void:
|
|
app.started=false;app.unlocked=4;app.open_lesson(index);await frames(3)
|
|
func choose_orientation(id: String, desired: int) -> void:
|
|
if app.erase_mode or app.kind!=id:await click(app.palette_buttons[id])
|
|
var steps:int=(desired-app.quarter+4)%4
|
|
for i in range(steps):await click(app.palette_buttons[id])
|
|
|
|
func reference_position(index:int) -> Vector3:
|
|
return app.lib.vector(Maps.solution(app.lesson)[index].position)
|
|
|
|
func built_at_reference(index:int) -> int:
|
|
var pos:=reference_position(index)
|
|
for i in range(app.records.size()):
|
|
var r:Dictionary=app.records[i]
|
|
if str(r.id).begins_with("built_") and r.position.x==pos.x and r.position.z==pos.z:return i
|
|
return -1
|
|
|
|
func click_slot(index: int, occupied:=false) -> void:
|
|
var point:Vector3=reference_position(index)+Vector3.UP*.001
|
|
var existing:int=built_at_reference(index)
|
|
if occupied and existing>=0:
|
|
var r:Dictionary=app.records[existing]
|
|
point=r.position+Basis(Vector3.UP,-r.quarter*PI/2)*app.lib.path_point(r.kind,.5)
|
|
await click_point(app.camera.unproject_position(point));await frames(2)
|
|
|
|
func assemble_by_gui() -> void:
|
|
for r in Maps.solution(app.lesson):
|
|
var slot:int=int(str(r.id).trim_prefix("built_"))
|
|
await choose_orientation(r.kind,int(r.quarter))
|
|
check("L%d_thumbnail_orientation_%d"%[app.lesson_index+1,slot+1],app.kind==r.kind and app.quarter==r.quarter)
|
|
await click_slot(slot)
|
|
var at:int=built_at_reference(slot)
|
|
check("L%d_one_click_place_%d"%[app.lesson_index+1,slot+1],at>=0 and app.records[at].kind==r.kind and app.records[at].quarter==r.quarter)
|
|
|
|
func run() -> void:
|
|
capture="--capture-tutorial" in OS.get_cmdline_user_args()
|
|
app=load("res://playtest/tutorial/scenes/tutorial.tscn").instantiate();root.add_child(app)
|
|
await frames(4)
|
|
if "--controls-only" in OS.get_cmdline_user_args():
|
|
await check_player_controls();write_report();quit(1 if failures else 0);return
|
|
check("five_progressive_lessons",app.lesson_index==0 and app.unlocked==0 and app.lesson_buttons.slice(1).all(func(b):return b.disabled))
|
|
# Player acceptance: choose palette, click bases, rotate, place, release and advance.
|
|
for index in range(5):
|
|
check("L%d_starts_unsolved"%(index+1),app.lesson_index==index and app.records.all(func(r):return not str(r.id).begins_with("built_")) and not app.solved)
|
|
await snapshot("%02d_initial"%(index+1))
|
|
var before_build_failures:int=failures
|
|
await assemble_by_gui()
|
|
if failures>before_build_failures:write_report();quit(1);return
|
|
check("L%d_authored_layout_valid"%(index+1),app.validate_level(app.encode()).is_empty(),{"error":app.validate_level(app.encode())})
|
|
var layout:Dictionary=app.encode()
|
|
await snapshot("%02d_built"%(index+1))
|
|
await click(app.run_button)
|
|
check("L%d_rest_release_before_boost"%(index+1),app.started and app.release_ticks.size()==1 and app.initial_velocity(0)==Vector3.ZERO,{"button_rect":str(app.run_button.get_global_rect()),"mouse":str(root.get_mouse_position()),"hover":str(root.gui_get_hovered_control()),"disabled":app.run_button.disabled,"failed":app.failed,"solved":app.solved,"status":app.status})
|
|
if not app.started:write_report();quit(1);return
|
|
var before:String=JSON.stringify(app.encode());app.place_current();app.remove_current();app.rotate_current();app.choose_kind("straight")
|
|
check("L%d_running_locks_layout"%(index+1),before==JSON.stringify(app.encode()) and app.erase_button.disabled and app.palette_buttons.values().all(func(b):return b.disabled))
|
|
await await_outcome()
|
|
var required:Array=app.records.filter(func(r):return str(r.id).begins_with("built_")).map(func(r):return r.id)
|
|
check("L%d_gui_solution_enters_goal"%(index+1),app.solved and app.entered.size()==1 and app.lost.is_empty() and app.events.size()==1 and app.events[0].goalId=="goal" and required.all(func(id):return app.contact_ids.has(id)),{"time":app.elapsed,"contacts":app.contact_ids.keys(),"events":app.events})
|
|
if not app.solved:write_report();quit(1);return
|
|
var boosts:Array=app.balls[0].boost_controller.events
|
|
check("L%d_real_launch_block_fires_once"%(index+1),boosts.size()==1 and boosts[0].blockId=="launcher" and is_equal_approx(Vector2(boosts[0].after.x,boosts[0].after.z).length()-Vector2(boosts[0].before.x,boosts[0].before.z).length(),app.Booster.SPEED_GAIN))
|
|
var accepted:Dictionary={"lesson":index+1,"time":app.elapsed,"layout":layout,"input_events":app.interface_events.duplicate(true),"contacts":app.contact_ids.keys(),"goal_events":app.events.duplicate(true),"trace":app.samples.duplicate(true),"launch_boosts":boosts.map(func(e):return {"blockId":e.blockId,"before":app.codec.array_from(e.before),"after":app.codec.array_from(e.after),"tick":e.tick})}
|
|
runs.append(accepted);save_json("%02d_accepted.json"%(index+1),accepted)
|
|
await snapshot("%02d_completed"%(index+1))
|
|
check("L%d_unlocks_next"%(index+1),app.completed.has(index) and app.unlocked==mini(4,index+1))
|
|
if index<4:await click(app.next_button);await frames(3)
|
|
check("all_five_completed",app.completed.size()==5)
|
|
if "--gui-only" in OS.get_cmdline_user_args():
|
|
write_report();quit(1 if failures else 0);return
|
|
# Each blank layout must require construction, and typical mistakes must fail.
|
|
for index in range(5):
|
|
await fresh(index);app.toggle_run();await await_outcome()
|
|
check("L%d_blank_does_not_win"%(index+1),not app.solved)
|
|
for repeat in range(5):
|
|
await fresh(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)})
|
|
app.rebuild();app.reset_simulation();await frames(3);app.toggle_run();await await_outcome()
|
|
check("L%d_repeat_%d"%[index+1,repeat+1],app.solved and app.lost.is_empty(),{"time":app.elapsed})
|
|
for config in [{"index":1,"name":"wrong_turn_orientation","slot":0,"quarter":1},
|
|
{"index":2,"name":"unrotated_corner","slot":0,"quarter":0},
|
|
{"index":3,"name":"slopes_swapped","slot":0,"kind":"steep"},
|
|
{"index":4,"name":"missing_middle","slot":4,"remove":true}]:
|
|
await fresh(config.index)
|
|
var solution:Array=Maps.solution(app.lesson)
|
|
for r in solution:
|
|
if r.id=="built_%d"%config.slot:
|
|
if config.get("remove",false):continue
|
|
if config.has("kind"):r.kind=config.kind
|
|
if config.has("quarter"):r.quarter=config.quarter
|
|
elif config.name=="slopes_swapped" and r.kind=="steep":r.kind="gentle"
|
|
app.records.append({"id":r.id,"kind":r.kind,"position":app.lib.vector(r.position),"quarter":int(r.quarter)})
|
|
app.rebuild();app.reset_simulation();await frames(3);app.toggle_run();await await_outcome()
|
|
check(config.name+"_fails_physically",not app.solved,{"time":app.elapsed,"final":app.codec.array_from(app.balls[0].position)})
|
|
# Editing constraints, recovery and the agreed challenge rules.
|
|
await fresh(4)
|
|
var fixed_before:Array=app.encode().pieces.duplicate(true)
|
|
app.choose_kind("gentle");await click_slot(0)
|
|
await click_slot(1)
|
|
check("inventory_prevents_second_gentle",app.used_count("gentle")==1 and built_at_reference(1)<0)
|
|
app.choose_eraser();await click_slot(0,true)
|
|
check("delete_returns_inventory",app.used_count("gentle")==0)
|
|
check("fixed_pieces_unchanged",app.encode().pieces==fixed_before)
|
|
app.choose_kind("y_merge");check("unlisted_type_rejected",app.kind!="y_merge")
|
|
app.choose_kind("gentle")
|
|
var q:int=app.quarter
|
|
for i in range(4):app.rotate_current()
|
|
check("four_rotations_restore_orientation",app.quarter==q)
|
|
await click_slot(0);var saved:String=JSON.stringify(app.encode());app.toggle_run();await frames(25)
|
|
app.toggle_run();var p:Vector3=app.balls[0].position;await frames(20)
|
|
check("pause_holds_ball",app.paused and app.balls[0].position==p)
|
|
app.toggle_run();await frames(15)
|
|
check("resume_moves_ball",not app.paused and app.balls[0].position.distance_to(p)>.001)
|
|
app.retry_attempt();check("retry_preserves_build_and_counts",app.retries==1 and not app.started and JSON.stringify(app.encode())==saved)
|
|
for i in range(4):app.toggle_run();app.retry_attempt()
|
|
check("fifth_retry_fails_challenge",app.failed and app.retries==5)
|
|
app.open_lesson(4);check("failure_cannot_skip_restart",app.failed and app.lesson_buttons.all(func(b):return b.disabled))
|
|
app.restart_challenge();check("failure_restarts_level_one",app.lesson_index==0 and app.unlocked==0 and app.retries==0 and app.challenge_seconds<1)
|
|
app.challenge_seconds=300;app._process(.01);check("five_minute_limit",app.failed)
|
|
app.restart_challenge();app.choose_kind("gentle");await click_slot(0);app.restart_challenge()
|
|
check("full_restart_clears_build",app.records.all(func(r):return not str(r.id).begins_with("built_")) and app.retries==0)
|
|
write_report();quit(1 if failures else 0)
|
|
|
|
func write_report() -> void:
|
|
var report:Dictionary={"engine":Engine.get_version_info().string,"physics_engine":"Jolt Physics","physics_hz":Engine.physics_ticks_per_second,"rendered_gui":capture,"passed":results.size()-failures,"failed":failures,"results":results,"accepted_runs":runs.map(func(r):return {"lesson":r.lesson,"time":r.time,"input_count":r.input_events.size(),"contacts":r.contacts})}
|
|
save_json("controls_acceptance.json" if "--controls-only" in OS.get_cmdline_user_args() else ("gui_acceptance.json" if capture else "acceptance.json"),report)
|
|
|
|
func check_player_controls() -> void:
|
|
await fresh(4)
|
|
check("bottom_model_thumbnails",app.palette_buttons.size()==4 and app.palette_buttons.values().all(func(b):return b.model!=null and b.artwork.texture!=null and b.get_global_rect().position.y>root.size.y*.7))
|
|
check("toolbar_centered",absf(app.toolbar.get_global_rect().get_center().x-root.get_visible_rect().size.x*.5)<2,{"center":app.toolbar.get_global_rect().get_center().x,"viewport":root.get_visible_rect().size.x,"window":root.size.x})
|
|
check("no_placement_confirmation",app.place_button==null and app.delete_button==null)
|
|
await click(app.palette_buttons.straight)
|
|
check("first_click_selects_without_rotating",app.kind=="straight" and app.quarter==0 and not app.erase_mode)
|
|
var preview_point:Vector3=reference_position(0)+Vector3.UP*.001
|
|
var move:=InputEventMouseMotion.new();move.position=app.camera.unproject_position(preview_point);root.push_input(move,true);await frames(2)
|
|
check("hover_previews_without_spending",built_at_reference(0)<0 and app.used_count("straight")==0 and app.preview_view.get_child_count()>0)
|
|
await click_slot(0)
|
|
check("grid_click_places_immediately",built_at_reference(0)>=0 and app.used_count("straight")==1)
|
|
await click_slot(1)
|
|
check("continuous_placement_keeps_selection",built_at_reference(1)>=0 and app.used_count("straight")==2 and app.kind=="straight" and app.quarter==0)
|
|
var layout:String=JSON.stringify(app.encode())
|
|
await click(app.palette_buttons.straight)
|
|
check("same_thumbnail_rotates_once",app.quarter==1 and app.orientations.straight==1 and is_equal_approx(app.palette_buttons.straight.model.rotation.y,-PI/2))
|
|
check("rotation_does_not_touch_existing_or_stock",JSON.stringify(app.encode())==layout and app.used_count("straight")==2)
|
|
for i in range(3):await click(app.palette_buttons.straight)
|
|
check("four_thumbnail_clicks_return_to_start",app.quarter==0)
|
|
await click(app.palette_buttons.straight)
|
|
await click(app.palette_buttons.gentle)
|
|
await click(app.palette_buttons.straight)
|
|
check("switching_type_restores_its_orientation",app.quarter==1)
|
|
await click_slot(2)
|
|
check("new_placement_uses_rotated_orientation",app.records[built_at_reference(2)].quarter==1 and app.used_count("straight")==3)
|
|
await click(app.erase_button)
|
|
check("eraser_enters_persistent_mode",app.erase_mode)
|
|
await click_slot(0,true)
|
|
check("erase_click_refunds_one",built_at_reference(0)<0 and app.used_count("straight")==2 and app.erase_mode)
|
|
await click_slot(1,true)
|
|
check("continuous_erasing_refunds_next",built_at_reference(1)<0 and app.used_count("straight")==1 and app.erase_mode)
|
|
await click_slot(0)
|
|
check("empty_erase_never_creates_stock",app.used_count("straight")==1 and app.erase_mode)
|
|
layout=JSON.stringify(app.encode())
|
|
for id in ["route_0","goal","stop"]:
|
|
var r:Dictionary=app.records[app.index_for(id)]
|
|
var bounds:AABB=app.lib.record_bounds(r)
|
|
var target:Vector3=bounds.get_center()+Vector3.UP*bounds.size.y*.5
|
|
await click_point(app.camera.unproject_position(target))
|
|
check("fixed_track_and_goal_protected",JSON.stringify(app.encode())==layout)
|
|
await click(app.palette_buttons.straight)
|
|
check("thumbnail_exits_erase_without_rotating",not app.erase_mode and app.quarter==1)
|
|
await choose_orientation("gentle",2);await click_slot(0)
|
|
await click_slot(1)
|
|
check("exhausted_stock_blocks_additional_placement",app.used_count("gentle")==1 and built_at_reference(1)<0)
|
|
await choose_orientation("straight",0);await click_slot(0,true)
|
|
check("replacement_refunds_old_type_atomically",app.used_count("gentle")==0 and app.records[built_at_reference(0)].kind=="straight")
|
|
var count:int=app.used_count("straight");await click_slot(0,true)
|
|
check("reclick_same_piece_does_not_double_spend",app.used_count("straight")==count)
|
|
layout=JSON.stringify(app.encode());await click(app.erase_button);await click(app.palette_buttons.straight)
|
|
check("toolbar_clicks_never_modify_world",JSON.stringify(app.encode())==layout)
|
|
await click(app.run_button);await frames(15)
|
|
check("running_disables_both_tools",app.erase_button.disabled and app.palette_buttons.values().all(func(b):return b.disabled))
|
|
await click(app.erase_button);await click_slot(0,true)
|
|
check("running_grid_click_cannot_erase",JSON.stringify(app.encode())==layout)
|
|
await key(KEY_SPACE);await frames(2)
|
|
check("pause_still_locks_tools",app.paused and app.erase_button.disabled and app.palette_buttons.straight.disabled)
|
|
await click(app.retry_button)
|
|
check("retry_restores_tools_and_keeps_layout",not app.started and not app.erase_button.disabled and JSON.stringify(app.encode())==layout)
|
|
# Earlier lessons retain convenient starting orientations but allow the same gesture.
|
|
await fresh(0);await click(app.palette_buttons.gentle)
|
|
check("first_lesson_default_orientation",app.quarter==2)
|
|
await click(app.palette_buttons.gentle)
|
|
check("first_lesson_uses_same_rotation_gesture",app.quarter==3)
|
|
|
|
await check_free_build()
|
|
|
|
func player_at(point:Vector3) -> Dictionary:
|
|
for r in app.records:
|
|
if str(r.id).begins_with("built_") and r.position.is_equal_approx(point):return r
|
|
return {}
|
|
|
|
func click_world(point:Vector3,attach:=false) -> void:
|
|
await click_point(app.camera.unproject_position(point),attach)
|
|
await frames(2)
|
|
|
|
func check_free_build() -> void:
|
|
await fresh(0)
|
|
app.target=Vector3(-2,3.5,1);app.camera_size=9;app.update_camera()
|
|
var first:=Vector3(-2,3.5,1)
|
|
var second:=Vector3(-2,3.5,2)
|
|
await click(app.palette_buttons.straight)
|
|
check("off_route_cell_is_reachable_initially",app.build_cells.has(first) and not app.build_cells.has(second))
|
|
await click_world(first+Vector3.UP*.014)
|
|
check("click_outside_original_slots_places",not player_at(first).is_empty() and app.used_count("straight")==1)
|
|
await click_world(second+Vector3.UP*.014)
|
|
check("off_route_quota_enforced",player_at(second).is_empty() and app.used_count("straight")==1)
|
|
await click(app.palette_buttons.gentle)
|
|
await click_world(second+Vector3.UP*.014)
|
|
check("extend_from_new_player_piece",not player_at(second).is_empty() and app.used_count("gentle")==1)
|
|
await click(app.erase_button)
|
|
await click_world(second+app.lib.path_point("gentle",.5))
|
|
check("off_route_erase_refunds_stock",player_at(second).is_empty() and app.used_count("gentle")==0)
|
|
await click(app.palette_buttons.gentle)
|
|
var isolated:=Vector3(1,3.5,2)
|
|
await click_world(isolated)
|
|
check("unattached_world_click_rejected",app.used_count("gentle")==0)
|
|
var upper:=first+Vector3.UP
|
|
check("both_vertical_faces_available",app.build_cells.has(upper) and app.build_cells.has(first-Vector3.UP))
|
|
await click_world(first+Vector3.UP*.68,true)
|
|
check("attach_above_owned_track_without_replacing_it",not player_at(upper).is_empty() and not player_at(first).is_empty())
|
|
await click(app.erase_button)
|
|
await click_world(upper+app.lib.path_point("gentle",.5))
|
|
# Look across the low cell so the piece above does not occlude its pick plane.
|
|
app.pitch=.38;app.yaw=PI/2;app.update_camera()
|
|
await click(app.palette_buttons.gentle)
|
|
var lower:=first-Vector3.UP
|
|
await click_world(lower+Vector3.UP*.014)
|
|
check("build_below_existing_piece",not player_at(lower).is_empty())
|
|
await click(app.erase_button)
|
|
await click_world(lower+app.lib.path_point("gentle",.5))
|
|
await click_world(first+app.lib.path_point("straight",.5))
|
|
await click(app.palette_buttons.straight)
|
|
check("erase_retracts_remote_frontier",app.used_count("straight")==0 and app.used_count("gentle")==0 and not app.build_cells.has(second))
|