Skip to content

feat(#1): 自機移動と Projectile 射撃システム (AC1-AC22) - #444

Merged
squne121 merged 2 commits into
mainfrom
worktree-issue-1-jiki-ido-to-projectile-shageki-system
May 28, 2026
Merged

squne121 merged 2 commits into
mainfrom
worktree-issue-1-jiki-ido-to-projectile-shageki-system

Conversation

@squne121

@squne121 squne121 commented May 28, 2026 •

Copy link
Copy Markdown
Owner

Closes #1

Summary

  • iteration 2 fixes: SimulationLoop production wiring / AC14 last-aim fallback / clamp invariant / blur+visibility reset / setTransform 明示化
  • ProjectileState 型と projectiles[]/nextProjectileId を GameState に追加し、Projectile ライフサイクルの state 契約を固定
  • CombatSystem を fire/cooldown/spawn に限定し progress.resources の非意図的 mutate を除去
  • ProjectileSystem(新規)が direction * speed * dt 移動・ageMs 管理・lifetime/境界外削除を担当
  • SimulationLoop(新規純関数)で panic clamp 残余破棄をテスト可能に切り出し; src/main.ts が advanceSimulationLoop() を呼ぶよう接続済み
  • InputBindings(新規)で KeyboardEvent.code(KeyW/A/S/D)と PointerEvent lifecycle(setPointerCapture/pointercancel/lostpointercapture)を実装; blur/visibilitychange 時に入力リセット追加
  • CanvasRenderer に devicePixelRatio backing store 拡大と Projectile 円描画を追加; context.scale → setTransform に変更
  • touch-action: none を canvas に CSS 適用
  • PlayerState に runtime-only lastAimDirectionX/Y を追加(GameSnapshot 対象外); 同一点 aim fallback で前回 aim 方向を利用(AC14)
  • clampPlayerToArena() を独立 export として切り出し; move command なし / resize 後でも invariant 保証

Schema Change Applicability

not_schema_change

  • 変更対象は in-memory runtime state(GameState.projectiles / nextProjectileId / lastAimDirectionX/Y)の追加であり、永続化フォーマット・wire format・on-disk schema を含まない。
  • createGameSnapshot の出力 schema(resources / weaponPower / playerMaxHp)は 変更なし。localStorage 永続化される GameSnapshot は backwards-compatible。
  • 既存セーブデータの読み込み挙動には影響しない(projectiles は runtime 初期化時に空配列で生成、永続化対象外)。
  • 公開 API / イベント / メッセージスキーマの変更なし。

Safety Claim Matrix

N/A

  • 本 PR は単体 implementation Issue 実装: 自機移動と Projectile 射撃システム #1 の deterministic な状態更新ロジック(座標・速度・寿命)と入力 adapter の追加であり、認証・権限・暗号・外部 I/O・データ削除・PII を扱わない。
  • 既存の no-secret 境界(docs/dev/secret-policy.md)に影響する要素なし(VITE_* への sensitive 値追加なし、external API 呼び出しなし)。

Scope Delta

Issue #1 の Allowed Paths に対し、以下 3 ファイルを 追加スコープ として変更している。AC3「panic clamp 残余破棄をテスト可能な純関数 / ヘルパに切り出し」を実現するための最小派生で、Issue contract の意図と整合する。

追加パス 根拠
src/systems/SimulationLoop.ts(新規) AC3 が要求する「panic clamp 残余破棄をテスト可能な純関数 / ヘルパに切り出し」を満たすため、runFixedTimestep 純関数を Issue Allowed Paths の src/systems/ 配下に新設
src/systems/index.ts 上記新規 export を既存 barrel に追加(barrel の最小変更)
tests/main-loop.test.ts(新規) AC3 の panic clamp 残余破棄を unit test で検証するため新設(Issue 本文「Required Tests」末尾で言及済み)

Issue #1 本文の ## Allowed Paths に同 3 件を Scope Delta として追記済み: #1

受け入れ条件の達成状況

  • AC1: 60Hz 固定タイムステップ(fixedDeltaMs = 1000/60 / SimulationConfig.ts)
  • AC2: maxFrameSkip = 5 で catch-up step 上限化(SimulationConfig.ts / main.ts)
  • AC3: accumulatorMs = accumulatorMs % fixedDeltaMs で残余破棄(src/main.ts が advanceSimulationLoop() 経由 / SimulationLoop.ts 純関数 / tests/main-loop.test.ts)
  • AC4: cooldown が weaponCooldownMs -= deltaMs(simulation tick)で管理(CombatSystem.ts、wall clock 非依存)
  • AC5: KeyboardEvent.code(KeyW/KeyA/KeyS/KeyD)で取得し InputCommand に正規化(src/input/InputBindings.ts)
  • AC6: 斜め入力の正規化(MovementSystem.ts の Math.hypot / tests/movement-system.test.ts)
  • AC7: [player.radius, arena_size - player.radius] boundary clamp(MovementSystem.ts / tests/movement-system.test.ts); move command なし / resize 後も保証
  • AC8: aim を {aimX, aimY} で保持し角度を GameState/InputCommand に保持しない(CombatSystem で派生計算)
  • AC9: pointerdown で event.isPrimary && event.button === 0 のみ受理、canvas.setPointerCapture(event.pointerId) 呼び出し(InputBindings.ts)
  • AC10: capture 中の pointerId に一致する pointermove のみ aim 更新(InputBindings.ts)
  • AC11: pointerup / pointercancel / lostpointercapture で primaryPressed = false(InputBindings.ts)
  • AC12: canvas に touch-action: none を CSS 適用(src/style.css)
  • AC13: primary pointer hold 中の自動連射(tests/combat-system.test.ts)
  • AC14: AIM_EPSILON_PX = 0.001 未満で前回 aim 方向保存・利用 fallback、初期値 +X(PlayerState.lastAimDirectionX/Y / CombatSystem.ts / tests/combat-system.test.ts — 上方向 aim → 同一点 aim → 上方向 projectile を検証)
  • AC15: ProjectileState(id / x / y / radius / directionX / directionY / speedPxPerSec / ageMs / lifetimeMs)+ nextProjectileId を GameState.ts に追加
  • AC16: CombatSystem が progress.resources を mutate せず、damage 発生なし(tests/combat-system.test.ts で検証)
  • AC17: src/systems/ProjectileSystem.ts 新規作成
  • AC18: ageMs >= lifetimeMs または arena 境界 +margin で削除、残存順 deterministic(ProjectileSystem.ts / tests/projectile-system.test.ts)
  • AC19: devicePixelRatio で backing store 拡大 + setTransform(dpr,0,0,dpr,0,0)(CanvasRenderer.ts)
  • AC20: src/state / src/systems 配下に devicePixelRatio 参照なし(grep 確認済み)
  • AC21: MovementSystem → CombatSystem → ProjectileSystem → CollisionSystem の順で stepSimulation 内に統合(src/main.ts)
  • AC22: pnpm typecheck && pnpm lint && pnpm test && pnpm build が PASS(127 tests / 9 files)

Verification Commands Results

Command Result
pnpm typecheck PASS
pnpm lint PASS
pnpm test PASS (9 files, 127 tests)
pnpm build PASS

Runtime Verification Applicability

decision: deferred — ブラウザ上での実際の弾道・pointer 体感確認は feature spec PH-1〜PH-4 を扱う後続 playtest issue(M1 Foundation Gate phase)で実施。

Contract Snapshot

#1 (comment)

WASD 移動・PointerEvent 射撃・60Hz fixed timestep・Projectile Canvas 描画の
deterministic MVP を実装する。

主な変更:
- src/state/GameState.ts: ProjectileState 型と projectiles[]/nextProjectileId 追加
- src/systems/MovementSystem.ts: boundary clamp と斜め入力正規化を保証
- src/systems/CombatSystem.ts: resources 非 mutate、aim epsilon fallback、projectile spawn
- src/systems/ProjectileSystem.ts (新規): 移動・ageMs・lifetime/境界外削除
- src/systems/SimulationLoop.ts (新規): panic clamp をテスト可能な純関数に切り出し
- src/main.ts: panic clamp 残余破棄 (accumulatorMs % fixedDeltaMs) と ProjectileSystem 統合
- src/input/InputBindings.ts (新規): KeyboardEvent.code + PointerEvent lifecycle (setPointerCapture/pointercancel/lostpointercapture)
- src/render/CanvasRenderer.ts: devicePixelRatio 対応と Projectile 円描画
- src/style.css: canvas に touch-action: none 適用
- tests/: movement-system/combat-system/projectile-system/input-mapper/main-loop の拡充・新規

pnpm typecheck && pnpm lint && pnpm test (124 tests) && pnpm build: 全 PASS

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST_CHANGES

Mergeability

  • mergeable=MERGEABLE, mergeStateStatus=BLOCKED(DRAFT 状態によるブロック、Conflict なし)

Evidence Check

AC coverage: △ — PR 本文の ## AC VC Results は AC3/AC5/AC9/AC11/AC12/AC14/AC15/AC17/AC18/AC19/AC21 の 11 件のみ記載。AC1/AC2/AC4/AC6/AC7/AC8/AC10/AC13/AC16/AC20/AC22 の 11 件は pnpm test PASS で代替されているが、PR テンプレートが求める [x] AC<N>: <達成(根拠)> 形式のチェックボックス一覧がない。個別 AC の達成根拠が確認できない。

Allowed Paths: △ — 以下 3 ファイルが Issue ## Allowed Paths に未記載:

  • src/systems/SimulationLoop.ts(新規)
  • src/systems/index.ts(更新)
  • tests/main-loop.test.ts(新規)

AC3 の「テスト可能な純関数 / ヘルパに切り出し」で機能的に意図された変更と解釈可能。ただし Allowed Paths への明示的な記載がない。src/systems/index.ts は既存ファイルの更新であり src/systems/ 配下の整合上必要な変更。PR 本文の Allowed Paths Compliance: true — 変更は全て contract の Allowed Paths 内 主張は根拠が薄い。

CI Verification: PASS — build/lint/test/typecheck/python-test すべて pass(gh pr checks 確認済み)

検証コマンド結果: △ — pnpm typecheck/lint/test/build は PASS 記載あり。rg/test -f 系コマンドは表で記録あり。ただし全 AC VC(AC1〜AC22 の完全一覧)との対応付けがなく部分的。

Schema Change Applicability: × — PR テンプレートが必須とする ## Schema Change Applicability セクションが欠落。GameState.ts への ProjectileState 追加は TypeScript 内部型であり Initial Known Schemas(issue_contract/v1 等)には該当しないが、not_schema_change の明示宣言がない。SKILL Step 4.5 の「not_schema_change を明示し根拠が diff と一致している場合は不要」に該当するためには明示が必要。

Safety Claim Matrix: × — PR テンプレートが必須とする ## Safety Claim Matrix セクションが欠落。changed paths・diff キーワードに safety-sensitive 条件は認められず N/A と判断されるが、N/A の一行記載もない。

Runtime Verification Applicability: PASS — decision: deferred を明示し、deferred_destination に後続 playtest issue への参照あり。Issue の <!-- runtime-verification: deferred --> と一致。

Blockers

  1. [BLOCKER] PR テンプレート必須セクションの欠落 — Schema Change Applicability: ## Schema Change Applicability セクションが存在しない。not_schema_change の明示と根拠(GameState への ProjectileState 追加が Initial Known Schemas の変更でない理由)を記載してください。APPROVE 禁止条件(SKILL Step 4.5)。

  2. [BLOCKER] PR テンプレート必須セクションの欠落 — Safety Claim Matrix: ## Safety Claim Matrix セクションが存在しない。changed paths・diff に safety-sensitive 条件が認められない場合は N/A と理由一行の記載で足ります。APPROVE 禁止条件(SKILL Step 4.6)。

  3. [BLOCKER] Allowed Paths の逸脱または未記載: src/systems/SimulationLoop.ts、src/systems/index.ts、tests/main-loop.test.ts が Issue ## Allowed Paths に記載されていない。PR 本文の「変更は全て contract の Allowed Paths 内」主張が成立していない。Allowed Paths 逸脱として記録(SKILL Step 4 Allowed Paths 遵守チェック)。

    補足: AC3「テスト可能な純関数 / ヘルパに切り出し」という仕様意図からすると SimulationLoop.ts は意図された変更と読めるため、Issue ## Allowed Paths にこの 3 ファイルを追記 または PR 本文で逸脱の根拠と Issue 担当者承認を明示することで解消できます。

  4. [BLOCKER] AC coverage の形式不備: PR テンプレートが求める ## 受け入れ条件の達成状況 のチェックボックス一覧([x] AC<N>: <達成(根拠)>)が存在しない。AC1〜AC22 の全件について、達成根拠の記載が必要です。

Non-blockers

  1. mergeStateStatus=BLOCKED は DRAFT 状態によるものと推測。Ready for Review への移行と同時に解消見込み。確認推奨。

LOOP_VERDICT

verdict: REQUEST_CHANGES
blockers:
  - schema_change_applicability_section_missing
  - safety_claim_matrix_section_missing
  - allowed_paths_undeclared_files
  - ac_coverage_format_missing
mergeable: MERGEABLE
mergeStateStatus: BLOCKED
reviewed_head_sha: f2bfa15014d6347b9fec28298007819f5fe33505
follow_up_issue_requests: []

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

iteration: 1 — 前回 iteration 0 で指摘した 4 blockers(Schema Change Applicability / Safety Claim Matrix / Allowed Paths Scope Delta / AC checkbox list)がすべて解消された。

Mergeability

  • mergeable=MERGEABLE, mergeStateStatus=CLEAN

Evidence Check

  • AC coverage: 全 22 件 [x] 済み・根拠記載あり
  • Allowed Paths: 全 16 ファイルが issue Allowed Paths または Scope Delta(SimulationLoop.ts / systems/index.ts / main-loop.test.ts)に収まる。Issue #1 の Allowed Paths に Scope Delta 追記済みで整合。
  • CI Verification: build / lint / python-test / test / typecheck / Generate agent session manifest がすべて pass
  • 検証コマンド結果: PR 本文 Verification Commands Results テーブルで pnpm typecheck / lint / test / build 全件 PASS 記録あり
  • Schema Change Applicability: not_schema_change を明示・根拠(GameState.projectiles は runtime 初期化のみ・永続化 schema 変更なし)が diff と整合
  • Safety Claim Matrix: N/A を明示・根拠(認証/権限/sandbox/MCP 非関与、決定論的状態更新のみ)が diff と整合
  • Runtime Verification: decision: deferred — M1 Foundation Gate playtest phase への deferred destination 参照あり
  • Scope Delta: PR 本文 Scope Delta テーブルと Issue #1 Allowed Paths が一致

Blockers

なし

Non-blockers(任意改善)

なし

LOOP_VERDICT

verdict: APPROVE
blockers: []
mergeable: MERGEABLE
mergeStateStatus: CLEAN
reviewed_head_sha: f2bfa15014d6347b9fec28298007819f5fe33505
follow_up_issue_requests: []

@squne121

Copy link
Copy Markdown
Owner Author

結論: REQUEST_CHANGES

既存レビューで指摘されていた Schema Change Applicability / Safety Claim / Allowed Paths / AC記載形式 は解消済みです。直近レビューでは APPROVE になっていますが、コードレベルではまだブロッカーがあります。特に、テストされている純関数が production loop に接続されていない 点と、AC14 の「前回aim方向 fallback」主張が実装されていない 点は、このPRの品質保証を崩しています。([GitHub]1)


参照した前提

Issue #1 は、WASD/矢印移動、左クリック/ポインタ押下射撃、60Hz固定ステップ、Canvas境界内移動、Projectileの直進・寿命・範囲外削除、Canvas描画、pnpm test / pnpm build を受け入れ条件にしています。敵・障害物衝突、ダメージ、AI、音、複雑な武器データ化は非ゴールです。([GitHub]2)

PR #444 は ProjectileState、projectiles[]、nextProjectileId、CombatSystem の射撃処理、ProjectileSystem、SimulationLoop、InputBindings、DPR対応Canvas描画、touch-action: none を追加した、Issue #1 対応PRです。PR本文ではAC1〜AC22の達成、Schema変更なし、安全性N/A、検証コマンドPASSを主張しています。([GitHub]1)


Blocker 1: SimulationLoop が production に未接続

PR本文では、panic clamp と residual discard を SimulationLoop.ts の純関数でテスト可能にした、と主張しています。実際に advanceSimulationLoop() は存在し、tests/main-loop.test.ts でテストされています。([GitHub]1)

しかし src/main.ts は advanceSimulationLoop() を import しておらず、frame loop 内で accumulator / while / panic clamp を直接実装しています。つまり、テスト対象の純関数は production loop の実体ではなく、production と test helper が将来分岐してもテストが検知できません。これはAC3の「main loop residual discard がテストされている」という主張を実質的に無効化します。([GitHub]3)

要求修正:

import { advanceSimulationLoop } from './systems/SimulationLoop'

function frame(now: number): void {
  const deltaMs = now - previousFrameTime
  previousFrameTime = now

  const result = advanceSimulationLoop(
    accumulatorMs,
    deltaMs,
    simulationConfig,
    stepSimulation,
  )

  accumulatorMs = result.accumulatorMs

  renderer.render(state)

  requestAnimationFrame(frame)
}

最低限、main.ts の accumulator 更新を advanceSimulationLoop() 経由にしてください。さらに、SimulationLoop のテスト名は「main-loop」ではなく「simulation-loop」に寄せるか、main.ts から実際に使われることを保証する integration test を追加すべきです。


Blocker 2: AC14 の「前回aim方向 fallback」が実装されていない

PR本文のAC14は、aim点が自機座標と同一の場合、AIM_EPSILON_PX = 0.001 以下なら 前回のaim方向に fallbackし、それもなければ +X と説明しています。([GitHub]1)

実装は異なります。CombatSystem はまず aim command で state.player.aimX/Y を上書きし、その後 dist < AIM_EPSILON_PX の場合は常に directionX = 1, directionY = 0 にしています。前回の非ゼロaim方向は保存も参照もされていません。テストも「同一点なら+X」しか確認しておらず、「前回aim方向を使う」分岐を検証していません。([GitHub]4)

これは仕様と実装の不一致です。PR本文だけでなく、操作感にも影響します。マウス/タッチ操作でポインタが自機中心に近い状態になった瞬間、最後に向いていた方向ではなく右方向に弾が出るため、プレイヤーからは不自然です。

要求修正案A: AC14どおり実装する

PlayerState に runtime-only の方向を追加します。

lastAimDirectionX: number
lastAimDirectionY: number

初期値は +X にします。

lastAimDirectionX: 1,
lastAimDirectionY: 0,

CombatSystem では、非ゼロaim時に last direction を更新し、同一点時はそれを使います。

if (distance >= AIM_EPSILON_PX) {
  directionX = dx / distance
  directionY = dy / distance
  state.player.lastAimDirectionX = directionX
  state.player.lastAimDirectionY = directionY
} else {
  directionX = state.player.lastAimDirectionX
  directionY = state.player.lastAimDirectionY
}

追加テスト:

it('uses previous non-zero aim direction when aim overlaps player', () => {
  // 先に上方向などへaimして lastAimDirection を作る
  // 次 tick で aim == player position にして fire
  // projectile.direction が +X ではなく前回方向であることを検証
})

要求修正案B: 実装に合わせてAC14を弱める

仕様として「同一点は常に +X」とするなら、PR本文・AC14・コメントから「previous aim direction fallback」を削除してください。ただしゲーム操作としては案Aのほうが妥当です。


Blocker 3: Canvas境界内保証が resize / idle 時に破れる

Issue #1 の受け入れ条件は「自機が Canvas 境界外に出ない」です。([GitHub]2)

MovementSystem は move command がない場合に即 return します。player clamp はその後の move 分岐内にしかありません。一方、main.ts の resizeArena() は arena.width / arena.height を更新するだけで、playerを再clampしません。つまり、広いCanvasの右端にいた状態でウィンドウを狭めると、次に移動入力が入るまで player が新しい arena 境界外に残り得ます。([GitHub]5)

これは通常操作で再現可能な境界不変条件の破れです。

要求修正:

clampを移動処理から分離してください。

export function clampPlayerToArena(state: GameState): void {
  const radius = state.player.radius
  state.player.x = clamp(state.player.x, radius, state.arena.width - radius)
  state.player.y = clamp(state.player.y, radius, state.arena.height - radius)
}

runMovementSystem() は、move command の有無に関係なく最後に clampPlayerToArena(state) を呼びます。resizeArena() 後にも同じ関数を呼びます。

追加テスト:

it('clamps player even when no movement command is present', () => {
  // playerをarena外に置く
  // move commandなしで runMovementSystem
  // 境界内に戻ること
})

it('clamps player after arena resize', () => {
  // 広いarena右端 → 狭いarenaにresize
  // playerが新arena内に収まること
})

Major: keyboard / pointer state が blur で stuck する可能性

InputBindings は keydown / keyup と pointer lifecycle を扱っていますが、window.blur や visibilitychange で入力状態をリセットしていません。タブ切替、Alt-Tab、DevTools focus、モバイルブラウザの中断で keyup / pointerup を取り逃がすと、移動または射撃が押下状態のまま残る可能性があります。現在のコードは key event と pointer event の通常経路だけを想定しています。([GitHub]6)

Pointer Events 自体はマウス・ペン・タッチを統合するモデルで、pointer capture と touch-action: none の使い方も方向性は妥当です。MDN の例でも canvas に touch-action: none を指定し、pointerdown / move / up / cancel を扱います。([MDN Web Docs]7)

ただし、ゲーム入力としては通常イベントだけでは不足です。

推奨修正:

function resetInput(): void {
  input.moveUp = false
  input.moveDown = false
  input.moveLeft = false
  input.moveRight = false
  input.primaryPressed = false
  capturedPointerId = undefined
}

window.addEventListener('blur', resetInput)
document.addEventListener('visibilitychange', () => {
  if (document.hidden) resetInput()
})

bindInput() の戻り値 cleanup にもこれらを含めてください。


Minor: DPR描画は概ね正しいが、transform設定を明示したほうが堅い

CanvasRenderer は DPR に応じて backing store を arena * dpr にし、CSSサイズは logical pixel のまま、context.scale(dpr, dpr) しています。この方針は HiDPI canvas の標準的な実装と一致します。([GitHub]8)

ただし、context.scale() は現在「canvas width/height 再代入で transform がリセットされる」ことに依存しています。現状では壊れていませんが、将来 backing store 再確保条件を変えると transform が累積するリスクがあります。Canvas 2D には resetTransform() や setTransform() があるため、ここは明示的にしたほうが安全です。([MDN Web Docs]9)

推奨:

context.setTransform(dpr, 0, 0, dpr, 0, 0)

または描画開始時に:

context.resetTransform()
context.scale(dpr, dpr)

良い点

ProjectileSystem は direction * speed * dt、age加算、lifetime / out-of-bounds filter という単純な実装で、Issue #1 のMVP範囲に収まっています。敵・障害物・damage・weapon data外部化に踏み込んでいない点も、非ゴールに沿っています。([GitHub]10)

GameState の snapshot schema を変えず、projectiles と nextProjectileId を runtime state に留めている点も妥当です。PR本文の「localStorage backward-compatible」という主張と整合します。([GitHub]11)

Pointer Events と touch-action: none の採用も、マウス・タッチ両対応のCanvasゲーム入力としては妥当です。([MDN Web Docs]7)


GitHubレビューコメント案

REQUEST_CHANGES

テンプレート/PR本文系の前回指摘は解消されていますが、コード側に3点ブロッカーがあります。

1. `SimulationLoop.ts` の `advanceSimulationLoop()` が production の `main.ts` から使われていません。テストは helper を検証していますが、実際の frame loop は `main.ts` に同等ロジックを直書きしており、AC3 の「panic clamp / residual discard が純関数としてテストされている」という主張が production に接続されていません。`main.ts` の accumulator 更新を `advanceSimulationLoop()` 経由にしてください。

2. AC14 は「同一点aim時は前回aim方向にfallback、それもなければ +X」と説明していますが、実装は常に +X fallback です。前回方向の保存/参照が存在せず、テストもこの分岐を検証していません。`lastAimDirectionX/Y` を runtime state に追加して実装するか、PR本文/AC14を実装に合わせて修正してください。ゲーム操作としては前者を要求します。

3. player clamp が move command のある tick にしか走りません。`resizeArena()` は arena width/height を変えるだけなので、広いCanvas端にいる状態でCanvasが縮むと、移動入力が入るまで自機が新しい境界外に残ります。Issue #1 の「Canvas境界外に出ない」に反します。clamp関数を分離し、movement有無に関係なく毎tick、かつ resize 後にも呼んでください。

非ブロッカーとして、`window.blur` / `visibilitychange` で input state を reset しないと keyup/pointerup 取り逃がしで移動・射撃が stuck し得ます。Canvas DPR対応は概ね正しいですが、`scale()` より `setTransform(dpr, 0, 0, dpr, 0, 0)` のほうが将来の累積transform事故に強いです。

以上の3ブロッカーを直せば、Issue #1 のMVPとしてはかなり安定します。現状のまま merge すると、「テストは通るが production loop が保証されていない」種類の負債を入れます。

… / clamp invariant / blur+visibility reset / setTransform

- src/main.ts: replace hand-written accumulator/while/panic with advanceSimulationLoop(); call clampPlayerToArena() in resizeArena()
- src/state/GameState.ts: add runtime-only lastAimDirectionX/Y to PlayerState (not in GameSnapshot)
- src/systems/CombatSystem.ts: save direction on normal aim; use lastAimDirection when dist < epsilon (AC14)
- src/systems/MovementSystem.ts: extract clampPlayerToArena() export; always clamp regardless of move command presence
- src/input/InputBindings.ts: resetInput() on window blur and document visibilitychange (guarded for non-browser envs)
- src/render/CanvasRenderer.ts: replace context.scale(dpr,dpr) with setTransform(dpr,0,0,dpr,0,0)
- tests: add clamp-without-move / resize-clamp tests; add AC14 last-aim fallback test (upward aim → same-position → uses last direction)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

iteration 2 として前回 REQUEST_CHANGES(Blocker 1-3 + 2 minor)の全件対応を確認。

Mergeability

  • mergeable=MERGEABLE, mergeStateStatus=CLEAN

Evidence Check

  • AC coverage: AC1〜AC22 全件 [x] 記載、各項目に根拠あり(placeholder なし)
  • Allowed Paths: 変更 15 ファイルが全て Issue #1 の Allowed Paths + Scope Delta 3 件(SimulationLoop.ts / systems/index.ts / main-loop.test.ts)の範囲内。Scope Delta は Issue 本文に追記済み
  • CI Verification: build/lint/typecheck/test/python-test 全 pass(GitHub Actions 確認済み)
  • 検証コマンド結果: PR 本文の Verification Commands Results テーブルに PASS 記録あり(127 tests / 9 files)

Blocker 1 解消確認: SimulationLoop production wiring

src/main.ts が advanceSimulationLoop を import し、frame() 内で advanceSimulationLoop(accumulatorMs, deltaMs, defaultSimulationConfig, stepSimulation) を呼び result.accumulatorMs で accumulator を更新している。production と test helper が同一実装であることを確認。

Blocker 2 解消確認: AC14 lastAimDirection fallback

PlayerState に lastAimDirectionX / lastAimDirectionY を追加(初期値 +X)。CombatSystem で非ゼロ aim 時に persist し、dist < AIM_EPSILON_PX 時に参照。tests/combat-system.test.ts に「上方向 aim → 同一点 aim → 上方向 projectile」の分岐テストが追加されていることを確認(lastAimDirectionY が -1 になることを assertion している)。

Blocker 3 解消確認: clampPlayerToArena 分離と resize 後呼び出し

clampPlayerToArena() を独立 export として MovementSystem.ts に実装。runMovementSystem() 末尾で move コマンド有無に関係なく呼び出し。resizeArena() 後にも clampPlayerToArena(currentState) を明示呼び出し。tests/movement-system.test.ts に「no move command でも clamp される」「arena 縮小後に clampPlayerToArena を呼ぶと境界内に収まる」の 2 テストが追加されていることを確認。

Minor 解消確認

  • window.blur / visibilitychange で resetInput() 呼び出し実装済み(InputBindings.ts 確認)
  • context.setTransform(dpr, 0, 0, dpr, 0, 0) 使用確認済み(CanvasRenderer.ts 確認)

Schema / Safety ゲート

  • Schema Change Applicability: not_schema_change を明示・根拠が diff と整合(GameSnapshot 変更なし、runtime state のみ)
  • Safety Claim Matrix: N/A として根拠記載あり(認証・権限・外部 I/O 非該当)

Blockers

なし

Non-blockers

なし

LOOP_VERDICT

verdict: APPROVE
blockers: []
mergeable: MERGEABLE
mergeStateStatus: CLEAN
reviewed_head_sha: ad638dbe0eeff2e8aecd21ef89e503673a0b7c06
follow_up_issue_requests: []

@squne121
squne121 marked this pull request as ready for review May 28, 2026 14:53
@squne121
squne121 merged commit 906533e into main May 28, 2026
6 checks passed
@squne121
squne121 deleted the worktree-issue-1-jiki-ido-to-projectile-shageki-system branch May 28, 2026 14:53
@squne121

Copy link
Copy Markdown
Owner Author

結論としては、PR #444 の deferred を直接消化する「playtest issue」より先に、E2E / browser playtest 基盤を作る Issue を 1 本切るべきです。理由は、PR #444 は実ブラウザ上の弾道・pointer 体感確認を後続 playtest issue に deferred している一方で、現状の package.json には test:e2e 等のブラウザ検証 script がなく、依存にも Playwright 系が見えません。([GitHub]1) ([GitHub]2)

既存の docs/product/playtest-protocol.md は、browser_automation を UI/Canvas/DOM 統合・リグレッションの根拠として認めつつ、UX 妥当性の代替にはしない、と整理しています。したがって Issue は「自動 E2E で最低限の操作可能性を担保し、人間 playtest の記録導線まで作る」スコープがよいです。([GitHub]3)


起票案

Title

実装: E2E / browser playtest foundation を導入し、movement + projectile の実ブラウザ検証導線を作る

Body

## Machine-Readable Contract

    contract_schema_version: v1
    issue_kind: implementation
    parent_issue: "#1"
    goal_ref: "PR #444 で deferred された『ブラウザ上での実際の弾道・pointer 体感確認』を、後続 playtest issue で実行可能にするため、E2E / browser playtest foundation を導入する"
    change_kind: test-infra

## Parent Issue

#1

## Parent Goal Ref

- Goal: 自機移動と Projectile 射撃システムを、Canvas 上で実際に操作・確認できる状態にする
- Deferred source: PR #444 `Runtime Verification Applicability`
  - `decision: deferred`
  - ブラウザ上での実際の弾道・pointer 体感確認は後続 playtest issue で実施

## Problem

PR #444 では unit test / build は通っているが、実ブラウザ上で以下を確認する基盤が未整備である。

- WASD 入力が実ブラウザで player movement に接続されていること
- pointer down / move / up / cancel / lostpointercapture が実ブラウザで破綻しないこと
- projectile が Canvas 上で視認できること
- fixed timestep / render / input binding / Canvas の統合がブラウザ環境で最低限成立すること
- 人間による体感確認結果を playtest-log へ残す導線があること

既存の `docs/product/playtest-protocol.md` は `browser_automation` を UI/Canvas/DOM 統合・リグレッションの根拠として認めているが、現状の package scripts には `test:e2e` 相当の入口がない。

## Outcome

Playwright ベースの最小 E2E foundation が導入され、PR #444 相当の movement + projectile を対象に、以下が可能になっている。

- `pnpm test:e2e` でローカル / CI から実ブラウザ smoke test を実行できる
- `pnpm test:e2e:ui` または `pnpm test:e2e:debug` で人間が操作確認しやすい導線がある
- Canvas / input / projectile の最低限の統合テストが存在する
- failure 時に trace / screenshot / video の少なくとも trace が保存される
- `docs/product/playtest-log.md` の schema に従って、PR #444 の deferred runtime verification を記録できる最小サンプルまたは手順がある

## In Scope

- Playwright Test の導入
  - `@playwright/test` の devDependency 追加
  - `playwright.config.ts` の追加
  - `pnpm test:e2e` script の追加
  - 必要なら `pnpm test:e2e:ui` / `pnpm test:e2e:debug` script を追加
- E2E smoke test の追加
  - Vite preview または dev server を Playwright から起動
  - 初期画面が表示されること
  - Canvas 要素が存在し、表示サイズを持つこと
  - `W/A/S/D` 入力を送れること
  - pointer down / move / up による射撃操作を送れること
  - projectile 生成の観測は、可能なら debug/test-only DOM overlay または exported state hook で検証する
- Canvas / state の観測方法の最小設計
  - 過度な本番 UI 汚染を避ける
  - `import.meta.env.DEV` または test-only hook など、production behavior を変えない観測境界を明示する
- Playtest 記録導線
  - `docs/product/playtest-protocol.md` の `browser_automation` / `human_internal` の使い分けに沿う
  - `docs/product/playtest-log.md` に記録するための最小テンプレート、または `docs/product/playtest-sessions/README.md` を追加する
- CI 統合
  - 既存 CI に `pnpm test:e2e` を追加する、または CI 追加を別 Issue に deferred する場合は理由を明示する

## Out of Scope

- 敵、当たり判定、ダメージ、sortie 終了条件の実装
- balance / tuning の決定
- 「面白さ」「操作感が良い」などの UX 妥当性を自動 E2E の結果だけで主張すること
- 外部テスター募集
- raw video / PII を public repository に保存すること
- 大規模な telemetry 基盤
- Vitest Browser Mode への全面移行
- visual regression snapshot の厳密な baseline 運用

## Acceptance Criteria

- AC1: `package.json` に `test:e2e` script が追加されている
- AC2: `@playwright/test` が devDependency として追加されている
- AC3: `playwright.config.ts` が存在し、Vite app を起動して E2E test を実行できる
- AC4: `tests/e2e/` 配下に movement + projectile smoke test が存在する
- AC5: E2E smoke test は Canvas の存在・表示サイズ・keyboard 入力・pointer 入力を実ブラウザで検証する
- AC6: failure 時の trace が保存される設定になっている
- AC7: `pnpm test:e2e` がローカルで PASS する
- AC8: `pnpm typecheck && pnpm lint && pnpm test && pnpm build` が PASS する
- AC9: playtest-log への記録方法が `docs/product/playtest-log.md` の schema と矛盾しない
- AC10: 自動 E2E の結果を UX 妥当性の証拠として扱わない旨が docs または PR body に明記されている

## Verification Commands

    # AC1: script 確認
    node -e "const p=require('./package.json'); if (!p.scripts?.['test:e2e']) process.exit(1)"

    # AC2: dependency 確認
    node -e "const p=require('./package.json'); if (!p.devDependencies?.['@playwright/test']) process.exit(1)"

    # AC3: config 確認
    test -f playwright.config.ts

    # AC4: E2E test 存在確認
    test -d tests/e2e && rg -n "projectile|pointer|keyboard|canvas|WASD|KeyW|mouse" tests/e2e

    # AC7: E2E 実行
    pnpm test:e2e

    # AC8: 既存品質ゲート
    pnpm typecheck && pnpm lint && pnpm test && pnpm build

    # AC9/AC10: playtest policy との整合確認
    rg -n "browser_automation|human_internal|UX|playtest-log|trace" docs tests package.json playwright.config.ts

## Allowed Paths

- `package.json`
- `pnpm-lock.yaml`
- `playwright.config.ts`
- `tests/e2e/**`
- `.github/workflows/**`
- `docs/product/playtest-log.md`
- `docs/product/playtest-protocol.md`
- `docs/product/playtest-sessions/**`
- `src/**`  
  - ただし test-only observability hook に必要な最小変更のみ

## Stop Conditions

- production behavior を変えないと E2E 観測が成立しない場合
- Canvas 描画の pixel-perfect visual regression を必須にしないと AC 達成できない場合
- Playwright ではなく別ツールへ全面移行する必要が判明した場合
- CI 実行時間・browser install・環境依存で既存 CI を不安定化させる場合
- `docs/product/playtest-protocol.md` の UX evidence policy と矛盾する場合
- 外部テスター、録画、PII 保存が必要になる場合

## Runtime Verification Applicability

    decision: required
    reason: この Issue は runtime code の主要挙動を変更しないが、実ブラウザ上の input / Canvas / render 統合を検証する基盤を導入するため、`pnpm test:e2e` による browser_automation runtime verification を必須とする。
    deferred_destination: null
    deferred_verification_condition: null

後続 Issue として分けるべきもの

この基盤 Issue とは別に、PR #444 の deferred を実際に消化する playtest execution issue を 1 本切るのが妥当です。

実施: PR #444 movement + projectile の browser automation / human_internal playtest を記録する

こちらは実装ではなく、docs/product/playtest-log.md に session entry を残し、bug / balance/tuning / unclear_needs_more_data を分類する Issue にする。既存プロトコルは、自動化は UI/Canvas/DOM 統合や回帰の根拠、人間確認は操作感・違和感・納得感の根拠、と分けているため、この 2 層構成が一番きれいです。([GitHub]3)

補足すると、Playwright は keyboard / mouse 操作、trace viewer、video、visual screenshot comparison を公式に持っているため、今回の「実ブラウザで pointer と Canvas を確認する」基盤には Playwright が第一候補でよいです。Vitest Browser Mode はブラウザ globals を使えるため component/browser test には向きますが、この Issue では「実アプリを起動して WASD / pointer / Canvas をまたぐ E2E」が主眼なので、まず Playwright Test に寄せるのが安全です。([Playwright]4)

squne121 added a commit that referenced this pull request May 28, 2026
… smoke test (#451)

* feat(#447): E2E / browser playtest foundation — movement + projectile smoke test

Introduces Playwright-based E2E foundation for the movement + projectile
integration established in PR #444. The implementation:

- Adds `@playwright/test` devDependency and `playwright.config.ts` using
  Vite preview server (pnpm build && pnpm preview, port 4173)
- Adds 11 behavioral smoke tests in `tests/e2e/movement-projectile.spec.ts`
  covering canvas visibility, WASD movement axes, keyup stop, projectile
  generation via pointer down, projectile movement, pointerup/pointercancel
  state clearing (AC5, AC11)
- Adds `test:e2e`, `test:e2e:ui`, `test:e2e:debug`, `test:e2e:headed`,
  `playwright:install`, `playwright:install:ci` scripts to package.json (AC1)
- Adds read-only `window.__LOOP_E2E__` observability hook in src/main.ts,
  gated by `VITE_E2E_MODE=true`; absent from production builds (AC12)
- Adds CI e2e job with Chromium install + failure artifact upload (AC13)
- Adds `docs/product/playtest-sessions/` directory with README and sample
  session record aligned to playtest-log.md schema (AC9)
- Excludes `tests/e2e/**` from vitest to prevent Playwright test mixing

All 11 E2E tests PASS locally. Production build confirmed free of
`__LOOP_E2E__`. pnpm typecheck && lint && test && build all PASS.

NOTE: Automatic E2E results confirm integration correctness only and are
NOT UX validity evidence. Human playtesting remains required for feel/UX.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* fix(e2e): CI webServer timeout を解消するため build を CI step に分離する

playwright.config.ts の webServer.command から pnpm build を除去し、
CI e2e ジョブに独立した build step (VITE_E2E_MODE=true pnpm build) を追加。
120 秒以内に build + preview 起動が完了しない問題を解消する (Option B)。

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* fix(#447): use pnpm exec vite preview to correctly pass --host flag

pnpm preview -- --host 127.0.0.1 caused the -- separator to stop
Vite's option parsing, so --host was never received. This resulted in
Playwright's webServer timing out in CI because it could not connect
to the expected URL.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* fix(#447): address PR #451 human review blockers (B1–B5)

- B1: test:e2e now includes build step (VITE_E2E_MODE=true pnpm build && playwright test) so it is self-contained without a pre-built dist/
- B2: __LOOP_E2E__.getState() returns a spread-copy snapshot instead of the live state reference; adds input.{primaryPressed,activePointerId} to the snapshot
- B3: pointerup and pointercancel tests now explicitly assert primaryPressed===false and activePointerId===null after the event
- B4: new test 'lostpointercapture clears active pointer state' verifies the lostpointercapture handler
- B5: new smoke test 'projectile renders on canvas' confirms canvas pixel data changes after firing

Also: adds activePointerId to InputState and writes it from InputBindings.ts (replaces closure-local capturedPointerId so the field is observable from the E2E hook).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* fix(#447): iteration 4 blockers — oracle, CI double-build, playtest template

B1: template-ize PT-20260529-001 playtest session file; replace stale
    build_ref/success_count/runs with <FILL_IN_FROM_CI> placeholders and
    add header clarifying this is a format sample, not an actual run record.

B2: strengthen projectile movement oracle to use expect.poll with 1s timeout
    so the test fails (not silently passes) if the projectile never moves.
    Removed the expired-fallback exit path.

B3: add test:e2e:ci script (playwright test only, no build step); update
    CI e2e job to use test:e2e:ci to eliminate double-build; fix
    playwright.config.ts comment to reflect actual webServer.command.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
squne121 added a commit that referenced this pull request May 29, 2026
* fix(test): exclude .claude/worktrees/** from Vitest discovery

Orphaned worktrees containing E2E spec files were being picked up by
vitest, causing Playwright test context errors in unit test runs.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* docs(#448): add PR #444 deferred playtest session records

Discharges the deferred runtime verification from PR #444 by adding:
- PT-20260529-001-pr444-browser-automation.md: actual pnpm test:e2e results
  (13/13 passed, build_ref 75cfc1e, retain-on-failure artifacts)
- PT-20260529-002-pr444-human-internal.md: developer-self human internal
  playtest of movement + projectile, with 10-step task script

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* fix(#448): fix playtest session schema violations

- success_rate: "100%" → 1.0 (schema invariant: 0.0–1.0 fraction)
- storage_class: "retain-on-failure" → "local_git" (Playwright retention
  policy moved to artifact_absent_reason)
- automation: null added to human_internal session
- confidence: high → medium for developer-self UX observations
- decision: no_action → defer for entries where UX validity is unconfirmed
- Remove overconfident "no tuning concerns" / "acceptable" phrasing

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

実装: 自機移動と Projectile 射撃システム

1 participant