Files
windroost/p2_godot_sample/scripts/screen_drag_test.gd
T
wushenghua c4067b3b22 feat: complete reduced-motion and ScreenDrag coverage; fix unscrollable lists
Closed the remaining AGENTS.md accessibility/input checklist items that did
not conflict with the project's own HUD contract.

Reduced motion is a new persisted setting, distinct from low-power: VFX jump
to their final frame, unit sprites hold their frame, hit flashes are off and
damage numbers stay static. A headless test proves each behaviour and that the
setting reaches a live battle HUD.

ScreenDrag coverage builds a genuine ScreenTouch -> ScreenDrag x6 -> release
sequence through Input.parse_input_event. It exposed a real player-facing bug:
the skyport and map ScrollContainers used MOUSE_FILTER_PASS, so touch drags
fell through to the parent and the lists were unscrollable on a device. They
now use MOUSE_FILTER_STOP. Headless Godot cannot simulate real viewport GUI
dispatch, so the test verifies the filter configuration and the real event
sequence, and the report explicitly states that actual scroll movement needs
a device rather than claiming it was proven.

130% text is deliberately NOT implemented: BATTLE_HUD_HIGH_FIDELITY_SPEC.md
lines 12 and 86 fix the slice at 100% and forbid an enlarged-text test. Per
the workspace authority order the project contract wins over the generic
checklist; PRODUCTION/42 records this as an intentional, documented deviation.

tools/run_p2_checks.sh now runs 24 gates; all pass, including the log audit.
2026-11-17 15:39:47 +08:00

124 lines
4.3 KiB
GDScript

extends SceneTree
## ScreenDrag input-path evidence.
##
## AGENTS.md requires real Input.parse_input_event ScreenTouch AND ScreenDrag
## where mobile input is claimed. touch_input_test covers ScreenTouch on the
## battle buttons. This verifies the drag sequence is accepted by the engine
## and that the scrolling pages are configured to RECEIVE it.
##
## Headless Godot does not run real viewport GUI dispatch, so a synthetic
## ScreenDrag cannot be asserted to move a ScrollContainer's scroll_vertical
## here (that needs a device). What we CAN prove locally: the exact real input
## events are constructed and accepted, and the scroll containers use
## MOUSE_FILTER_STOP (not PASS) so drags are not swallowed - which was a real
## bug found by this work: the map/skyport lists were unscrollable on touch.
const OUTPUT_PATH := "res://artifacts/screen_drag_test.json"
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _run() -> void:
var shell := load("res://scenes/game_root.tscn").instantiate() as GameRoot
root.add_child(shell)
await process_frame
await process_frame
# The scroll containers must accept touch drags (STOP, not PASS).
var map_scroll := shell.find_map_scroll_for_test()
var skyport_scroll := shell.find_skyport_scroll_for_test()
_check(map_scroll != null, "map should have a ScrollContainer")
_check(skyport_scroll != null, "skyport should have a ScrollContainer")
if map_scroll != null:
_check(
map_scroll.mouse_filter == Control.MOUSE_FILTER_STOP,
"map ScrollContainer must use MOUSE_FILTER_STOP to receive drags (got %s)" % str(map_scroll.mouse_filter)
)
_record("map_scroll_filter", {"filter": map_scroll.mouse_filter})
if skyport_scroll != null:
_check(
skyport_scroll.mouse_filter == Control.MOUSE_FILTER_STOP,
"skyport ScrollContainer must use MOUSE_FILTER_STOP (got %s)" % str(skyport_scroll.mouse_filter)
)
_record("skyport_scroll_filter", {"filter": skyport_scroll.mouse_filter})
# Build and inject a genuine ScreenTouch -> ScreenDrag* -> release sequence.
var finger := 3
var center := Vector2(195, 278)
var down := InputEventScreenTouch.new()
down.index = finger
down.position = center
down.pressed = true
Input.parse_input_event(down)
await process_frame
var drag_classes: Array = []
for step in range(6):
var drag := InputEventScreenDrag.new()
drag.index = finger
drag.position = center + Vector2(0, -30 * (step + 1))
drag.relative = Vector2(0, -30)
Input.parse_input_event(drag)
drag_classes.append(drag.get_class())
await process_frame
var up := InputEventScreenTouch.new()
up.index = finger
up.position = center + Vector2(0, -180)
up.pressed = false
Input.parse_input_event(up)
await process_frame
_check(drag_classes.size() == 6, "six ScreenDrag events should be injected")
_check(drag_classes.all(func(c: String) -> bool: return c == "InputEventScreenDrag"), "all drag events must be InputEventScreenDrag")
_record("drag_sequence", {
"touch_pressed": true,
"drag_events": drag_classes,
"touch_released": true,
"method": "Input.parse_input_event",
})
root.remove_child(shell)
shell.free()
_finish()
func _finish() -> void:
var passed := _problems.is_empty()
var report := {
"schema": 1,
"kind": "windroost_screen_drag_test",
"headless_note": "viewport GUI dispatch is not simulated headless; actual scroll movement requires a device. Filter config and real event construction are verified here.",
"overall": "PASS" if passed else "FAIL",
"problems": _problems,
"steps": _steps,
}
var artifact_dir := ProjectSettings.globalize_path("res://artifacts")
DirAccess.make_dir_recursive_absolute(artifact_dir)
var file := FileAccess.open(artifact_dir.path_join("screen_drag_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _steps:
print("SCREEN_DRAG_STEP %s" % JSON.stringify(entry))
if passed:
print("SCREEN_DRAG_PASS %d stages verified" % _steps.size())
else:
print("SCREEN_DRAG_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)
func _check(condition: bool, message: String) -> void:
if not condition:
_problems.append(message)
func _record(name: String, data: Dictionary) -> void:
var entry := data.duplicate()
entry["step"] = name
_steps.append(entry)