extends SceneTree var app 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+" "+JSON.stringify(detail)) func settle() -> void: await process_frame await physics_frame await physics_frame func click_screen(at: Vector2) -> void: for down in [true,false]: var e:=InputEventMouseButton.new();e.button_index=MOUSE_BUTTON_LEFT;e.pressed=down;e.position=at e.button_mask=MOUSE_BUTTON_MASK_LEFT if down else 0 root.push_input(e,true);await process_frame await settle() func click_button(control: Control) -> void: app.sidebar_scroll.scroll_vertical=0;await process_frame;await process_frame var y:=control.get_global_rect().get_center().y if y>780:app.sidebar_scroll.scroll_vertical=int(y-650) await process_frame;await process_frame await click_screen(control.get_global_rect().get_center()) func block(kind: String,id: String,bottom: Vector3) -> Dictionary: return app.placement.record_at(kind,bottom,0,id) func load_case(records: Array) -> void: var balls=[{"id":"keep_ball","ballTypeId":"wood_ball","position":[4,3,0]}] app.apply_data(app.codec.encode(records,balls,"Editor tools")) app.target=Vector3(1,1,0);app.camera_size=10;app.update_camera() app.sidebar_scroll.scroll_vertical=0 await settle() func click_block(id: String) -> void: var record: Dictionary=app.records[app.index_for(id)] var bounds: AABB=app.lib.record_bounds(record) var point:=bounds.position+bounds.size*Vector3(.85,.35,.85) var screen: Vector2=app.camera.unproject_position(point) check("target_visible_"+id,screen.x>340 and root.get_visible_rect().has_point(screen),{"screen":screen}) await click_screen(screen) func cleared() -> bool: return app.records.is_empty() and app.spawn_specs.is_empty() and app.pieces.is_empty() and app.goals.is_empty() and app.balls.is_empty() and app.tags.is_empty() and app.world.get_child_count()==0 and app.actors.get_child_count()==0 func run() -> void: app=load("res://designer/scenes/workshop.tscn").instantiate();root.add_child(app) await settle();root.notify_mouse_entered() var labels: Array=app.find_children("*","Button",true,false).map(func(b):return b.text) check("reset_replaces_redo_and_blank_entry",labels.count("重置")==1 and "重做" not in labels and "新建空白" not in labels and "撤销" in labels and "橡皮擦" in labels) var all_kinds: Array=app.IDS.duplicate() for group in app.entity_registry.values(): for entry in group:all_kinds.append(entry.id) for kind in all_kinds: await load_case([block(kind,kind,Vector3.ZERO)]) app.select_ball(0) var before: Dictionary=app.encode() await click_button(app.eraser_tool_button) check("eraser_activation_"+kind,app.block_mode=="erase" and app.eraser_tool_button.button_pressed and app.records.size()==1 and app.selected_ball_id.is_empty() and app.selection.get_child_count()==0 and app.ball_marker.get_child_count()==0) await click_block(kind) check("erase_"+kind,app.records.is_empty() and app.pieces.is_empty() and app.block_mode=="erase" and app.spawn_specs==before.balls) app.undo();await settle() check("undo_erase_"+kind,app.encode()==before) # A click removes only the visible target, including stacked and multi-cell blocks. await load_case([block("wall","lower",Vector3.ZERO),block("wall","upper",Vector3.UP),block("y_merge","wide",Vector3(2,0,2))]) await click_button(app.eraser_tool_button) await click_block("upper") check("stack_erases_only_top",app.index_for("upper")==-1 and app.index_for("lower")>=0 and app.records.size()==2) await click_block("lower") check("eraser_stays_active_for_next_click",app.index_for("lower")==-1 and app.records.size()==1 and app.block_mode=="erase") await click_block("wide") check("multicell_erases_whole_record",app.records.is_empty()) var history: int=app.undo_stack.size() await click_screen(Vector2(1250,700)) await click_screen(app.camera.unproject_position(app.balls[0].position)) check("empty_space_and_balls_are_ignored",app.records.is_empty() and app.spawn_specs.size()==1 and app.undo_stack.size()==history and app.block_mode=="erase" and app.selected_ball_id.is_empty()) await click_button(app.palette_box.get_child(0)) check("ball_palette_exits_eraser",app.block_mode=="place" and not app.eraser_tool_button.button_pressed and app.ball_controls.visible) app.select_category("chutes");await click_button(app.eraser_tool_button) await click_button(app.palette_box.get_child(0)) check("block_palette_exits_eraser",app.block_mode=="place" and app.block_controls.visible) await click_button(app.eraser_tool_button);await click_button(app.category_buttons.nonInteractive) check("category_exits_eraser",app.block_mode=="place") await click_button(app.eraser_tool_button);await click_button(app.eraser_tool_button) check("second_click_exits_eraser",app.block_mode=="place" and not app.eraser_tool_button.button_pressed) # Reset empties every authored object, has no confirmation step and is undoable. var mixed=[block("wall","wall",Vector3.ZERO),block("goal_hole","goal",Vector3(2,0,0)),block("water","water",Vector3(-2,0,0)),block("ice","ice",Vector3(0,0,2))] for phase in ["editing","running","paused"]: await load_case(mixed) var before: Dictionary=app.encode() await click_button(app.eraser_tool_button) if phase!="editing": app.toggle_run();await settle() if phase=="paused":app.toggle_run();await settle() await click_block("wall") check("erase_locked_"+phase,app.records.size()==4 and app.eraser_tool_button.disabled) check("reset_available_"+phase,not app.reset_level_button.disabled) await click_button(app.reset_level_button) check("reset_clears_everything_"+phase,cleared() and not app.started and not app.paused and app.elapsed==0 and app.entered.is_empty() and app.lost.is_empty() and app.block_mode=="place" and app.kind.is_empty() and app.selection.get_child_count()==0 and app.ball_marker.get_child_count()==0) app.undo();await settle() check("undo_reset_"+phase,app.encode()==before and app.records.size()==4 and app.balls.size()==1) # Clearing the editor does not overwrite a saved level on disk. var file_path: String="res://playtest/artifacts/styled/editor_tools_saved.json" app.save_level(file_path) var saved:=FileAccess.get_file_as_string(file_path) await click_button(app.reset_level_button) check("reset_keeps_saved_file",FileAccess.get_file_as_string(file_path)==saved) app.load_level(file_path);await settle() check("saved_level_reloads_after_reset",app.records.size()==4 and app.balls.size()==1) root.remove_child(app);app.queue_free();await process_frame var scene=load("res://playtest/showcase/scenes/showcase.tscn").instantiate();root.add_child(scene) await settle() var before: Dictionary=scene.encode() scene.reset_level() check("reset_tool_is_workshop_only",scene.encode()==before) root.remove_child(scene);scene.queue_free();await process_frame var file:=FileAccess.open("res://playtest/artifacts/styled/editor_tools_report.json",FileAccess.WRITE) file.store_string(JSON.stringify({"passed":results.size()-failures,"failed":failures,"checks":results}," "));file.close() print("EDITOR_TOOLS_REPORT ",results.size()-failures," passed, ",failures," failed") quit(1 if failures else 0)