Files
windroost/p2_godot_sample/scripts/touch_input_test.gd
T
wushenghua a0c590deec feat: add animated units, real touch input and the runtime economy loop
Continues the MVP work from the UI and numbers baseline.

Animation. The frame runs were already in the repository but had never been
packed for runtime use. pack_animation_strip.py now derives one shared scale
and one shared foot line from the union of every frame in a state, so the
character does not jitter between frames; H01 idle/attack, EG01 idle/hit and
B01 idle/hit are packed as transparent fixed-grid atlases. UnitView plays
them with the node origin on the foot line, loops idle, plays hit once and
falls back, and flashes on damage. Content-to-art bindings live in the
content fixture, so no character id is hardcoded in the HUD.

Touch. The previous HUD used gui_input callbacks, which is not proof of a
mobile input path. run_touch_test.sh now feeds InputEventScreenTouch through
Input.parse_input_event and checks that taps on the tap toggle, an enemy card
and the storm button produce the right events on the right tick. It also
caught a real bug: Godot emulates mouse presses from touches, so one tap was
firing both handlers; enemy taps are now debounced.

Economy. The paper model had the reward and upgrade curves but the runtime
only subtracted gold from a balance that was always zero. The scene now owns
permanent progress: victory grants the reward from the shared rules, upgrades
cost a growing amount, hero DPS rises per level, and the next battle is
created with the upgraded roster DPS. run_economy_loop_test.sh proves four
N01 clears pay for the first upgrade and that duplicate grants and losses
behave correctly. The economy pacing was left at four wins rather than
weakening it to satisfy the test.

tools/run_p2_checks.sh now runs 11 gates; all pass. PRODUCTION/38 records
P2-IMP-02/03 and P2-BAT-02 as PASS. Remaining P2 holds: profiler/visual
limit, shield-break and ultimate VFX, real-device safe area and performance.
2026-11-16 23:30:49 +08:00

134 lines
4.7 KiB
GDScript

extends SceneTree
## Real touch-input evidence for the P2/P3a HUD.
##
## This test does NOT call button callbacks or `gui_input` directly. It feeds
## `InputEventScreenTouch` through `Input.parse_input_event`, so the event goes
## through the engine's normal viewport/Control routing and the emulated mouse
## path that real mobile touches use.
##
## It verifies that a touch lands on the correct tick and produces the right
## simulation event, and writes a machine-readable log.
const OUTPUT_PATH := "res://artifacts/touch_input_test.json"
const SCENARIO := "P3A-N03-SEMI"
const SEED := 10001
var _log: Array = []
var _problems: Array = []
func _init() -> void:
_run.call_deferred()
func _run() -> void:
var root_window := get_root()
root_window.content_scale_size = Vector2i(390, 844)
root_window.size = Vector2i(390, 844)
await process_frame
await process_frame
var scene = load("res://scripts/battle_scene.gd").new()
root_window.add_child(scene)
var battle := scene as BattleScene
battle.set_process(false)
battle.setup("zh_CN", SCENARIO, SEED)
battle.advance_by_delta(2.0)
await process_frame
await process_frame
var hit_center := battle.hud.enemy_hit_center("E-R1-F3-V1#1")
var tap_center := battle.hud.named_button_center("TapButton")
var storm_center := battle.hud.named_button_center("StormButton")
_log.append({"step": "targets", "enemy": str(hit_center), "tap": str(tap_center), "storm": str(storm_center)})
if hit_center == Vector2.ZERO or tap_center == Vector2.ZERO or storm_center == Vector2.ZERO:
_problems.append("a required hit target was not found")
# 1. Start continuous tapping with a real touch.
await _tap(tap_center)
var tap_active := bool(battle.tap_active)
_log.append({"step": "tap_button", "tick": battle.state_fingerprint()["ticks"], "tap_active": tap_active})
if not tap_active:
_problems.append("ScreenTouch on TapButton did not start tapping")
# 2. Select an enemy with a real touch, then let a few ticks land.
var before := (battle.state.get("event_log", []) as Array).size()
await _tap(hit_center)
battle.advance_by_delta(0.4)
var after_log: Array = battle.state.get("event_log", [])
var click_events: Array = []
for event in after_log.slice(before):
if str(event.get("type", "")) == "click_enemy":
click_events.append(event)
_log.append({"step": "enemy_touch", "tick": battle.state_fingerprint()["ticks"], "click_events": click_events})
if click_events.is_empty():
_problems.append("ScreenTouch on the enemy did not insert a click_enemy event")
# One ScreenTouch must not be routed twice (ScreenTouch plus emulated mouse).
for event in click_events:
var same_time := 0
for other in click_events:
if other.get("time") == event.get("time"):
same_time += 1
if same_time > 2:
_problems.append(
"duplicate click_enemy events at time %s (%d); mouse emulation from touch must stay off"
% [str(event.get("time")), same_time]
)
break
# 3. Use the storm button with a real touch.
var before_storm := (battle.state.get("event_log", []) as Array).size()
await _tap(storm_center)
battle.advance_by_delta(0.2)
var storm_events: Array = []
for event in (battle.state.get("event_log", []) as Array).slice(before_storm):
if str(event.get("type", "")) == "offboard_burst":
storm_events.append(event)
_log.append({"step": "storm_touch", "tick": battle.state_fingerprint()["ticks"], "storm_events": storm_events})
if storm_events.is_empty():
_problems.append("ScreenTouch on StormButton did not insert an offboard_burst event")
var passed := _problems.is_empty()
var report := {
"schema": 1,
"kind": "windroost_touch_input_test",
"input_method": "Input.parse_input_event(InputEventScreenTouch)",
"scenario": SCENARIO,
"seed": SEED,
"overall": "PASS" if passed else "FAIL",
"problems": _problems,
"steps": _log,
"final_fingerprint": battle.state_fingerprint(),
}
var artifact_dir := ProjectSettings.globalize_path("res://artifacts")
DirAccess.make_dir_recursive_absolute(artifact_dir)
var file := FileAccess.open(artifact_dir.path_join("touch_input_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _log:
print("TOUCH_STEP %s" % JSON.stringify(entry))
if passed:
print("TOUCH_INPUT_PASS %d real ScreenTouch events verified" % 3)
else:
print("TOUCH_INPUT_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)
func _tap(position: Vector2) -> void:
var down := InputEventScreenTouch.new()
down.index = 1
down.position = position
down.pressed = true
Input.parse_input_event(down)
await process_frame
await process_frame
var up := InputEventScreenTouch.new()
up.index = 1
up.position = position
up.pressed = false
Input.parse_input_event(up)
await process_frame