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.
This commit is contained in:
2026-11-16 23:30:49 +08:00
parent e7b55e1c17
commit a0c590deec
51 changed files with 1976 additions and 123 deletions
+5 -2
View File
@@ -26,15 +26,18 @@
- [x] P2 性能、多语言、1x/2x/3x 和最小存档读写 smoke 验证表(用例已冻结)
- [x] 运行时与纸面数值一致(parity 闸门):300 条结果逐字段一致,冻结参考已建立
- [x] 战斗 HUD 承载物:合同驱动的布局、中英文 key 层、三尺寸截图矩阵
- [x] 角色动画进入战斗舞台:H01/EG01/B01 多帧图集、统一脚线、idle 循环与 hit 回退
- [x] 真实输入证据:`Input.parse_input_event` ScreenTouch 命中三个入口并在正确 tick 产生事件
- [x] 运行时经济闭环:胜利→奖励→金币→升级→DPS 变化→下一场生效
- [ ] 正式开发协作方式、分支方式和启动顺序由 Owner 指定
EG01/B01 的完整 `attack/death/break` 角色状态不再阻塞 P3a。P3a 使用 idle、hit、程序化命中闪白、破盾闪光和淡出;P3c 再补完整动作状态。
固定 seed 战斗 fixture 已通过三组 100 seed 场景;这只完成 P1 的战斗可复现证据,经济、重建、离线和存档事务仍未放行。
当前运行时状态:`p2_godot_sample/` 已完成 Godot 4.6 headless/runtime smoke,并通过最小 schema=1 存档、重复领奖抑制和重新加载恢复检查。**P2 完整验收仍未放行**:真实视觉布局已由 UI 承载物补上,但角色动画、真实 `Input.parse_input_event` 触摸证据、profiler/VFX、真机安全区和性能仍无证据。
当前运行时状态:`p2_godot_sample/` 已完成 Godot 4.6 headless/runtime smoke,并通过最小 schema=1 存档、重复领奖抑制和重新加载恢复检查。**P2 完整验收仍未放行**:真实视觉布局、角色动画和真实触摸已补上,但 profiler/可视上限、破盾与终极 VFX、真机安全区与性能仍无证据。
一次性检查入口:`tools/run_p2_checks.sh`(9 项:内容校验、文案校验、经济校验、纸面确定性、运行时 parity、headless smoke、存档 smoke、速度等价、UI 截图矩阵)。
一次性检查入口:`tools/run_p2_checks.sh`(11 项:内容校验、文案校验、经济校验、纸面确定性、运行时 parity、headless smoke、存档 smoke、速度等价、真实触摸、运行时经济闭环、UI 截图矩阵)。
经济/离线/重建的纸面 smoke 也已通过:成本单调、购买幂等、8 小时离线封顶和 1999/2000/4000 等级边界均有结果文件;Godot 运行时事务和完整回本节奏仍未放行。
+12 -7
View File
@@ -1,8 +1,8 @@
# 38 · P2 Godot 小样验证用例
> 状态:**用例和 manifest 已冻结;headless/runtime smoke、最小存档 smoke、运行时数值一致性和 UI 承载物已验证,完整 P2 验收仍 HOLD**(2026-11-16 更新)。本文件定义最小技术样本,不授权启动完整产品开发。
> 状态:**用例和 manifest 已冻结;headless/runtime smoke、最小存档 smoke、运行时数值一致性、UI 承载物、角色动画、真实触摸和运行时经济闭环已验证;完整 P2 验收仍 HOLD**(2026-11-16 更新)。本文件定义最小技术样本,不授权启动完整产品开发。
>
> 一次性检查入口:`tools/run_p2_checks.sh`(9 项全部通过才算本轮成立)。
> 一次性检查入口:`tools/run_p2_checks.sh`(11 项全部通过才算本轮成立)。
## 1. 固定样本
@@ -53,19 +53,20 @@ python3 tools/mvp_content_validator.py
| ID | 验证 | 状态 | 证据 |
|---|---|---|---|
| P2-IMP-01 | 资源导入 | ✅ PASS | Godot 导入日志;9 个 NinePatch 帧在 390/360/430 三尺寸下像素对齐 |
| P2-IMP-02 | 锚点和脚底线 | ⛔ HOLD | 仍无 `AnimationPlayer`,待机/命中只有单帧 |
| P2-IMP-03 | 状态播放 | ⛔ HOLD | 尚未接入动画播放 |
| P2-IMP-02 | 锚点和脚底线 | ✅ PASS | 动画打包器对整段状态使用统一缩放和统一 `foot_y`,运行时 `UnitView` 以脚线为节点原点;逐帧位置可由 manifest 直接核对 |
| P2-IMP-03 | 状态播放 | ✅ PASS | H01 idle/attack、EG01 idle/hit、B01 idle/hit 多帧图集;idle 循环、hit 播放一次后回 idle,受击由 HP 下降触发可见闪白 |
| P2-UI-01 | NinePatch | ✅ PASS | `tools/create_pixel_ui_frames.py` 产出 6px 边框 / 6px 切角帧;`BattleHudLayout.verify_layout` 在三尺寸下核对真实区域矩形 |
| P2-UI-02 | 动态文字 | ✅ PASS | 中英文截图 8 张;`tools/mvp_ui_text_validator.py` 证明两语言 key 集合一致、代码引用的 key 全部存在、全部内容 ID 都有文案 |
| P2-UI-03 | 安全区 | ⛔ HOLD | 布局已按运行时安全区内缩,但尚无带真实 inset 的设备证据 |
| P2-BAT-01 | 逻辑接线 | ✅ PASS | `tools/mvp_parity_gate.py`:纸面与运行时 300 条结果逐字段 + 逐条 event_log 一致 |
| P2-BAT-02 | 输入 | ⛔ HOLD | HUD 信号与按 tick 注入已实现;真实 `Input.parse_input_event` ScreenTouch 证据未产出 |
| P2-BAT-02 | 输入 | ✅ PASS | `run_touch_test.sh`:真实 `Input.parse_input_event(InputEventScreenTouch)` 命中 TapButton、敌人卡和风暴号令,并在正确 tick 产生 `click_enemy` / `offboard_burst`;同时修复了触摸被模拟成鼠标导致的重复触发 |
| P2-BAT-03 | 可视上限 | ⛔ HOLD | 尚未做节点计数与 profiler |
| P2-VFX-01 | 三个程序化 VFX | ⛔ HOLD | 仍只有 VFX ID,没有粒子/着色器实现 |
| P2-VFX-01 | 三个程序化 VFX | ⛔ HOLD | 命中闪白已接入,破盾与终极环仍只有 ID,没有粒子/着色器实现 |
| P2-SCALE-01 | 1x/2x/3x | ✅ PASS | `run_speed_equivalence.sh`:3 帧率 × 3 速度 = 9 组结算指纹完全相同 |
| P2-SAVE-01 | 最小存档 smoke | ✅ PASS | schema=1、重复领奖抑制、重载恢复 |
| 运行时经济 | 胜利→奖励→升级→DPS | ✅ PASS | `run_economy_loop_test.sh`:4 胜 × 30 金币 = 120 → 升级扣费 → 旅团 DPS 65→67 → 下一场战斗确实用 67;重复领奖与失败不发奖均通过 |
按第 3 节的放行规则,`P2-IMP`、`P2-UI`、`P2-BAT`、`P2-SCALE`、`P2-SAVE` 必须全部 PASS,因此 **P2 完整验收仍 HOLD**,剩余缺口集中在角色动画、真实触摸证据、profiler/VFX 和真机安全区。
按第 3 节的放行规则,`P2-IMP`、`P2-UI`、`P2-BAT`、`P2-SCALE`、`P2-SAVE` 必须全部 PASS,因此 **P2 完整验收仍 HOLD**,剩余缺口集中在安全区真机证据、profiler/可视上限和破盾/终极 VFX,以及人工与设备闸门。
### 4.1 本轮新增资产与数据
@@ -75,7 +76,11 @@ python3 tools/mvp_content_validator.py
| 冻结参考 | `data/mvp_validation_seed_reference.json` | 纸面数字的冻结基线,偏离即失败 |
| 本地化文案 | `data/ui_text.zh_CN.json`、`data/ui_text.en_US.json` | 81 个 key,7 语言架构第一天成立 |
| NinePatch 帧 | `PRODUCTION/source/pixel_pilot/ui/frames/` | 6px 边框、6px 切角、48×48 |
| 角色动画帧 | `PRODUCTION/source/pixel_pilot/characters/*/*_anim.png` | H01/EG01/B01 的 idle/attack/hit 多帧图集,统一缩放与脚线打包 |
| 内容→美术绑定 | `data/mvp_content_fixture.json` 的 `art_id` | 每个内容 ID 指向其美术 ID |
| 奖励与成长规则 | `data/mvp_battle_rules.json` 的 `reward_amounts` / `progression` | 纸面与运行时共用,运行时经济闸门校验 |
| UI 截图 | `p2_godot_sample/artifacts/ui_captures/` | 8 张,含真实视口尺寸与区域矩形清单 |
| 触摸/经济证据 | `p2_godot_sample/artifacts/touch_input_test.json`、`economy_loop_test.json` | 真实 ScreenTouch 事件链与完整经济循环逐阶段记录 |
### 4.2 本轮修复的缺陷
@@ -0,0 +1,90 @@
{
"schema": 1,
"status": "runtime",
"character_id": "B01",
"state": "hit",
"frame_count": 3,
"fps": 12,
"loop": false,
"cell_size": [
128,
128
],
"atlas_size": [
384,
128
],
"logical_canvas": [
128,
128
],
"fit": 0.86,
"scale": 0.154174,
"foot_y": 113,
"resample": "nearest",
"source_frames": [
"PRODUCTION/source/sprite_runs/B01/run/frames/hit/frame-0.png",
"PRODUCTION/source/sprite_runs/B01/run/frames/hit/frame-1.png",
"PRODUCTION/source/sprite_runs/B01/run/frames/hit/frame-2.png"
],
"union_alpha_bbox": [
0,
0,
714,
704
],
"atlas_sha256": "55dd55ad5516c12138283516ff784e89a9fd6718da23753d3f432b5ba05e623c",
"frames": [
{
"name": "frame-0",
"atlas_rect": [
0,
0,
128,
128
],
"cell_offset": [
9,
4
],
"size": [
110,
109
]
},
{
"name": "frame-1",
"atlas_rect": [
128,
0,
128,
128
],
"cell_offset": [
9,
4
],
"size": [
110,
109
]
},
{
"name": "frame-2",
"atlas_rect": [
256,
0,
128,
128
],
"cell_offset": [
9,
4
],
"size": [
110,
109
]
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

@@ -0,0 +1,108 @@
{
"schema": 1,
"status": "runtime",
"character_id": "B01",
"state": "idle",
"frame_count": 4,
"fps": 8,
"loop": true,
"cell_size": [
128,
128
],
"atlas_size": [
512,
128
],
"logical_canvas": [
128,
128
],
"fit": 0.86,
"scale": 0.15439,
"foot_y": 113,
"resample": "nearest",
"source_frames": [
"PRODUCTION/source/sprite_runs/B01/run/frames/idle/frame-0.png",
"PRODUCTION/source/sprite_runs/B01/run/frames/idle/frame-1.png",
"PRODUCTION/source/sprite_runs/B01/run/frames/idle/frame-2.png",
"PRODUCTION/source/sprite_runs/B01/run/frames/idle/frame-3.png"
],
"union_alpha_bbox": [
0,
0,
713,
704
],
"atlas_sha256": "b02eb60594feb2dd0cc726c71b297bc429768372bdce5cf7be02c415092fbfde",
"frames": [
{
"name": "frame-0",
"atlas_rect": [
0,
0,
128,
128
],
"cell_offset": [
9,
4
],
"size": [
110,
109
]
},
{
"name": "frame-1",
"atlas_rect": [
128,
0,
128,
128
],
"cell_offset": [
9,
4
],
"size": [
110,
109
]
},
{
"name": "frame-2",
"atlas_rect": [
256,
0,
128,
128
],
"cell_offset": [
9,
4
],
"size": [
110,
109
]
},
{
"name": "frame-3",
"atlas_rect": [
384,
0,
128,
128
],
"cell_offset": [
9,
4
],
"size": [
110,
109
]
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

@@ -0,0 +1,90 @@
{
"schema": 1,
"status": "runtime",
"character_id": "EG01",
"state": "hit",
"frame_count": 3,
"fps": 12,
"loop": false,
"cell_size": [
96,
96
],
"atlas_size": [
288,
96
],
"logical_canvas": [
96,
96
],
"fit": 0.86,
"scale": 0.271579,
"foot_y": 84,
"resample": "nearest",
"source_frames": [
"PRODUCTION/source/sprite_runs/EG01/run/frames/hit/frame-0.png",
"PRODUCTION/source/sprite_runs/EG01/run/frames/hit/frame-1.png",
"PRODUCTION/source/sprite_runs/EG01/run/frames/hit/frame-2.png"
],
"union_alpha_bbox": [
0,
0,
297,
304
],
"atlas_sha256": "244323547eb548f8ad50aa0b55d833d5060ff09fed99069ce52c8e05c45bcc23",
"frames": [
{
"name": "frame-0",
"atlas_rect": [
0,
0,
96,
96
],
"cell_offset": [
7,
1
],
"size": [
81,
83
]
},
{
"name": "frame-1",
"atlas_rect": [
96,
0,
96,
96
],
"cell_offset": [
7,
1
],
"size": [
81,
83
]
},
{
"name": "frame-2",
"atlas_rect": [
192,
0,
96,
96
],
"cell_offset": [
7,
1
],
"size": [
81,
83
]
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

@@ -0,0 +1,108 @@
{
"schema": 1,
"status": "runtime",
"character_id": "EG01",
"state": "idle",
"frame_count": 4,
"fps": 8,
"loop": true,
"cell_size": [
96,
96
],
"atlas_size": [
384,
96
],
"logical_canvas": [
96,
96
],
"fit": 0.86,
"scale": 0.271579,
"foot_y": 84,
"resample": "nearest",
"source_frames": [
"PRODUCTION/source/sprite_runs/EG01/run/frames/idle/frame-0.png",
"PRODUCTION/source/sprite_runs/EG01/run/frames/idle/frame-1.png",
"PRODUCTION/source/sprite_runs/EG01/run/frames/idle/frame-2.png",
"PRODUCTION/source/sprite_runs/EG01/run/frames/idle/frame-3.png"
],
"union_alpha_bbox": [
0,
0,
297,
304
],
"atlas_sha256": "671aecc61734cdf956b9c7a6709dd57c24d0546dd2c475210cc9c2f394fa933a",
"frames": [
{
"name": "frame-0",
"atlas_rect": [
0,
0,
96,
96
],
"cell_offset": [
7,
1
],
"size": [
81,
83
]
},
{
"name": "frame-1",
"atlas_rect": [
96,
0,
96,
96
],
"cell_offset": [
7,
1
],
"size": [
81,
83
]
},
{
"name": "frame-2",
"atlas_rect": [
192,
0,
96,
96
],
"cell_offset": [
7,
1
],
"size": [
81,
83
]
},
{
"name": "frame-3",
"atlas_rect": [
288,
0,
96,
96
],
"cell_offset": [
7,
1
],
"size": [
81,
83
]
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

@@ -0,0 +1,108 @@
{
"schema": 1,
"status": "runtime",
"character_id": "H01",
"state": "attack",
"frame_count": 4,
"fps": 12,
"loop": false,
"cell_size": [
96,
96
],
"atlas_size": [
384,
96
],
"logical_canvas": [
96,
96
],
"fit": 0.86,
"scale": 0.224348,
"foot_y": 84,
"resample": "nearest",
"source_frames": [
"PRODUCTION/source/sprite_runs/H01/run/frames/attack/frame-0.png",
"PRODUCTION/source/sprite_runs/H01/run/frames/attack/frame-1.png",
"PRODUCTION/source/sprite_runs/H01/run/frames/attack/frame-2.png",
"PRODUCTION/source/sprite_runs/H01/run/frames/attack/frame-3.png"
],
"union_alpha_bbox": [
0,
0,
357,
368
],
"atlas_sha256": "550f3bd573bef145e23385de147c1f5fe781569338f736ef3e812a40302ce6f7",
"frames": [
{
"name": "frame-0",
"atlas_rect": [
0,
0,
96,
96
],
"cell_offset": [
8,
1
],
"size": [
80,
83
]
},
{
"name": "frame-1",
"atlas_rect": [
96,
0,
96,
96
],
"cell_offset": [
8,
1
],
"size": [
80,
83
]
},
{
"name": "frame-2",
"atlas_rect": [
192,
0,
96,
96
],
"cell_offset": [
8,
1
],
"size": [
80,
83
]
},
{
"name": "frame-3",
"atlas_rect": [
288,
0,
96,
96
],
"cell_offset": [
8,
1
],
"size": [
80,
83
]
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

@@ -0,0 +1,108 @@
{
"schema": 1,
"status": "runtime",
"character_id": "H01",
"state": "idle",
"frame_count": 4,
"fps": 8,
"loop": true,
"cell_size": [
96,
96
],
"atlas_size": [
384,
96
],
"logical_canvas": [
96,
96
],
"fit": 0.86,
"scale": 0.224348,
"foot_y": 84,
"resample": "nearest",
"source_frames": [
"PRODUCTION/source/sprite_runs/H01/run/frames/idle/frame-0.png",
"PRODUCTION/source/sprite_runs/H01/run/frames/idle/frame-1.png",
"PRODUCTION/source/sprite_runs/H01/run/frames/idle/frame-2.png",
"PRODUCTION/source/sprite_runs/H01/run/frames/idle/frame-3.png"
],
"union_alpha_bbox": [
0,
0,
321,
368
],
"atlas_sha256": "5743b6f5a980e061b169d3f9d0ccd43bcabfe5ab8a8c66c269ec97ae87e92292",
"frames": [
{
"name": "frame-0",
"atlas_rect": [
0,
0,
96,
96
],
"cell_offset": [
12,
1
],
"size": [
72,
83
]
},
{
"name": "frame-1",
"atlas_rect": [
96,
0,
96,
96
],
"cell_offset": [
12,
1
],
"size": [
72,
83
]
},
{
"name": "frame-2",
"atlas_rect": [
192,
0,
96,
96
],
"cell_offset": [
12,
1
],
"size": [
72,
83
]
},
{
"name": "frame-3",
"atlas_rect": [
288,
0,
96,
96
],
"cell_offset": [
12,
1
],
"size": [
72,
83
]
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

+4
View File
@@ -140,6 +140,8 @@ windroost/
9 项检查:内容校验、UI 文案校验、经济校验、纸面确定性、**运行时与纸面数值 parity**、Godot headless smoke、存档 smoke、**1x/2x/3x 结算等价**、**UI 截图矩阵**。
新增 2 项运行时证据:`run_touch_test.sh`(真实 `Input.parse_input_event` ScreenTouch)、`run_economy_loop_test.sh`(胜利→奖励→升级→DPS 生效)。合计 11 项。
关键数据归属:
| 数据 | 路径 | 说明 |
@@ -148,6 +150,8 @@ windroost/
| 冻结参考 | `data/mvp_validation_seed_reference.json` | 纸面数字基线,偏离即 parity 失败 |
| 本地化文案 | `data/ui_text.zh_CN.json`、`data/ui_text.en_US.json` | 所有可见文本走 key,7 语言架构第一天成立 |
| NinePatch 帧 | `PRODUCTION/source/pixel_pilot/ui/frames/` | 6px 边框、6px 切角,由 `tools/create_pixel_ui_frames.py` 生成 |
| 角色动画帧 | `PRODUCTION/source/pixel_pilot/characters/*/*_anim.png` | H01/EG01/B01 多帧图集,由 `tools/pack_animation_strip.py` 统一缩放与脚线打包 |
| 内容→美术绑定 | `data/mvp_content_fixture.json` 的 `art_id` | 每个内容 ID 对应的美术 ID |
可运行工程:`p2_godot_sample/`,直接用 Godot 4.6 打开即可操作战斗 HUD。
+13
View File
@@ -73,6 +73,19 @@
"P3A-N10-MANUAL_WIN": "DROP-R1-BOSS-01",
"P3A-N10-MANUAL_LOSS": "REWARD-R1-C01-N10"
},
"reward_amounts": {
"REWARD-R1-C01-N01": { "gold": 30, "crystal": 0 },
"REWARD-R1-C01-N03": { "gold": 50, "crystal": 0 },
"DROP-R1-BOSS-01": { "gold": 100, "crystal": 5 },
"REWARD-R1-C01-N10": { "gold": 0, "crystal": 0 }
},
"progression": {
"initial_level": 1,
"dps_per_level_ratio": 0.25,
"upgrade_base_cost": 120,
"upgrade_cost_growth": 1.15,
"comment": "Hero DPS at level n is base_dps * (1 + dps_per_level_ratio * (n - initial_level)). The roster bonus is the sum of the per-hero gains and is passed into create_state. Upgrade cost grows geometrically per purchased level."
},
"evaluation_order": [
"input_events",
"shield_rebuild",
+91 -10
View File
@@ -2,23 +2,104 @@
"schema": 1,
"purpose": "Frozen P3a/P2 content fixture; full launch content remains in the launch data pack",
"heroes": [
{"id": "H01", "signature": "break", "base_atk": 10, "base_spd": 90, "base_dps": 8, "unlock_node_id": "R1-C01-N01"},
{"id": "H02", "signature": "single", "base_atk": 14, "base_spd": 110, "base_dps": 12, "unlock_node_id": "R1-C01-N01"},
{"id": "H04", "signature": "click", "base_atk": 11, "base_spd": 100, "base_dps": 9, "unlock_node_id": "R1-C01-N02"}
{
"id": "H01",
"signature": "break",
"base_atk": 10,
"base_spd": 90,
"base_dps": 8,
"unlock_node_id": "R1-C01-N01",
"art_id": "H01"
},
{
"id": "H02",
"signature": "single",
"base_atk": 14,
"base_spd": 110,
"base_dps": 12,
"unlock_node_id": "R1-C01-N01",
"art_id": "H02"
},
{
"id": "H04",
"signature": "click",
"base_atk": 11,
"base_spd": 100,
"base_dps": 9,
"unlock_node_id": "R1-C01-N02",
"art_id": "H04"
}
],
"enemies": [
{"id": "E-R1-F1-V1", "kind": "normal", "hp_mult": 0.8, "armor": 1, "shield_max": 0, "weak_tag": "aoe"},
{"id": "E-R1-F3-V1", "kind": "elite", "hp_mult": 2.0, "armor": 3, "shield_max": 60, "weak_tag": "break"}
{
"id": "E-R1-F1-V1",
"kind": "normal",
"hp_mult": 0.8,
"armor": 1,
"shield_max": 0,
"weak_tag": "aoe",
"art_id": "EG01"
},
{
"id": "E-R1-F3-V1",
"kind": "elite",
"hp_mult": 2.0,
"armor": 3,
"shield_max": 60,
"weak_tag": "break",
"art_id": "EG01"
}
],
"validation_pressure_enemies": [
{"id": "E-R1-F4-V1", "kind": "elite_support", "hp_mult": 1.0, "armor": 1, "shield_max": 0, "weak_tag": "sustain"}
{
"id": "E-R1-F4-V1",
"kind": "elite_support",
"hp_mult": 1.0,
"armor": 1,
"shield_max": 0,
"weak_tag": "sustain",
"art_id": "EG01"
}
],
"bosses": [
{"id": "B-R1-01", "hp": 1500, "armor": 5, "shield_max": 200, "timer_sec": 30, "phase_ids": ["B-R1-01-P1", "B-R1-01-P2"]}
{
"id": "B-R1-01",
"hp": 1500,
"armor": 5,
"shield_max": 200,
"timer_sec": 30,
"phase_ids": [
"B-R1-01-P1",
"B-R1-01-P2"
],
"art_id": "B01"
}
],
"nodes": [
{"id": "R1-C01-N01", "node_type": "normal", "wave_ids": ["W-R1-C01-N01-01"], "reward_id": "REWARD-R1-C01-N01"},
{"id": "R1-C01-N03", "node_type": "elite", "wave_ids": ["W-R1-C01-N03-01", "W-R1-C01-N03-02"], "reward_id": "REWARD-R1-C01-N03"},
{"id": "R1-C01-N10", "node_type": "boss", "wave_ids": ["B-R1-01"], "reward_id": "DROP-R1-BOSS-01"}
{
"id": "R1-C01-N01",
"node_type": "normal",
"wave_ids": [
"W-R1-C01-N01-01"
],
"reward_id": "REWARD-R1-C01-N01"
},
{
"id": "R1-C01-N03",
"node_type": "elite",
"wave_ids": [
"W-R1-C01-N03-01",
"W-R1-C01-N03-02"
],
"reward_id": "REWARD-R1-C01-N03"
},
{
"id": "R1-C01-N10",
"node_type": "boss",
"wave_ids": [
"B-R1-01"
],
"reward_id": "DROP-R1-BOSS-01"
}
]
}
+12 -7
View File
@@ -13,13 +13,16 @@
- `scripts/ui_text.gd` + `data/ui_text.zh_CN.json` + `data/ui_text.en_US.json`:运行时文案层,81 个 key,7 语言架构第一天成立。
- `scripts/ui_theme.gd`:共享主题与 NinePatch 工厂;用 `SystemFont` 解析系统中文字体(Godot 内置字体没有 CJK 字形)。
- `scripts/capture_runner.gd` + `run_capture.sh`:真实渲染截图矩阵,同时输出每个视口下的实际区域矩形,供合同核对。
- `scripts/unit_view.gd`:动画单位视图。从图集清单读取帧区域、FPS 和脚线,节点原点即脚线;支持 idle 循环、一次性 hit 回退和受击闪白。
- `scripts/touch_input_test.gd` + `run_touch_test.sh`:用真实 `Input.parse_input_event(InputEventScreenTouch)` 触摸 TapButton、敌人卡和风暴号令,验证事件在正确 tick 进入 event_log;同时防住触摸被模拟成鼠标导致的重复触发。
- `scripts/economy_loop_test.gd` + `run_economy_loop_test.sh`:运行时经济闭环,胜利奖励、重复领奖保护、升级扣费、DPS 变化、下一场生效和失败不发奖。
- `scripts/speed_equivalence_test.gd` + `run_speed_equivalence.sh`:1x/2x/3x 与帧率无关的结算等价性测试。
- `assets/`:通过 symlink 接入已存在的 H01、EG01、B01、背景、UI 板和新增的 NinePatch 帧源文件,不复制或修改冻结资产。
- `assets/`:通过 symlink 接入角色、背景、UI 板、NinePatch 帧和多帧动画图集源文件,不复制或修改冻结资产。
- `scenes/p2_sample.tscn` + `scripts/p2_sample.gd`:原有的技术样板场景,保留用于对照;不再作为 main scene。
## 已验证
执行 `tools/run_p2_checks.sh`(9 项一次性检查):
执行 `tools/run_p2_checks.sh`(11 项一次性检查):
- 工程可由 `--editor --quit` 导入并退出;
- 三个 scenario 都能被加载并生成包含 `seed`、`scenario_id`、`mode`、`result`、`duration_seconds`、`reward_id` 和 `event_log` 的 JSON;
@@ -30,13 +33,15 @@
- 存档 smoke 记录 schema=1、node/progress、reward_id、claimed,首次领取成功、第二次同 reward 返回 `already_claimed` 且不重复生效,重新 load 后 progress、reward 和 claimed 保持不变;
- **1x/2x/3x 在 3 帧率 × 3 速度共 9 组下结算指纹完全相同**;
- **UI 截图矩阵 8 张**:390×844 / 360×800 / 430×932,zh_CN 与 en_US,战斗态、暂停弹层和胜利结算;每张都记录真实视口尺寸与区域矩形,390×844 与合同逐像素一致。
- **战斗舞台已渲染真实角色**:H01 在下方、EG01/B01 在上方,动画帧按统一脚线对齐;敌人受击会播放一次性 hit 并闪白。
- **真实触摸通过**:`Input.parse_input_event(InputEventScreenTouch)` 命中三个入口,在正确 tick 产生 `click_enemy` / `offboard_burst`,并防住重复触发。
- **运行时经济闭环通过**:4 胜 × 30 金币 = 120 → 升级扣费 → 旅团 DPS 65→67 → 下一场战斗实际使用 67;重复领奖与失败不发奖均通过。
## 仍未验证
- 角色动画:待机/命中切换、脚底线锚点和状态播放(工程里还没有 `AnimationPlayer`);
- 真实 `Input.parse_input_event` ScreenTouch 触摸证据;
- 节点计数与 profiler,可视上限和性能;
- 三个程序化 VFX 的粒子/着色器实现;
- 真机安全区 inset、低功耗降级、真机帧率和内存;
- 角色动画:H01/EG01/B01 的 idle 与 hit/attack 已接入;skill/ultimate 帧虽已生成但尚未接入运行时。
- profiler 与可视上限:尚未做节点计数和性能采样。
- 三个程序化 VFX:命中闪白已接入,破盾与终极环仍只有 ID。
- 真机安全区 inset、低功耗降级、真机帧率和内存。
- 真实 OS 后台/挂起恢复、崩溃中断、原子写入失败恢复和跨版本迁移;
- 该 adapter 不是 P3a 正式产品战斗实现,也没有实现重建、离线收益或全量内容。
@@ -0,0 +1,42 @@
{
"kind": "windroost_economy_loop_test",
"overall": "PASS",
"problems": [],
"schema": 1,
"steps": [
{
"dps": 65.0,
"gold": 0,
"level": 1,
"step": "initial"
},
{
"crystal": 0,
"gold": 120,
"round": 5,
"step": "victory"
},
{
"gold": 120,
"step": "duplicate_reward_guard"
},
{
"cost": 120,
"dps_after": 67.0,
"dps_before": 65.0,
"gold": 0,
"level": 2,
"step": "upgrade"
},
{
"gold": 0,
"sim_dps": 67.0,
"step": "next_battle"
},
{
"gold": 0,
"result": "timeout",
"step": "loss"
}
]
}
@@ -0,0 +1,101 @@
{
"final_fingerprint": {
"burst_damage": 222.532,
"click_damage": 339.836,
"duration_seconds": 2.4,
"enemies": [
{
"dead": false,
"hp": 532.225,
"id": "E-R1-F3-V1#1",
"shield": 0.0
},
{
"dead": false,
"hp": 450.0,
"id": "E-R1-F4-V1#2",
"shield": 0.0
}
],
"event_count": 10,
"result": "timeout",
"shield_broken": 1,
"ticks": 25,
"ultimate_casts": 0,
"weakness_hits": 25
},
"input_method": "Input.parse_input_event(InputEventScreenTouch)",
"kind": "windroost_touch_input_test",
"overall": "PASS",
"problems": [],
"scenario": "P3A-N03-SEMI",
"schema": 1,
"seed": 10001,
"steps": [
{
"enemy": "(109.5, 160.0)",
"step": "targets",
"storm": "(232.0, 468.0)",
"tap": "(101.0, 468.0)"
},
{
"step": "tap_button",
"tap_active": true,
"tick": 19
},
{
"click_events": [
{
"damage": 41.242,
"target_id": "E-R1-F3-V1",
"time": 1.9,
"type": "click_enemy"
},
{
"damage": 41.242,
"target_id": "E-R1-F3-V1",
"time": 1.9,
"type": "click_enemy"
},
{
"damage": 41.242,
"target_id": "E-R1-F3-V1",
"time": 2.0,
"type": "click_enemy"
},
{
"damage": 41.242,
"target_id": "E-R1-F3-V1",
"time": 2.0,
"type": "click_enemy"
},
{
"damage": 41.242,
"target_id": "E-R1-F3-V1",
"time": 2.1,
"type": "click_enemy"
},
{
"damage": 41.242,
"target_id": "E-R1-F3-V1",
"time": 2.2,
"type": "click_enemy"
}
],
"step": "enemy_touch",
"tick": 23
},
{
"step": "storm_touch",
"storm_events": [
{
"damage": 324.076,
"target_id": "E-R1-F3-V1",
"time": 2.3,
"type": "offboard_burst"
}
],
"tick": 25
}
]
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 163 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 KiB

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 212 KiB

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 92 KiB

+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/B01/B01_hit_anim.manifest.json
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/B01/B01_hit_anim.png
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/B01/B01_idle_anim.manifest.json
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/B01/B01_idle_anim.png
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/EG01/EG01_hit_anim.manifest.json
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/EG01/EG01_hit_anim.png
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/EG01/EG01_idle_anim.manifest.json
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/EG01/EG01_idle_anim.png
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/H01/H01_attack_anim.manifest.json
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/H01/H01_attack_anim.png
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/H01/H01_idle_anim.manifest.json
+1
View File
@@ -0,0 +1 @@
../../PRODUCTION/source/pixel_pilot/characters/H01/H01_idle_anim.png
+47
View File
@@ -0,0 +1,47 @@
#!/bin/zsh
set -euo pipefail
ROOT_DIR="${0:A:h}"
GODOT_BIN="${GODOT_BIN:-/Applications/Godot.app/Contents/MacOS/Godot}"
LOG_PATH="$ROOT_DIR/artifacts/economy_loop_test.log"
TIMEOUT_SECONDS="${ECONOMY_TEST_TIMEOUT_SECONDS:-180}"
if [[ ! -x "$GODOT_BIN" ]]; then
print -u2 "Godot binary not found: $GODOT_BIN"
exit 127
fi
mkdir -p "$ROOT_DIR/artifacts"
"$GODOT_BIN" --headless --path "$ROOT_DIR" --script res://scripts/economy_loop_test.gd \
> "$LOG_PATH" 2>&1 &
GODOT_PID=$!
(
sleep "$TIMEOUT_SECONDS"
kill -TERM "$GODOT_PID" 2>/dev/null || true
sleep 5
kill -KILL "$GODOT_PID" 2>/dev/null || true
) &
WATCHDOG_PID=$!
set +e
wait "$GODOT_PID"
STATUS=$?
set -e
kill -TERM "$WATCHDOG_PID" 2>/dev/null || true
wait "$WATCHDOG_PID" 2>/dev/null || true
cat "$LOG_PATH"
if [[ $STATUS -ne 0 ]]; then
print -u2 "ECONOMY_LOOP_FAIL exit=$STATUS"
exit "$STATUS"
fi
grep -q "ECONOMY_LOOP_PASS" "$LOG_PATH" || {
print -u2 "ECONOMY_LOOP_FAIL missing pass marker"
exit 4
}
exit 0
+47
View File
@@ -0,0 +1,47 @@
#!/bin/zsh
set -euo pipefail
ROOT_DIR="${0:A:h}"
GODOT_BIN="${GODOT_BIN:-/Applications/Godot.app/Contents/MacOS/Godot}"
LOG_PATH="$ROOT_DIR/artifacts/touch_input_test.log"
TIMEOUT_SECONDS="${TOUCH_TEST_TIMEOUT_SECONDS:-180}"
if [[ ! -x "$GODOT_BIN" ]]; then
print -u2 "Godot binary not found: $GODOT_BIN"
exit 127
fi
mkdir -p "$ROOT_DIR/artifacts"
"$GODOT_BIN" --headless --path "$ROOT_DIR" --script res://scripts/touch_input_test.gd \
> "$LOG_PATH" 2>&1 &
GODOT_PID=$!
(
sleep "$TIMEOUT_SECONDS"
kill -TERM "$GODOT_PID" 2>/dev/null || true
sleep 5
kill -KILL "$GODOT_PID" 2>/dev/null || true
) &
WATCHDOG_PID=$!
set +e
wait "$GODOT_PID"
STATUS=$?
set -e
kill -TERM "$WATCHDOG_PID" 2>/dev/null || true
wait "$WATCHDOG_PID" 2>/dev/null || true
cat "$LOG_PATH"
if [[ $STATUS -ne 0 ]]; then
print -u2 "TOUCH_INPUT_FAIL exit=$STATUS"
exit "$STATUS"
fi
grep -q "TOUCH_INPUT_PASS" "$LOG_PATH" || {
print -u2 "TOUCH_INPUT_FAIL missing pass marker"
exit 4
}
exit 0
+270 -87
View File
@@ -46,6 +46,14 @@ var _stage_timer_bar: ProgressBar
var _stage_timer_label: Label
var _stage_hint: Label
var _stage_wave_label: Label
var _stage_inner: Control
var _units_layer: Node2D
var _overlay_layer: Control
var _unit_views: Dictionary = {}
var _unit_plates: Dictionary = {}
var _hero_views: Dictionary = {}
var _enemy_hit_areas: Dictionary = {}
var _last_enemy_tap_usec: int = 0
var _tap_button: Button
var _storm_button: Button
@@ -233,9 +241,11 @@ func _build_battle_stage() -> void:
panel.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
region.add_child(panel)
var stack := Control.new()
stack.mouse_filter = Control.MOUSE_FILTER_IGNORE
panel.add_child(stack)
_stage_inner = Control.new()
_stage_inner.name = "Inner"
_stage_inner.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
_stage_inner.mouse_filter = Control.MOUSE_FILTER_IGNORE
panel.add_child(_stage_inner)
var background := TextureRect.new()
background.texture = load(BACKGROUND) as Texture2D
@@ -243,24 +253,28 @@ func _build_battle_stage() -> void:
background.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED
background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
background.mouse_filter = Control.MOUSE_FILTER_IGNORE
background.modulate = Color(0.72, 0.78, 0.86, 1.0)
stack.add_child(background)
background.modulate = Color(0.74, 0.80, 0.88, 1.0)
_stage_inner.add_child(background)
var margin := MarginContainer.new()
margin.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
margin.add_theme_constant_override("margin_left", 10)
margin.add_theme_constant_override("margin_right", 10)
margin.add_theme_constant_override("margin_top", 8)
margin.add_theme_constant_override("margin_bottom", 8)
stack.add_child(margin)
# Units are real sprites on a Node2D layer; the overlay above them carries
# the HP, shield and name plates.
_units_layer = Node2D.new()
_units_layer.name = "Units"
_stage_inner.add_child(_units_layer)
var column := VBoxContainer.new()
column.add_theme_constant_override("separation", 6)
margin.add_child(column)
_overlay_layer = Control.new()
_overlay_layer.name = "Overlay"
_overlay_layer.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
_overlay_layer.mouse_filter = Control.MOUSE_FILTER_IGNORE
_stage_inner.add_child(_overlay_layer)
var top_row := HBoxContainer.new()
top_row.add_theme_constant_override("separation", 8)
column.add_child(top_row)
top_row.set_anchors_and_offsets_preset(Control.PRESET_TOP_WIDE)
top_row.offset_left = 10
top_row.offset_right = -10
top_row.offset_top = 6
_stage_inner.add_child(top_row)
_stage_wave_label = UiTheme.make_label("", 11, UiTheme.COLOR_TEXT_DIM)
top_row.add_child(_stage_wave_label)
var timer_spacer := Control.new()
@@ -271,22 +285,19 @@ func _build_battle_stage() -> void:
top_row.add_child(_stage_timer_label)
_stage_timer_bar = UiTheme.make_bar(UiTheme.COLOR_ORANGE, 6)
column.add_child(_stage_timer_bar)
var enemy_area := Control.new()
enemy_area.size_flags_vertical = Control.SIZE_EXPAND_FILL
enemy_area.mouse_filter = Control.MOUSE_FILTER_PASS
column.add_child(enemy_area)
_stage_enemy_row = HBoxContainer.new()
_stage_enemy_row.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
_stage_enemy_row.add_theme_constant_override("separation", 8)
_stage_enemy_row.alignment = BoxContainer.ALIGNMENT_CENTER
enemy_area.add_child(_stage_enemy_row)
_stage_timer_bar.set_anchors_and_offsets_preset(Control.PRESET_TOP_WIDE)
_stage_timer_bar.offset_left = 10
_stage_timer_bar.offset_right = -10
_stage_timer_bar.offset_top = 22
_stage_inner.add_child(_stage_timer_bar)
_stage_hint = UiTheme.make_label("", 11, UiTheme.COLOR_TEXT_DIM)
_stage_hint.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
column.add_child(_stage_hint)
_stage_hint.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_WIDE)
_stage_hint.offset_top = -18
_stage_hint.offset_bottom = -4
_stage_inner.add_child(_stage_hint)
func _build_manual_zone() -> void:
@@ -307,17 +318,20 @@ func _build_manual_zone() -> void:
margin.add_child(row)
_tap_button = UiTheme.make_button("", 12)
_tap_button.name = "TapButton"
_tap_button.custom_minimum_size = Vector2(150, 52)
_tap_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
_tap_button.pressed.connect(_on_tap_pressed)
row.add_child(_tap_button)
_storm_button = UiTheme.make_button("", 12)
_storm_button.name = "StormButton"
_storm_button.custom_minimum_size = Vector2(96, 52)
_storm_button.pressed.connect(func() -> void: storm_used.emit())
row.add_child(_storm_button)
_ultimate_button = UiTheme.make_button("", 12)
_ultimate_button.name = "UltimateButton"
_ultimate_button.custom_minimum_size = Vector2(96, 52)
_ultimate_button.pressed.connect(_on_ultimate_pressed)
row.add_child(_ultimate_button)
@@ -510,62 +524,9 @@ func set_hint(text: String) -> void:
func set_enemies(enemies: Array, targeted_id: String) -> void:
for child in _stage_enemy_row.get_children():
child.queue_free()
for enemy in enemies:
_stage_enemy_row.add_child(_build_enemy_card(enemy, str(enemy.get("id", "")) == targeted_id))
_sync_stage_units(enemies, targeted_id)
func _build_enemy_card(enemy: Dictionary, targeted: bool) -> Control:
var card := PanelContainer.new()
card.custom_minimum_size = Vector2(104, 0)
card.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
card.add_theme_stylebox_override(
"panel",
UiTheme.frame_style(UiTheme.FRAME_TILE if not targeted else UiTheme.FRAME_TAB_SELECTED)
)
card.mouse_filter = Control.MOUSE_FILTER_STOP
var enemy_id := str(enemy.get("id", ""))
card.gui_input.connect(_on_enemy_card_input.bind(enemy_id))
var margin := MarginContainer.new()
margin.add_theme_constant_override("margin_left", 6)
margin.add_theme_constant_override("margin_right", 6)
margin.add_theme_constant_override("margin_top", 5)
margin.add_theme_constant_override("margin_bottom", 5)
card.add_child(margin)
var column := VBoxContainer.new()
column.add_theme_constant_override("separation", 3)
margin.add_child(column)
var name_key := "content.enemy.%s" % str(enemy.get("content_id", ""))
var is_boss := str(enemy.get("content_id", "")).begins_with("B-")
if is_boss:
name_key = "content.boss.%s" % str(enemy.get("content_id", ""))
column.add_child(UiTheme.make_label(UiText.t(name_key, locale), 11))
var hp_bar := UiTheme.make_bar(UiTheme.COLOR_MINT, 8)
hp_bar.value = _ratio(float(enemy.get("hp", 0.0)), float(enemy.get("max_hp", 1.0)))
column.add_child(hp_bar)
var shield := float(enemy.get("shield", 0.0))
if shield > 0.0:
var shield_bar := UiTheme.make_bar(UiTheme.COLOR_ORANGE, 5)
shield_bar.value = 1.0
column.add_child(shield_bar)
var tags := HBoxContainer.new()
tags.add_theme_constant_override("separation", 4)
column.add_child(tags)
if bool(enemy.get("shield_broken", false)):
tags.add_child(UiTheme.make_label(UiText.t("hud.stage.shield_broken", locale), 9, UiTheme.COLOR_ORANGE))
if str(enemy.get("weak_tag", "")) == "break":
tags.add_child(UiTheme.make_label(UiText.t("hud.stage.weakness_active", locale), 9, UiTheme.COLOR_MINT))
if targeted:
tags.add_child(UiTheme.make_label("▼", 9, UiTheme.COLOR_BORDER))
return card
func _ratio(value: float, total: float) -> float:
if total <= 0.0:
@@ -573,7 +534,217 @@ func _ratio(value: float, total: float) -> float:
return clampf(value / total, 0.0, 1.0)
## Art binding for a content id. The content fixture owns this mapping.
var _art_binding: Dictionary = {}
func set_art_binding(binding: Dictionary) -> void:
_art_binding = binding
func _art_id_for(content_id: String) -> String:
return str(_art_binding.get(content_id, content_id))
func _sync_stage_units(enemies: Array, targeted_id: String) -> void:
if _units_layer == null or _stage_inner == null:
return
var margin := BattleHudLayout.STAGE_INNER_MARGIN
var usable_width := maxf(1.0, _stage_inner.size.x - margin * 2.0)
var count := maxi(1, enemies.size())
var slot := usable_width / float(count)
var alive_ids: Array[String] = []
for enemy in enemies:
alive_ids.append(str(enemy.get("id", "")))
for key in _unit_views.keys():
if not alive_ids.has(str(key)):
var stale: UnitView = _unit_views[key]
stale.queue_free()
_unit_views.erase(key)
for key in _unit_plates.keys():
if not alive_ids.has(str(key)):
var stale_plate: Control = _unit_plates[key]
stale_plate.queue_free()
_unit_plates.erase(key)
for key in _enemy_hit_areas.keys():
if not alive_ids.has(str(key)):
var stale_area: Control = _enemy_hit_areas[key]
stale_area.queue_free()
_enemy_hit_areas.erase(key)
for index in range(enemies.size()):
var enemy: Dictionary = enemies[index]
var unit_id := str(enemy.get("id", ""))
var content_id := str(enemy.get("content_id", ""))
var is_boss := content_id.begins_with("B-")
var art_id := _art_id_for(content_id)
var states := ["idle", "hit"] if not is_boss else ["idle", "hit"]
var view: UnitView = _unit_views.get(unit_id)
if view == null:
view = UnitView.new()
view.name = unit_id
if not view.configure(art_id, states):
view.queue_free()
continue
_units_layer.add_child(view)
_unit_views[unit_id] = view
var plate := _build_unit_plate(unit_id, is_boss)
_overlay_layer.add_child(plate)
_unit_plates[unit_id] = plate
var center_x := margin + slot * (float(index) + 0.5)
view.position = Vector2(round(center_x), BattleHudLayout.STAGE_ENEMY_FOOT_Y)
var plate: Control = _unit_plates.get(unit_id)
if plate != null:
var plate_width := minf(slot - 4.0, 118.0)
plate.size = Vector2(plate_width, BattleHudLayout.STAGE_UNIT_PLATE_HEIGHT)
plate.position = Vector2(
round(center_x - plate_width * 0.5), BattleHudLayout.STAGE_ENEMY_PLATE_Y
)
_update_unit_plate(plate, enemy, unit_id == targeted_id)
var hit_area: Control = _enemy_hit_areas.get(unit_id)
if hit_area == null:
hit_area = Control.new()
hit_area.name = "hit_%s" % unit_id
hit_area.mouse_filter = Control.MOUSE_FILTER_STOP
hit_area.gui_input.connect(_on_enemy_card_input.bind(unit_id))
_overlay_layer.add_child(hit_area)
_enemy_hit_areas[unit_id] = hit_area
hit_area.position = Vector2(
round(margin + slot * float(index)), 0.0
)
hit_area.size = Vector2(round(slot), BattleHudLayout.STAGE_ENEMY_FOOT_Y)
func _build_unit_plate(unit_id: String, is_boss: bool) -> Control:
var plate := Control.new()
plate.name = unit_id
plate.mouse_filter = Control.MOUSE_FILTER_IGNORE
var column := VBoxContainer.new()
column.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
column.add_theme_constant_override("separation", 4)
column.mouse_filter = Control.MOUSE_FILTER_IGNORE
plate.add_child(column)
# Row 1: the name and the target marker. The name gets its own line so a
# long enemy name can never collide with the state tags.
var header := HBoxContainer.new()
header.add_theme_constant_override("separation", 4)
column.add_child(header)
var name_label := UiTheme.make_label("", 10)
name_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
name_label.clip_text = true
header.add_child(name_label)
var marker := UiTheme.make_label("", 9, UiTheme.COLOR_BORDER)
header.add_child(marker)
var hp_bar := UiTheme.make_bar(UiTheme.COLOR_MINT, 7)
column.add_child(hp_bar)
var shield_bar := UiTheme.make_bar(UiTheme.COLOR_ORANGE, 5)
column.add_child(shield_bar)
var tag_label := UiTheme.make_label("", 9, UiTheme.COLOR_MINT)
tag_label.clip_text = true
column.add_child(tag_label)
plate.set_meta("name_label", name_label)
plate.set_meta("tag_label", tag_label)
plate.set_meta("marker", marker)
plate.set_meta("hp_bar", hp_bar)
plate.set_meta("shield_bar", shield_bar)
plate.set_meta("is_boss", is_boss)
return plate
func _update_unit_plate(plate: Control, enemy: Dictionary, targeted: bool) -> void:
var content_id := str(enemy.get("content_id", ""))
var is_boss := bool(plate.get_meta("is_boss", false))
var key := ("content.boss.%s" if is_boss else "content.enemy.%s") % content_id
var name_label: Label = plate.get_meta("name_label")
name_label.text = UiText.t(key, locale)
var tag_label: Label = plate.get_meta("tag_label")
var tags: Array[String] = []
if bool(enemy.get("shield_broken", false)):
tags.append(UiText.t("hud.stage.shield_broken", locale))
if str(enemy.get("weak_tag", "")) == "break":
tags.append(UiText.t("hud.stage.weakness_active", locale))
tag_label.text = " ".join(tags)
var marker: Label = plate.get_meta("marker")
marker.text = "▼" if targeted else ""
var hp_bar: ProgressBar = plate.get_meta("hp_bar")
hp_bar.value = _ratio(float(enemy.get("hp", 0.0)), float(enemy.get("max_hp", 1.0)))
var shield_bar: ProgressBar = plate.get_meta("shield_bar")
var shield := float(enemy.get("shield", 0.0))
shield_bar.visible = shield > 0.0
shield_bar.value = 1.0
## Test helpers: the centre of a real hit target in screen coordinates.
func enemy_hit_center(unit_id: String) -> Vector2:
var area: Control = _enemy_hit_areas.get(unit_id)
if area == null:
return Vector2.ZERO
return area.global_position + area.size * 0.5
func named_button_center(button_name: String) -> Vector2:
var button := find_child(button_name, true, false) as Control
if button == null:
return Vector2.ZERO
return button.global_position + button.size * 0.5
## Play the hit state on a unit that just took damage.
func play_unit_hit(unit_id: String) -> void:
var view: UnitView = _unit_views.get(unit_id)
if view == null:
return
view.play_once("hit", "idle")
view.flash(Color(1.0, 0.92, 0.78), 0.14)
## Place the visible heroes in the lower band of the stage.
func _sync_hero_units(roster: Array) -> void:
if _units_layer == null or _stage_inner == null:
return
var margin := BattleHudLayout.STAGE_INNER_MARGIN
var usable_width := maxf(1.0, _stage_inner.size.x - margin * 2.0)
var count := maxi(1, roster.size())
var slot := usable_width / float(count)
var alive_ids: Array[String] = []
for hero in roster:
alive_ids.append(str(hero.get("id", "")))
for key in _hero_views.keys():
if not alive_ids.has(str(key)):
var stale: UnitView = _hero_views[key]
stale.queue_free()
_hero_views.erase(key)
for index in range(roster.size()):
var hero: Dictionary = roster[index]
var hero_id := str(hero.get("id", ""))
var view: UnitView = _hero_views.get(hero_id)
if view == null:
view = UnitView.new()
view.name = "hero_%s" % hero_id
if not view.configure(_art_id_for(hero_id), ["idle", "attack"]):
view.queue_free()
continue
_units_layer.add_child(view)
_hero_views[hero_id] = view
var center_x := margin + slot * (float(index) + 0.5)
view.position = Vector2(round(center_x), BattleHudLayout.STAGE_HERO_FOOT_Y)
view.modulate = Color(0.86, 0.88, 0.94, 1.0)
func set_roster(roster: Array) -> void:
_sync_hero_units(roster)
for child in _roster_row.get_children():
child.queue_free()
if roster.is_empty():
@@ -731,7 +902,19 @@ func _on_ultimate_pressed() -> void:
func _on_enemy_card_input(event: InputEvent, enemy_id: String) -> void:
if event is InputEventScreenTouch and event.pressed:
target_selected.emit(enemy_id)
elif event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
target_selected.emit(enemy_id)
var is_touch: bool = event is InputEventScreenTouch and event.pressed
var is_mouse: bool = (
event is InputEventMouseButton
and event.pressed
and event.button_index == MOUSE_BUTTON_LEFT
)
if not (is_touch or is_mouse):
return
# Godot emulates a mouse press from a touch by default, so one real touch
# can deliver both a ScreenTouch and a MouseButton to this handler. Debounce
# them so a single tap selects the target once.
var now := Time.get_ticks_usec()
if now - _last_enemy_tap_usec < 60_000:
return
_last_enemy_tap_usec = now
target_selected.emit(enemy_id)
@@ -78,6 +78,16 @@ const STAGE_MIN_HEIGHT := 200.0
## Share of extra height that goes to the stage on taller screens.
const STAGE_GROW_SHARE := 0.6
## Inside the battle stage: the enemy band sits above the visible hero band,
## matching the portrait contract (enemies on top, the company below).
## All values are relative to the stage inner area.
const STAGE_INNER_MARGIN := 8.0
const STAGE_ENEMY_FOOT_Y := 112.0
const STAGE_HERO_FOOT_Y := 296.0
const STAGE_ENEMY_PLATE_Y := 116.0
const STAGE_HERO_PLATE_Y := 300.0
const STAGE_UNIT_PLATE_HEIGHT := 50.0
## Compute the height of every region for a given content height.
##
+117 -9
View File
@@ -12,6 +12,7 @@ extends Node2D
const HUD_SCENE := preload("res://scenes/battle_hud.tscn")
const SEED_PATH := "res://../data/mvp_validation_seed_pack.json"
const CONTENT_PATH := "res://../data/mvp_content_fixture.json"
const TICK_SECONDS := 0.1
const STORM_COOLDOWN_SECONDS := 10.0
@@ -32,11 +33,15 @@ var targeted_id := ""
var gold := 0
var crystal := 0
var round_index := 1
var hero_levels: Dictionary = {}
var roster_bonus := 0.0
var finished := false
var _accumulator := 0.0
var _seed_pack: Dictionary = {}
var _reward_ids: Dictionary = {}
var _last_enemy_hp: Dictionary = {}
var _reward_granted := false
func _ready() -> void:
@@ -48,6 +53,7 @@ func _ready() -> void:
add_child(layer)
hud = HUD_SCENE.instantiate() as BattleHud
layer.add_child(hud)
hud.set_art_binding(_load_art_binding())
hud.target_selected.connect(_on_target_selected)
hud.tap_started.connect(_on_tap_started)
hud.tap_stopped.connect(_on_tap_stopped)
@@ -74,7 +80,88 @@ func _read_json(path: String) -> Dictionary:
return parsed
## Prepare a scenario. Safe to call again to restart.
## Content id to art id, owned by the content fixture.
func _load_art_binding() -> Dictionary:
var binding: Dictionary = {}
var content := _read_json(CONTENT_PATH)
for group in ["heroes", "enemies", "validation_pressure_enemies", "bosses"]:
for row in content.get(group, []):
var content_id := str(row.get("id", ""))
var art_id := str(row.get("art_id", ""))
if not content_id.is_empty() and not art_id.is_empty():
binding[content_id] = art_id
return binding
## Permanent progress survives a new battle; use this for a fresh run.
func reset_progress() -> void:
gold = 0
crystal = 0
round_index = 1
hero_levels.clear()
for hero_id in rules.get("heroes", {}).keys():
hero_levels[str(hero_id)] = int(rules.get("progression", {}).get("initial_level", 1))
roster_bonus = 0.0
func level_of(hero_id: String) -> int:
return int(hero_levels.get(hero_id, 1))
func upgrade_cost(hero_id: String) -> int:
var progression: Dictionary = rules.get("progression", {})
var base := float(progression.get("upgrade_base_cost", 120))
var growth := float(progression.get("upgrade_cost_growth", 1.15))
var steps := maxi(0, level_of(hero_id) - int(progression.get("initial_level", 1)))
return int(round(base * pow(growth, float(steps))))
func hero_dps(hero_id: String) -> float:
var hero: Dictionary = rules.get("heroes", {}).get(hero_id, {})
var base := float(hero.get("base_dps", 0.0))
var progression: Dictionary = rules.get("progression", {})
var ratio := float(progression.get("dps_per_level_ratio", 0.25))
var initial := int(progression.get("initial_level", 1))
return base * (1.0 + ratio * float(maxi(0, level_of(hero_id) - initial)))
func base_roster_dps() -> float:
var total := 0.0
for hero in rules.get("heroes", {}).values():
total += float(hero.get("base_dps", 0.0))
return total
func effective_roster_dps() -> float:
var total := 0.0
for hero_id in rules.get("heroes", {}).keys():
total += hero_dps(str(hero_id))
return total
func grant_victory_reward(reward_id: String) -> Dictionary:
var amounts: Dictionary = rules.get("reward_amounts", {}).get(reward_id, {})
var gained_gold := int(amounts.get("gold", 0))
var gained_crystal := int(amounts.get("crystal", 0))
gold += gained_gold
crystal += gained_crystal
return {"gold": gained_gold, "crystal": gained_crystal}
func purchase_upgrade(hero_id: String) -> bool:
var cost := upgrade_cost(hero_id)
if gold < cost:
return false
gold -= cost
hero_levels[hero_id] = level_of(hero_id) + 1
roster_bonus = effective_roster_dps() - base_roster_dps()
if roster_bonus < 0.0:
roster_bonus = 0.0
return true
## Prepare a scenario. Safe to call again to restart a battle while keeping
## permanent progress.
func setup(
requested_locale: String = "zh_CN",
scenario_id: String = "P3A-N03-SEMI",
@@ -88,17 +175,18 @@ func setup(
if scenario.is_empty():
push_error("Unknown scenario %s" % scenario_id)
return
if hero_levels.is_empty():
reset_progress()
var timeout := float(scenario.get("timeout_seconds", 60.0))
state = P2BattleSim.create_state(rules, scenario, seed_value, timeout)
state = P2BattleSim.create_state(rules, scenario, seed_value, timeout, roster_bonus)
finished = false
_reward_granted = false
_accumulator = 0.0
tap_active = false
storm_cooldown = 0.0
ultimate_energy = ULTIMATE_ENERGY_MAX
targeted_id = ""
gold = 0
crystal = 0
round_index = 1
_last_enemy_hp.clear()
if hud != null:
hud.set_locale(locale)
hud.set_nav_active("expedition")
@@ -183,6 +271,13 @@ func _refresh() -> void:
var enemies: Array = []
for enemy in state["enemies"]:
enemies.append(enemy)
# An enemy that lost HP since the last refresh plays its hit state.
for enemy in enemies:
var unit_id := str(enemy.get("id", ""))
var hp := float(enemy.get("hp", 0.0))
if _last_enemy_hp.has(unit_id) and float(_last_enemy_hp[unit_id]) > hp:
hud.play_unit_hit(unit_id)
_last_enemy_hp[unit_id] = hp
hud.set_enemies(enemies, targeted_id)
var roster: Array = []
@@ -204,9 +299,9 @@ func _refresh() -> void:
hud.set_growth(
first_hero,
UiText.t("content.hero.%s" % first_hero, locale),
3,
120,
float(state["roster_dps"])
level_of(first_hero),
upgrade_cost(first_hero),
effective_roster_dps()
)
var timeout := float(state["timeout_seconds"])
@@ -235,6 +330,10 @@ func _refresh() -> void:
reward_id = (
"DROP-R1-BOSS-01" if victory else "REWARD-R1-C01-N10"
)
if victory and not _reward_granted:
_reward_granted = true
grant_victory_reward(reward_id)
round_index += 1
var reward_text := ""
if victory:
reward_text = (
@@ -312,10 +411,19 @@ func _on_ultimate_override(_hero_id: String) -> void:
func _on_upgrade_requested(_hero_id: String) -> void:
gold = max(0, gold - 120)
var hero_id := "H01"
if not state["visible_hero_ids"].is_empty():
hero_id = str(state["visible_hero_ids"][0])
if purchase_upgrade(hero_id):
show_toast(UiText.tf("hud.growth.cost", {"gold": gold}, locale))
_refresh()
func show_toast(message: String) -> void:
if hud != null:
hud.set_hint(message)
func _on_speed_changed(multiplier: float) -> void:
speed = multiplier
_refresh()
+5 -1
View File
@@ -170,7 +170,8 @@ static func create_state(
rules: Dictionary,
scenario: Dictionary,
seed_value: int,
timeout_seconds: float
timeout_seconds: float,
roster_bonus: float = 0.0
) -> Dictionary:
var scenario_id := str(scenario.get("id", ""))
var mode := str(scenario.get("mode", ""))
@@ -190,6 +191,9 @@ static func create_state(
var roster_dps := 0.0
for hero in heroes.values():
roster_dps += float(hero.get("base_dps", 0.0))
# Permanent hero levels add a roster bonus. Batch runs pass 0, so their
# output stays byte-identical to the paper runner.
roster_dps += roster_bonus
var enemies: Array = []
var enemy_ids: Array = scenario.get("enemy_ids", [])
@@ -0,0 +1,116 @@
extends SceneTree
## Runtime economy loop test.
##
## Proves that the player-facing loop works in the running game rather than
## only on paper: win -> reward -> gold -> upgrade -> higher roster DPS ->
## the next battle actually uses the upgraded DPS. Also checks duplicate
## reward suppression and that failing a battle grants no gold.
const OUTPUT_PATH := "res://artifacts/economy_loop_test.json"
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _run() -> void:
var scene = load("res://scripts/battle_scene.gd").new()
get_root().add_child(scene)
var battle := scene as BattleScene
battle.set_process(false)
battle.reset_progress()
var base_dps := battle.base_roster_dps()
_check(absf(base_dps - 65.0) < 0.001, "base roster DPS should be 65, got %s" % str(base_dps))
_check(battle.gold == 0, "a fresh profile should start with 0 gold")
_check(battle.crystal == 0, "a fresh profile should start with 0 crystal")
_record("initial", {"gold": battle.gold, "dps": battle.effective_roster_dps(), "level": battle.level_of("H01")})
# N01 pays 30 gold and the first upgrade costs 120: four clears are the
# intended early pacing, so replay rather than weakening the economy.
for run_index in range(4):
battle.setup("zh_CN", "P3A-N01-AUTO", 10001)
battle.advance_ticks(200)
_check(str(battle.state.get("result", "")) == "win", "N01 auto should win on run %d" % (run_index + 1))
_check(battle.gold == 120, "four N01 wins should grant 120 gold, got %d" % battle.gold)
_check(battle.crystal == 0, "N01 grants no crystal")
_record("victory", {"gold": battle.gold, "crystal": battle.crystal, "round": battle.round_index})
# Re-rendering the settled frame must not pay the reward twice.
battle.advance_ticks(1)
_check(battle.gold == 120, "duplicate reward grant must not add gold")
_record("duplicate_reward_guard", {"gold": battle.gold})
# Upgrade the first visible hero.
var cost := battle.upgrade_cost("H01")
var dps_before := battle.effective_roster_dps()
var level_before := battle.level_of("H01")
var bought := battle.purchase_upgrade("H01")
_check(bought, "the upgrade should be affordable with 30 gold")
_check(battle.gold == 120 - cost, "the upgrade should cost %d gold" % cost)
_check(battle.level_of("H01") == level_before + 1, "the hero level should increase")
_check(
battle.effective_roster_dps() > dps_before,
"upgrading should raise roster DPS from %s" % str(dps_before)
)
_record("upgrade", {
"gold": battle.gold, "cost": cost, "level": battle.level_of("H01"),
"dps_before": dps_before, "dps_after": battle.effective_roster_dps()
})
# The next battle must actually use the upgraded DPS.
battle.setup("zh_CN", "P3A-N01-AUTO", 10001)
var sim_dps := float(battle.state.get("roster_dps", 0.0))
_check(
absf(sim_dps - battle.effective_roster_dps()) < 0.001,
"the new battle should use the upgraded roster DPS: sim=%s profile=%s"
% [str(sim_dps), str(battle.effective_roster_dps())]
)
_check(sim_dps > 65.0, "the new battle should be stronger than the base 65 DPS")
_record("next_battle", {"sim_dps": sim_dps, "gold": battle.gold})
# A loss grants nothing.
battle.setup("zh_CN", "P3A-N03-SEMI", 10001)
battle.advance_ticks(300)
var gold_before_loss := battle.gold
_check(str(battle.state.get("result", "")) == "timeout", "N03 seed 10001 should time out")
_check(battle.gold == gold_before_loss, "a loss must not grant gold")
_record("loss", {"gold": battle.gold, "result": str(battle.state.get("result", ""))})
var passed := _problems.is_empty()
var report := {
"schema": 1,
"kind": "windroost_economy_loop_test",
"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("economy_loop_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _steps:
print("ECONOMY_STEP %s" % JSON.stringify(entry))
if passed:
print("ECONOMY_LOOP_PASS %d stages verified" % _steps.size())
else:
print("ECONOMY_LOOP_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)
+133
View File
@@ -0,0 +1,133 @@
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
+173
View File
@@ -0,0 +1,173 @@
class_name UnitView
extends Node2D
## Runtime unit renderer for the battle stage.
##
## Each unit state is a fixed-grid animation atlas produced by
## `tools/pack_animation_strip.py`, with one shared scale and one shared foot
## line across all frames of that state. That is what keeps the character
## from jumping between frames.
##
## The node origin is the unit's foot line, so units can be placed by their
## ground position without any per-frame correction.
## Textures have to live inside the project to be imported, so the animation
## atlases are linked into `assets/` and addressed from there.
const CHARACTER_DIR := "res://assets/"
var character_id := ""
var _states: Dictionary = {}
var _sprite: Sprite2D
var _current := ""
var _frame_index := 0
var _elapsed := 0.0
var _returning_to := ""
var _flash_time := 0.0
var _flash_duration := 0.0
var _flash_color := Color(1, 1, 1, 1)
func _ready() -> void:
_ensure_sprite()
func _ensure_sprite() -> void:
if _sprite != null and is_instance_valid(_sprite):
return
_sprite = Sprite2D.new()
_sprite.name = "Art"
_sprite.centered = true
_sprite.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
add_child(_sprite)
## Load one or more states for a character. Returns false when no state could
## be loaded, which means the unit has no approved art yet.
func configure(id: String, state_list: Array) -> bool:
character_id = id
_states.clear()
_ensure_sprite()
for state in state_list:
var loaded := _load_state(str(state))
if loaded:
_states[str(state)] = loaded
if _states.is_empty():
return false
if _states.has("idle"):
set_state("idle")
else:
set_state(str(_states.keys()[0]))
return true
func _load_state(state: String) -> Dictionary:
var base := "%s/%s_%s_anim" % [CHARACTER_DIR, character_id, state]
var manifest_path := base + ".manifest.json"
var texture_path := base + ".png"
var file := FileAccess.open(manifest_path, FileAccess.READ)
if file == null:
return {}
var parsed = JSON.parse_string(file.get_as_text())
file.close()
if not parsed is Dictionary:
return {}
var texture := load(texture_path) as Texture2D
if texture == null:
return {}
var frames: Array = []
for frame in parsed.get("frames", []):
var rect: Array = frame.get("atlas_rect", [])
if rect.size() != 4:
continue
frames.append(Rect2(float(rect[0]), float(rect[1]), float(rect[2]), float(rect[3])))
if frames.is_empty():
return {}
var cell: Array = parsed.get("cell_size", [96, 96])
var foot_y := float(parsed.get("foot_y", cell[1]))
return {
"texture": texture,
"frames": frames,
"fps": float(parsed.get("fps", 8)),
"loop": bool(parsed.get("loop", false)),
"cell": [float(cell[0]), float(cell[1])],
"foot_y": foot_y,
}
func has_state(state: String) -> bool:
return _states.has(state)
func set_state(state: String) -> void:
if not _states.has(state) or state == _current:
return
_current = state
_frame_index = 0
_elapsed = 0.0
_returning_to = ""
_apply_frame()
## Play a non-looping state once, then fall back to `fallback`.
func play_once(state: String, fallback: String = "idle") -> void:
if not _states.has(state):
return
_current = state
_frame_index = 0
_elapsed = 0.0
_returning_to = fallback
func flash(color: Color = Color(1, 1, 1, 1), duration: float = 0.12) -> void:
_flash_color = color
_flash_duration = duration
_flash_time = duration
func _process(delta: float) -> void:
if _states.is_empty():
return
if _flash_time > 0.0:
_flash_time = maxf(0.0, _flash_time - delta)
var ratio := _flash_time / maxf(0.001, _flash_duration)
_sprite.modulate = Color(1, 1, 1, 1).lerp(_flash_color, ratio)
else:
_sprite.modulate = Color(1, 1, 1, 1)
var state: Dictionary = _states.get(_current, {})
var frames: Array = state.get("frames", [])
if frames.size() <= 1:
return
_elapsed += delta
var fps := float(state.get("fps", 8))
var frame_duration := 1.0 / maxf(0.1, fps)
while _elapsed >= frame_duration:
_elapsed -= frame_duration
_frame_index += 1
if _frame_index >= frames.size():
if state.get("loop", false):
_frame_index = 0
else:
_frame_index = frames.size() - 1
if not _returning_to.is_empty() and _states.has(_returning_to):
var fallback := _returning_to
_returning_to = ""
set_state(fallback)
return
_apply_frame()
func _apply_frame() -> void:
var state: Dictionary = _states.get(_current, {})
var frames: Array = state.get("frames", [])
if frames.is_empty():
return
_sprite.texture = state.get("texture")
_sprite.region_enabled = true
_sprite.region_rect = frames[_frame_index]
var cell: Array = state.get("cell", [96.0, 96.0])
var foot_y := float(state.get("foot_y", cell[1]))
# The node origin is the foot line, so the art has to be lifted by the
# distance between the cell centre and the foot line.
_sprite.offset = Vector2(0.0, -(foot_y - float(cell[1]) * 0.5))
+152
View File
@@ -0,0 +1,152 @@
#!/usr/bin/env python3
"""Pack an animation state into a fixed-grid, foot-aligned runtime atlas.
Why this exists
---------------
`chroma_key_atlas.py` normalises one cell at a time, so it is right for a
single frame per state but wrong for animation: every frame would get its own
scale and its own vertical placement, and the character would jitter on every
frame change.
This packer takes all frames of one state and gives them:
* one shared scale, derived from the union of every frame's alpha box;
* one shared foot line, so the character's feet never move between frames;
* a fixed cell grid, so the runtime can address frames by index.
The output atlas keeps transparency, so the runtime can composite it directly
over the battle background with nearest filtering.
Usage:
python3 tools/pack_animation_strip.py \
--character H01 --state idle \
--frames PRODUCTION/source/sprite_runs/H01/run/frames/idle \
--output-dir PRODUCTION/source/pixel_pilot/characters/H01
"""
from __future__ import annotations
import argparse
import hashlib
import json
from pathlib import Path
from typing import Dict, List, Sequence, Tuple
from PIL import Image
FRAME_ORDER = ("frame-0", "frame-1", "frame-2", "frame-3", "frame-4", "frame-5", "frame-6")
def frame_files(folder: Path) -> List[Path]:
files = [item for item in folder.iterdir() if item.suffix.lower() == ".png"]
def sort_key(path: Path) -> Tuple[int, str]:
digits = "".join(ch for ch in path.stem if ch.isdigit())
return (int(digits) if digits else 999, path.stem)
return sorted(files, key=sort_key)
def union_alpha_box(images: Sequence[Image.Image]) -> Tuple[int, int, int, int]:
union: List[int] = [0, 0, 0, 0]
for image in images:
box = image.getchannel("A").getbbox()
if box is None:
continue
union[0] = min(union[0], box[0])
union[1] = min(union[1], box[1])
union[2] = max(union[2], box[2])
union[3] = max(union[3], box[3])
if union[2] <= union[0] or union[3] <= union[1]:
raise ValueError("no visible pixels in the supplied frames")
return (union[0], union[1], union[2], union[3])
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--character", required=True)
parser.add_argument("--state", required=True)
parser.add_argument("--frames", required=True, type=Path, help="directory holding the frame PNGs")
parser.add_argument("--output-dir", required=True, type=Path)
parser.add_argument("--canvas", type=int, default=128, help="logical cell size in pixels")
parser.add_argument("--fit", type=float, default=0.86, help="maximum art ratio inside the cell")
parser.add_argument("--fps", type=int, default=8)
parser.add_argument("--loop", action="store_true")
parser.add_argument("--resample", choices=("nearest", "lanczos"), default="nearest")
args = parser.parse_args()
files = frame_files(args.frames)
if not files:
raise SystemExit(f"no frame PNGs found in {args.frames}")
images = [Image.open(path).convert("RGBA") for path in files]
union = union_alpha_box(images)
canvas = args.canvas
art_w = union[2] - union[0]
art_h = union[3] - union[1]
scale = min((canvas * args.fit) / art_w, (canvas * args.fit) / art_h)
scaled_size = (max(1, round(art_w * scale)), max(1, round(art_h * scale)))
foot_y = round(canvas * 0.88)
resample = (
Image.Resampling.NEAREST
if args.resample == "nearest"
else Image.Resampling.LANCZOS
)
count = len(images)
atlas = Image.new("RGBA", (canvas * count, canvas), (0, 0, 0, 0))
entries: List[Dict[str, object]] = []
for index, (path, image) in enumerate(zip(files, images)):
cropped = image.crop(union)
resized = cropped.resize(scaled_size, resample)
offset_x = (canvas - scaled_size[0]) // 2
offset_y = foot_y - scaled_size[1]
frame = Image.new("RGBA", (canvas, canvas), (0, 0, 0, 0))
frame.alpha_composite(resized, (offset_x, offset_y))
atlas.alpha_composite(frame, (index * canvas, 0))
entries.append({
"name": path.stem,
"atlas_rect": [index * canvas, 0, canvas, canvas],
"cell_offset": [offset_x, offset_y],
"size": list(scaled_size),
})
args.output_dir.mkdir(parents=True, exist_ok=True)
name = f"{args.character}_{args.state}_anim"
atlas_path = args.output_dir / f"{name}.png"
atlas.save(atlas_path)
digest = hashlib.sha256(atlas_path.read_bytes()).hexdigest()
manifest = {
"schema": 1,
"status": "runtime",
"character_id": args.character,
"state": args.state,
"frame_count": count,
"fps": args.fps,
"loop": bool(args.loop),
"cell_size": [canvas, canvas],
"atlas_size": list(atlas.size),
"logical_canvas": [canvas, canvas],
"fit": args.fit,
"scale": round(scale, 6),
"foot_y": foot_y,
"resample": args.resample,
"source_frames": [str(path) for path in files],
"union_alpha_bbox": list(union),
"atlas_sha256": digest,
"frames": entries,
}
manifest_path = args.output_dir / f"{name}.manifest.json"
manifest_path.write_text(
json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8"
)
print(
f"packed {args.character}/{args.state}: {count} frames, "
f"cell {canvas}px, art {scaled_size[0]}x{scaled_size[1]}, foot_y={foot_y} -> {atlas_path}"
)
return 0
if __name__ == "__main__":
raise SystemExit(main())
+2
View File
@@ -28,6 +28,8 @@ run_step "runtime parity gate" python3 tools/mvp_parity_gate.py
run_step "godot headless smoke" "$ROOT_DIR/p2_godot_sample/run_headless_smoke.sh"
run_step "godot save smoke" "$ROOT_DIR/p2_godot_sample/run_save_smoke.sh"
run_step "speed equivalence" "$ROOT_DIR/p2_godot_sample/run_speed_equivalence.sh"
run_step "real screen touch" "$ROOT_DIR/p2_godot_sample/run_touch_test.sh"
run_step "runtime economy loop" "$ROOT_DIR/p2_godot_sample/run_economy_loop_test.sh"
run_step "ui capture matrix" "$ROOT_DIR/p2_godot_sample/run_capture.sh"
print ""