P08-03: 配置の通常操作受入
This commit is contained in:
+165
@@ -0,0 +1,165 @@
|
||||
extends "res://tests/fixtures/p08-03/placement.gd"
|
||||
## Passive endpoint implementation. All gameplay/input is performed by Root CUA.
|
||||
## Shared parent contains the handler endpoints, but every such endpoint below
|
||||
## is overridden; this class never emits UI signals or invokes product handlers.
|
||||
var receipts: Array = []
|
||||
var all_requests: Array = []
|
||||
var input_observer: Node
|
||||
|
||||
class InputObserver extends Node:
|
||||
var events: Array = []
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton or event is InputEventKey:
|
||||
var row := {"ticks_usec": Time.get_ticks_usec(), "text": event.as_text(), "pressed": event.is_pressed()}
|
||||
if event is InputEventMouseButton:
|
||||
row["button"] = event.button_index
|
||||
row["position"] = [event.position.x, event.position.y]
|
||||
row["ctrl"] = event.ctrl_pressed
|
||||
events.append(row)
|
||||
|
||||
func request(action: Dictionary) -> void:
|
||||
serial += 1
|
||||
var stem := "%s-request-%04d" % [role, serial]
|
||||
var folder := directory.path_join(stem)
|
||||
DirAccess.make_dir_recursive_absolute(folder)
|
||||
var window: Window = main.get_window()
|
||||
action.merge({"sequence": serial, "target_pid": OS.get_process_id(), "role": role,
|
||||
"state": "waiting_for_root_cua", "window_title": window.title,
|
||||
"window_position": [window.position.x, window.position.y],
|
||||
"window_size": [window.size.x, window.size.y], "screen_scale": DisplayServer.screen_get_scale(window.current_screen),
|
||||
"content_scale_factor": window.content_scale_factor, "setup": "diagnostic"})
|
||||
json_file(stem + "/request.json", action)
|
||||
var path := folder.path_join("ack.json")
|
||||
var first_event: int = input_observer.events.size()
|
||||
var deadline := Time.get_ticks_msec() + 300000
|
||||
print("P08_ROOT_CUA_WAIT " + folder.path_join("request.json"))
|
||||
while not FileAccess.file_exists(path) and Time.get_ticks_msec() < deadline:
|
||||
await tree.process_frame
|
||||
if not FileAccess.file_exists(path):
|
||||
expect(false, "Root CUA acknowledgement timeout")
|
||||
tree.quit(1)
|
||||
return
|
||||
var ack: Variant = JSON.parse_string(FileAccess.get_file_as_string(path))
|
||||
if not ack is Dictionary or ack.get("target_pid") != OS.get_process_id() or ack.get("sequence") != serial or ack.get("request_sha256") != FileAccess.get_sha256(folder.path_join("request.json")):
|
||||
expect(false, "Root CUA acknowledgement identity/hash")
|
||||
tree.quit(1)
|
||||
return
|
||||
await frames()
|
||||
json_file(stem + "/observed.json", {"pid": OS.get_process_id(), "sequence": serial,
|
||||
"events": input_observer.events.slice(first_event), "status": main.build_status_label.text})
|
||||
receipts.append("os-pair/" + stem + "/ack.json")
|
||||
all_requests.append("os-pair/" + stem + "/ack.json")
|
||||
|
||||
func annotate(row: Dictionary) -> void:
|
||||
row["input_method"] = "native_os"
|
||||
row["requests"] = receipts.duplicate()
|
||||
receipts.clear()
|
||||
|
||||
func point(node: Control) -> Dictionary:
|
||||
var viewport: Vector2 = node.get_global_transform_with_canvas() * (node.size * 0.5)
|
||||
var screen: Vector2 = node.get_screen_transform() * (node.size * 0.5)
|
||||
return {"node": String(node.get_path()), "viewport": [viewport.x, viewport.y], "screen": [screen.x, screen.y], "window_id": node.get_window().get_window_id()}
|
||||
|
||||
func setup() -> void:
|
||||
input_method = "native_os"
|
||||
expect(DisplayServer.get_name() != "headless", "OS recorder requires a real display")
|
||||
main = load("res://scenes/main/main.tscn").instantiate()
|
||||
tree.root.add_child(main)
|
||||
tree.root.title = "The Tree P08-03 " + role + " PID " + str(OS.get_process_id())
|
||||
input_observer = InputObserver.new()
|
||||
tree.root.add_child(input_observer)
|
||||
await frames()
|
||||
json_file(role + "-profile.json", {"pid": OS.get_process_id(), "user_data_dir": OS.get_user_data_dir(), "engine": Engine.get_version_info(), "display": DisplayServer.get_name()})
|
||||
if role == "writer":
|
||||
await load_menu(main.find_child("SaveLoadMenu", true, false))
|
||||
var stored: Dictionary = SaveService.inspect_snapshot(ProjectSettings.globalize_path(String(main.manual_save_path)))
|
||||
expect(bool(stored.get("ok", false)), "read-only initial formal inspection")
|
||||
expect(runtime.create_snapshot() == stored.get("snapshot", {}), "OS initial formal model exact")
|
||||
expect(clock.paused, "diagnostic formal fixture starts paused")
|
||||
|
||||
func diagnostic_budget() -> void:
|
||||
budget = JSON.parse_string(FileAccess.get_file_as_string(directory.path_join("diagnostic-budget.json")))
|
||||
|
||||
func save_initial_fixture() -> void:
|
||||
# The controller copied the handler's SHA-pinned formal diagnostic fixture.
|
||||
# Root loaded it using the normal menu. No model/setup mutation here.
|
||||
pass
|
||||
|
||||
func reveal(node: Control) -> void:
|
||||
await request({"action": "reveal_palette", "node": String(node.get_path()),
|
||||
"instructions": "Scroll the normal palette until this button is visible. Do not activate it yet."})
|
||||
|
||||
func button(node: BaseButton) -> void:
|
||||
expect(node != null and not node.disabled, "available production button")
|
||||
if node == null or node.disabled:
|
||||
return
|
||||
# Native modal windows own a separate input viewport.
|
||||
var old_observer: Node = input_observer
|
||||
if node.get_window() != main.get_window():
|
||||
input_observer = InputObserver.new()
|
||||
node.get_window().add_child(input_observer)
|
||||
var action := point(node)
|
||||
action.merge({"action": "button", "instructions": "Click the named button through CUA; capture before/after screenshots."})
|
||||
await request(action)
|
||||
if input_observer != old_observer:
|
||||
input_observer.queue_free()
|
||||
input_observer = old_observer
|
||||
|
||||
func click(cell: Vector3i) -> Dictionary:
|
||||
var view: WorldPreview = main.world_preview
|
||||
for attempt: int in range(8):
|
||||
if Rect2(Vector2.ZERO, view.size).has_point(view.cell_to_canvas(cell)):
|
||||
break
|
||||
var framing := point(view)
|
||||
framing.merge({"action": "framing", "world_cell": vector(cell), "instructions": "Use ordinary zoom-out at the preview center until the requested world cell is visible; coordinates will be recomputed after ack."})
|
||||
await request(framing)
|
||||
expect(Rect2(Vector2.ZERO, view.size).has_point(view.cell_to_canvas(cell)), "OS target visible after normal framing")
|
||||
var local := view.cell_to_canvas(cell)
|
||||
var viewport := view.get_global_transform_with_canvas() * local
|
||||
var screen := view.get_screen_transform() * local
|
||||
observed_cell = null
|
||||
await request({"action": "cell", "world_cell": vector(cell), "viewport": [viewport.x, viewport.y],
|
||||
"screen": [screen.x, screen.y], "instructions": "Click this transformed world-cell center. If clipped, use normal zoom/pan first and request a new collection; never substitute fixed pixels."})
|
||||
var selected: Variant = observed_cell
|
||||
if not selected is Vector3i:
|
||||
# With no active build tool, the normal preview selects a facility.
|
||||
var occupant: StringName = runtime.world_service.get_occupant(cell)
|
||||
expect(not occupant.is_empty() and view.selected_entity_id == occupant, "actual OS facility selection")
|
||||
selected = view.canvas_to_cell(view.get_local_mouse_position())
|
||||
expect(selected is Vector3i and selected == cell, "observed OS selected cell")
|
||||
return {"world_cell": vector(cell), "selected_cell": vector(selected) if selected is Vector3i else [],
|
||||
"local": [local.x, local.y], "viewport": [viewport.x, viewport.y],
|
||||
"viewport_transform": affine(view.get_global_transform_with_canvas()),
|
||||
"screen": [screen.x, screen.y], "screen_transform": affine(view.get_screen_transform()),
|
||||
"map_position": [view.get_map_rect().position.x, view.get_map_rect().position.y],
|
||||
"cell_dimensions": [view.get_cell_rect(cell).size.x, view.get_cell_rect(cell).size.y],
|
||||
"bounds": runtime.world_service.get_bounds(), "zoom": view.zoom_level,
|
||||
"pan": [view.pan_offset.x, view.pan_offset.y]}
|
||||
|
||||
func wheel(event: InputEventMouseButton, move_mode: bool) -> void:
|
||||
var action := point(main.world_preview)
|
||||
action.merge({"action": "wheel", "direction": "up" if event.button_index == MOUSE_BUTTON_WHEEL_UP else "down",
|
||||
"ctrl": false, "move_mode": move_mode, "instructions": "Send one ordinary wheel step at the preview center without Ctrl; retain the CUA receipt."})
|
||||
await request(action)
|
||||
|
||||
func complete_build(id: StringName) -> void:
|
||||
await request({"action": "complete_construction", "definition": String(id),
|
||||
"minutes": runtime.definition_registry.get_facility(id).build_minutes,
|
||||
"instructions": "Use normal speed/play controls, wait for construction completion, then pause. No injected clock or model changes."})
|
||||
expect(clock.paused, "Root paused after ordinary construction progression")
|
||||
|
||||
func load_menu(menu: MenuButton) -> void:
|
||||
var action := point(menu)
|
||||
action.merge({"action": "load_menu", "item_id": 0, "instructions": "Open this normal menu and choose manual load (item 0)."})
|
||||
await request(action)
|
||||
|
||||
func archive_formal() -> void:
|
||||
DirAccess.make_dir_recursive_absolute(directory.path_join("formal"))
|
||||
for member: String in MEMBERS:
|
||||
var source := ProjectSettings.globalize_path(String(main.manual_save_path)).path_join(member)
|
||||
var destination := directory.path_join("formal/" + member)
|
||||
expect(DirAccess.copy_absolute(source, destination) == OK, "archive formal " + member)
|
||||
expect(FileAccess.get_sha256(source) == FileAccess.get_sha256(destination), "archive formal SHA " + member)
|
||||
|
||||
func finish_observations() -> void:
|
||||
json_file(role + "-requests.json", {"pid": OS.get_process_id(), "requests": all_requests})
|
||||
Reference in New Issue
Block a user