From 4471e636693c04f7a0a6c4387f5ab18c649cf82c Mon Sep 17 00:00:00 2001 From: John Taylor Date: Sat, 22 Aug 2026 10:20:26 -0400 Subject: [PATCH 1/7] docs: combat-merge design spec (one encounter widget, two mounts; epic 2/7) Co-Authored-By: Claude Fable 5 --- .../specs/2026-08-22-combat-merge-design.md | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 docs/superpowers/specs/2026-08-22-combat-merge-design.md diff --git a/docs/superpowers/specs/2026-08-22-combat-merge-design.md b/docs/superpowers/specs/2026-08-22-combat-merge-design.md new file mode 100644 index 0000000..bb1be0c --- /dev/null +++ b/docs/superpowers/specs/2026-08-22-combat-merge-design.md @@ -0,0 +1,109 @@ +# Combat Merge — One Encounter Widget, Two Mounts + +**Date:** 2026-08-22 +**Status:** Approved design, pre-implementation +**Sub-project:** 2 of 7 in the tool-consolidation epic (roadmap in +`docs/superpowers/specs/2026-08-22-tracking-merge-design.md`) +**Branch note:** stacked on `feat/tracking-merge` (PR #333) because both touch +`lib/features/run_screen.dart`; rebase onto main after #333 lands. + +## Problem + +Two implementations render the same fight: + +- **EncounterScreen** (`lib/features/encounter_screen.dart`, ~1620 lines, + Track → Encounter): the full combat manager — combatant rows with HP + steppers, conditions, tags, attack chips, stat-block edit, initiative edit, + add flows (ad-hoc / characters / bestiary / foes / reference / generator), + QuickRef, end-encounter with thread-clock advance. +- **`_InitiativePanel`** (`lib/features/run_screen.dart:169-273`, Run + dashboard): a ~100-line read-only re-implementation — initiative rows, + current-turn highlight, defeated strike-through, HP readout, tap-row + stat-block dialog, Next-turn and Roll-all buttons. + +Every change to combat rendering must be made twice. The Run panel drifts. + +## Decisions already made (user-confirmed) + +1. **One widget, two mounts** — extract the encounter body into one reusable + pane with a compact mode; Track keeps the full manager, Run mounts the + same widget compact. No verb-semantics change. +2. **Lonelog `BattlePane` stays out** — it serves lonelog's own notation and + model; not part of this merge. +3. **Approach A** — a single `EncounterPane({bool compact})`, not a + shared-row-only extraction and not per-section feature flags. + +## Design + +### 1. Component extraction (`lib/features/encounter_screen.dart`) + +- New public widget `EncounterPane extends ConsumerWidget` with constructor + `const EncounterPane({super.key, this.compact = false})`. Full mode owns + EVERYTHING `EncounterScreen.build` renders today — the whole + `Column[_header, list, _addButtons]` body including the Round header, + `next-turn`, `enc-rules`, `end-encounter`, and the add-combatant button + rows (`add-character`/`add-adhoc`/`generate-monster`/`add-bestiary`/ + `add-foes`/`add-from-reference`). There is no separate screen chrome. +- `EncounterScreen` remains the Track mount name and becomes a trivial + wrapper returning `const EncounterPane()`. All existing `enc-*` and add + keys, dialogs, and helper methods move to the pane unchanged — full mode + is a pure extraction, zero behavior change. +- The pane brings no `Card`/`Scaffold` surface of its own in compact mode — + the Run `_Panel` supplies the chrome (repo rule: detail widgets bring their + own surface only where the host adds none; here the host adds one). + +### 2. Compact mode contract + +Compact mode renders, from `encounterProvider` state: + +- One row per combatant: initiative `CircleAvatar` (current-turn highlighted), + name (defeated = strike-through, current = primary color), HP readout + `cur/max` when a track exists. Row key: `run-init-row-`. +- Tap on a row with a non-empty stat block opens the read-only + `StatBlockView` dialog (existing `_showStatBlock` behavior moves into the + pane). +- Action row: `run-init-next` ("Next turn") and `run-init-roll-all` + ("Roll all init") — same `EncounterNotifier.nextTurn()` / + `rollInitiativeForAll()` calls as today, disabled when no combatants. +- An `run-init-open-full` `ActionChip`/TextButton ("Open encounter") that + navigates via `shellRouteProvider.notifier.goTo(Destination.track, + subtab: 'encounter')`. +- Empty state: the existing "No encounter yet." text, key `run-init-empty`. +- Compact mode shows NONE of the manager affordances: no HP steppers, no + condition/tag editing, no attack chips, no stat-block/initiative editors, + no add flows, no end-encounter. +- Key policy: compact mode emits the `run-init-*` keys above (existing Run + tests and muscle memory unchanged); full mode keeps the `enc-*` keys. + Colors in both modes come from existing token usage; no new + `ColorScheme` references (design ratchet). + +### 3. Run wiring (`lib/features/run_screen.dart`) + +- Delete `_InitiativePanel` (lines 169-273) entirely. +- The dashboard slot becomes + `_Panel(k: Key('run-panel-initiative'), title: 'Initiative · Round N', child: EncounterPane(compact: true))` + — a small private wrapper (`_InitiativeSlot` or inline in `build`) may + compute the round title from `encounterProvider`, since `_Panel` titles are + Run-side chrome. +- `run_screen.dart` imports `encounter_screen.dart` for the pane. No other + panel changes. + +### 4. Testing + success criteria + +Tests: + +- Existing encounter tests (`encounter_attack_test.dart` and friends) stay + green untouched — full mode is a pure extraction. +- Existing `run_screen_test.dart` initiative cases keep passing against the + shared pane (same `run-init-*` keys). +- New widget test: compact mode renders rows + actions but NOT manager + affordances (asserts absence of `enc-attack-`, `enc-minus-0`, + `enc-statblock-`); `run-init-open-full` navigates to Track/encounter. + +Success criteria: + +- `flutter analyze` clean; full suite green. +- `_InitiativePanel` no longer exists; `run_screen.dart` renders combat + through `EncounterPane(compact: true)`. +- Track → Encounter is behaviorally unchanged. +- No model or persistence change anywhere in the diff. From ab6a1f27fe308172c95313024503cf8efe254ef4 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Sat, 22 Aug 2026 10:35:36 -0400 Subject: [PATCH 2/7] docs: combat-merge implementation plan (3 TDD tasks) Co-Authored-By: Claude Fable 5 --- .../plans/2026-08-22-combat-merge.md | 383 ++++++++++++++++++ 1 file changed, 383 insertions(+) create mode 100644 docs/superpowers/plans/2026-08-22-combat-merge.md diff --git a/docs/superpowers/plans/2026-08-22-combat-merge.md b/docs/superpowers/plans/2026-08-22-combat-merge.md new file mode 100644 index 0000000..ffbc74d --- /dev/null +++ b/docs/superpowers/plans/2026-08-22-combat-merge.md @@ -0,0 +1,383 @@ +# Combat Merge Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** One `EncounterPane` widget renders combat everywhere — full manager on Track → Encounter, compact glance on the Run dashboard; the duplicate `_InitiativePanel` is deleted. + +**Architecture:** Pure widget-level merge, no model or persistence change. Task 1 extracts today's `EncounterScreen` body into `EncounterPane` (full mode, zero behavior change). Task 2 adds the compact branch (glance rows + next-turn/roll-all + open-full link, `run-init-*` keys). Task 3 deletes `_InitiativePanel` and mounts `EncounterPane(compact: true)` in the Run dashboard slot. + +**Tech Stack:** Flutter + flutter_riverpod. Tests: `flutter test`, `flutter analyze`. + +**Spec:** `docs/superpowers/specs/2026-08-22-combat-merge-design.md` + +## Global Constraints + +- No model or persistence change anywhere in the diff. +- Full mode is a pure extraction: every existing `enc-*`, `add-*`, `next-turn`, `end-encounter` key and behavior unchanged; existing encounter tests must pass untouched. +- Compact mode emits keys `run-init-row-`, `run-init-next`, `run-init-roll-all`, `run-init-empty`, plus new `run-init-open-full`; it shows NO manager affordances (no HP steppers, condition/tag editors, attack chips, stat-block/init editors, add flows, end-encounter). +- Colors from existing token usage; no new `Theme.of(context).colorScheme` references (design ratchet). +- The pane brings no `Card` surface in compact mode — Run's `_Panel` supplies chrome. +- Package prefix in tests: `package:loreseer/...`. A hook auto-runs `dart format` on every `.dart` edit. Format only files you edit. +- Each task ends with the named tests green + `flutter analyze` clean on touched files, then a commit. + +--- + +### Task 1: Extract `EncounterPane` (full mode, pure move) + +**Files:** +- Modify: `lib/features/encounter_screen.dart:16-40` +- Test: existing `test/encounter_attack_test.dart` (no edits — it must stay green) + +**Interfaces:** +- Produces: `class EncounterPane extends ConsumerWidget` with `const EncounterPane({super.key, this.compact = false}); final bool compact;`. Full mode renders exactly what `EncounterScreen.build` renders today (`Column[_header, list/_empty, _addButtons]` under the same `async.when`). `EncounterScreen` becomes `class EncounterScreen extends StatelessWidget { build => const EncounterPane(); }`. +- Consumes: nothing new. + +- [ ] **Step 1: Restructure the widget** + +In `lib/features/encounter_screen.dart`: + +1. Rename the existing `class EncounterScreen extends ConsumerWidget` to `class EncounterPane extends ConsumerWidget` — its `build` and ALL its helper methods (`_header`, `_empty`, `_list`, `_attack`, `_addButtons`, `_addFromBestiary`, `_endEncounter`, `_addTag`, `_addFromCharacters`, `_generateMonster`, `_addAdHoc`, `_editStatBlock`, `_saveToBestiary`, `_editInit`, `_addFromFoes`, `_addFromSystemCreatures`, `_addFromReference`) move with it verbatim. Private dialog classes in the file are untouched. +2. Give it the constructor and field: + +```dart +/// The one combat surface. Full mode (default) is the Track → Encounter +/// manager; [compact] renders the Run dashboard glance (Task 2). +class EncounterPane extends ConsumerWidget { + const EncounterPane({super.key, this.compact = false}); + + /// Compact = read-and-act glance: rows + next turn + roll-all only. + final bool compact; +``` + +3. Add a new thin Track mount at the top of the file: + +```dart +/// Track → Encounter mount. All rendering lives in [EncounterPane]. +class EncounterScreen extends StatelessWidget { + const EncounterScreen({super.key}); + + @override + Widget build(BuildContext context) => const EncounterPane(); +} +``` + +No other line changes — this is a rename plus a wrapper. `compact` is declared but not yet read (that is Task 2); if the analyzer flags the unused field, reference it trivially only if required — it will not, fields are not flagged. + +- [ ] **Step 2: Verify pure extraction** + +Run: `flutter test test/encounter_attack_test.dart && flutter analyze lib/features/encounter_screen.dart` +Expected: PASS with zero test edits, analyzer clean. Then run the wider encounter coverage: `flutter test test/encounter_screen_test.dart` if that file exists (`ls test | grep encounter` first); every existing encounter test file must pass unedited. + +- [ ] **Step 3: Commit** + +```bash +git add lib/features/encounter_screen.dart +git commit -m "refactor(encounter): extract EncounterPane; EncounterScreen is a thin mount" +``` + +--- + +### Task 2: Compact mode + +**Files:** +- Modify: `lib/features/encounter_screen.dart` (the `EncounterPane.build` + one new private helper) +- Test: `test/encounter_pane_compact_test.dart` (create) + +**Interfaces:** +- Consumes: `EncounterPane.compact` from Task 1; `encounterProvider`, `EncounterNotifier.nextTurn()/rollInitiativeForAll()`, `StatBlockView` (from `sheet_widgets.dart`, already imported), `shellRouteProvider` + `Destination` (import `../shared/shell_route.dart` / `../shared/destination.dart` as the file's existing imports allow — check what `run_screen.dart` imports for `shellRouteProvider` and mirror it). +- Produces: compact rendering under keys `run-init-row-`, `run-init-next`, `run-init-roll-all`, `run-init-empty`, `run-init-open-full`. Task 3 mounts it. + +- [ ] **Step 1: Write the failing test** + +Create `test/encounter_pane_compact_test.dart`: + +```dart +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:loreseer/engine/models.dart'; +import 'package:loreseer/features/encounter_screen.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +void main() { + void seed(List> combatants) { + SharedPreferences.setMockInitialValues({ + 'loreseer.encounter.v1.default': jsonEncode({ + 'round': 2, + 'turnIndex': 0, + 'combatants': combatants, + }), + 'loreseer.sessions.v1': jsonEncode({ + 'active': 'default', + 'sessions': [ + {'id': 'default', 'name': 'Campaign 1'} + ], + }), + }); + } + + Future pump(WidgetTester tester) async { + await tester.pumpWidget(const ProviderScope( + child: MaterialApp( + home: Scaffold(body: EncounterPane(compact: true))))); + await tester.pumpAndSettle(); + } + + testWidgets('compact renders glance rows and actions, no manager UI', + (tester) async { + seed([ + { + 'id': 'g1', + 'name': 'Goblin', + 'initiative': 12, + 'track': {'current': 4, 'max': 7}, + }, + ]); + await pump(tester); + + expect(find.byKey(const Key('run-init-row-g1')), findsOneWidget); + expect(find.text('Goblin'), findsOneWidget); + expect(find.text('4/7'), findsOneWidget); + expect(find.byKey(const Key('run-init-next')), findsOneWidget); + expect(find.byKey(const Key('run-init-roll-all')), findsOneWidget); + expect(find.byKey(const Key('run-init-open-full')), findsOneWidget); + + // Manager affordances absent in compact mode. + expect(find.byKey(const Key('enc-attack-g1')), findsNothing); + expect(find.byKey(const Key('enc-minus-0')), findsNothing); + expect(find.byKey(const Key('enc-statblock-g1')), findsNothing); + expect(find.byKey(const Key('add-adhoc')), findsNothing); + expect(find.byKey(const Key('end-encounter')), findsNothing); + }); + + testWidgets('compact empty state', (tester) async { + seed([]); + await pump(tester); + expect(find.byKey(const Key('run-init-empty')), findsOneWidget); + }); +} +``` + +Adjust the seeded combatant JSON to `Combatant.fromJson`'s real field names first — read `Combatant.toJson`/`fromJson` in `lib/engine/models.dart` (or its part files) and use those exact keys; if hand-writing JSON is brittle, build `Combatant` objects and `jsonEncode(EncounterState(...).toJson())` instead. + +- [ ] **Step 2: Run test to verify it fails** + +Run: `flutter test test/encounter_pane_compact_test.dart` +Expected: FAIL — compact flag ignored, full manager renders (`enc-*` keys found / `run-init-*` missing). + +- [ ] **Step 3: Implement the compact branch** + +In `EncounterPane.build`, inside the `data:` case, branch first: + +```dart + data: (s) => compact + ? _compact(context, ref, s) + : Column( + children: [ + _header(context, ref, s), + ... +``` + +Add the helper (adapted from the deleted-in-Task-3 `_InitiativePanel`, so Run behavior is preserved): + +```dart + /// Run-dashboard glance: rows + next-turn/roll-all + open-full link. + /// Emits the historical run-init-* keys so Run tests and muscle memory + /// survive the merge. No Card surface — the host panel supplies chrome. + Widget _compact(BuildContext context, WidgetRef ref, EncounterState s) { + final theme = Theme.of(context); + final notifier = ref.read(encounterProvider.notifier); + final rows = []; + for (var i = 0; i < s.combatants.length; i++) { + final c = s.combatants[i]; + final current = i == s.turnIndex; + rows.add(InkWell( + key: Key('run-init-row-${c.id}'), + onTap: (c.statBlock != null && !c.statBlock!.isEmpty) + ? () => _showCompactStatBlock(context, c) + : null, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 3), + child: Row(children: [ + CircleAvatar( + radius: 14, + backgroundColor: current + ? theme.colorScheme.primaryContainer + : theme.colorScheme.surfaceContainerHighest, + child: + Text('${c.initiative}', style: theme.textTheme.labelMedium), + ), + const SizedBox(width: 10), + Expanded( + child: Text(c.name, + style: c.defeated + ? const TextStyle(decoration: TextDecoration.lineThrough) + : (current + ? TextStyle(color: theme.colorScheme.primary) + : null)), + ), + if (c.track != null) + Text('${c.track!.current}/${c.track!.max}', + style: theme.textTheme.bodySmall), + ]), + ), + )); + } + + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (s.combatants.isEmpty) + Text('No encounter yet.', + key: const Key('run-init-empty'), + style: TextStyle(color: Theme.of(context).colorScheme.outline)) + else + ...rows, + const SizedBox(height: 8), + Row(children: [ + Flexible( + child: FilledButton.tonal( + key: const Key('run-init-next'), + onPressed: + s.combatants.isEmpty ? null : () => notifier.nextTurn(), + child: const Text('Next turn'), + ), + ), + const SizedBox(width: 8), + Flexible( + child: OutlinedButton( + key: const Key('run-init-roll-all'), + onPressed: s.combatants.isEmpty + ? null + : () => notifier.rollInitiativeForAll(), + child: const Text('Roll all init'), + ), + ), + const SizedBox(width: 8), + Flexible( + child: TextButton( + key: const Key('run-init-open-full'), + onPressed: () => ref + .read(shellRouteProvider.notifier) + .goTo(Destination.track, subtab: 'encounter'), + child: const Text('Open encounter'), + ), + ), + ]), + ], + ); + } + + void _showCompactStatBlock(BuildContext context, Combatant c) { + showDialog( + context: context, + builder: (_) => AlertDialog( + title: Text(c.name), + content: SingleChildScrollView( + child: StatBlockView( + block: c.statBlock!, + curHp: c.track?.current, + maxHp: c.track?.max, + ), + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('Close'), + ), + ], + ), + ); + } +``` + +Notes: +- The `theme.colorScheme.*` references above are MOVED from the old `_InitiativePanel`, not new design-language choices; the design-ratchet test counts files, and `encounter_screen.dart` already uses `colorScheme` (verify with `grep -c colorScheme lib/features/encounter_screen.dart` — nonzero today). If the ratchet test still fails, STOP and report DONE_WITH_CONCERNS rather than restyling. +- Add the imports the helper needs (`shellRouteProvider`, `Destination`) by mirroring `run_screen.dart`'s import lines for those symbols. +- The `Flexible`-wrapped buttons follow the repo's loose-constraints gotcha — keep them `Flexible`, never bare. + +- [ ] **Step 4: Run tests to verify they pass** + +Run: `flutter test test/encounter_pane_compact_test.dart test/encounter_attack_test.dart && flutter analyze lib/features/encounter_screen.dart` +Expected: PASS; full-mode tests still untouched and green. + +- [ ] **Step 5: Commit** + +```bash +git add lib/features/encounter_screen.dart test/encounter_pane_compact_test.dart +git commit -m "feat(encounter): compact glance mode on EncounterPane" +``` + +--- + +### Task 3: Run wiring — delete `_InitiativePanel` + +**Files:** +- Modify: `lib/features/run_screen.dart:43` (construction) and `:169-273` (delete `_InitiativePanel`) +- Test: `test/run_screen_test.dart` (should need no or minimal edits — verify) + +**Interfaces:** +- Consumes: `EncounterPane(compact: true)` from Task 2 (import `encounter_screen.dart`). +- Produces: the Run dashboard's initiative slot backed by the shared pane; `run-panel-initiative` key + "Initiative · Round N" title preserved. + +- [ ] **Step 1: Rewire the dashboard slot** + +In `lib/features/run_screen.dart`: + +1. Replace `const initiative = _InitiativePanel();` (line ~43) with `const initiative = _InitiativeSlot();`. +2. Delete `class _InitiativePanel` (lines 169-273) entirely, including its `_showStatBlock` (now lives in the pane). +3. Add the slot wrapper next to the other panels: + +```dart +/// Initiative slot: Run-side chrome around the shared [EncounterPane] +/// glance. The pane owns rendering; this owns the panel card + title. +class _InitiativeSlot extends ConsumerWidget { + const _InitiativeSlot(); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final enc = + ref.watch(encounterProvider).valueOrNull ?? const EncounterState(); + return _Panel( + k: const Key('run-panel-initiative'), + title: 'Initiative · Round ${enc.round}', + child: const EncounterPane(compact: true), + ); + } +} +``` + +4. Add `import 'encounter_screen.dart';`. Remove imports that only `_InitiativePanel` used if the analyzer flags them (`StatBlockView` import stays only if another panel uses it — `run-init-row` stat-block glance moved to the pane, but `_PartyPanel`/reference panels may still use `sheet_widgets.dart`; keep what the analyzer needs). + +- [ ] **Step 2: Run the Run tests** + +Run: `flutter test test/run_screen_test.dart && flutter analyze lib/features/run_screen.dart lib/features/encounter_screen.dart` +Expected: PASS with no or minimal test edits — the compact pane emits identical `run-init-*` keys and identical behaviors. If a case fails, fix the CODE to honor the old contract unless the assertion covers a deliberately removed detail; brief allows editing the test only for such removed details, and the report must name each edited assertion and why. + +- [ ] **Step 3: Full suite** + +Run: `flutter test` +Expected: green. Attribute any failure via the final "Failing tests:" block only. + +- [ ] **Step 4: Update CLAUDE.md** + +Add one Project-notes bullet (top of the list, normal prose, existing style): + +> **Combat merge (2026-08-22, consolidation epic sub-project 2)** — ONE combat widget: `EncounterPane({compact})` in `encounter_screen.dart` renders both the full Track → Encounter manager (`EncounterScreen` is now a thin mount) and the Run dashboard glance (`_InitiativeSlot` wraps `EncounterPane(compact: true)`; the old `_InitiativePanel` is deleted). Compact keeps the historical `run-init-*` keys + a `run-init-open-full` jump to Track → Encounter and shows no manager affordances. Pure widget merge — no model/persistence change. See `docs/superpowers/specs/2026-08-22-combat-merge-design.md`. + +- [ ] **Step 5: Commit** + +```bash +git add lib/features/run_screen.dart CLAUDE.md +git commit -m "feat(run): initiative slot mounts shared EncounterPane; _InitiativePanel deleted" +``` + +--- + +## Post-plan verification (before PR) + +- Full suite + analyze green (Task 3 proves). +- Manual smoke on macOS: Run dashboard shows the glance; row tap opens stat block; Open encounter jumps to Track → Encounter; full manager unchanged. +- Branch is stacked on `feat/tracking-merge`; after PR #333 squash-merges, rebase with `git rebase --onto origin/main feat/tracking-merge feat/combat-merge` before opening the PR (or open the PR with base `feat/tracking-merge` if #333 is still open). From 36913ccc42bedcb00a9b882b83cdfd36def0cfdf Mon Sep 17 00:00:00 2001 From: John Taylor Date: Sat, 22 Aug 2026 10:37:43 -0400 Subject: [PATCH 3/7] refactor(encounter): extract EncounterPane; EncounterScreen is a thin mount --- lib/features/encounter_screen.dart | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/features/encounter_screen.dart b/lib/features/encounter_screen.dart index a377637..e3db11e 100644 --- a/lib/features/encounter_screen.dart +++ b/lib/features/encounter_screen.dart @@ -10,11 +10,25 @@ import '../state/providers.dart'; import 'inspire.dart'; import 'quick_ref_view.dart'; +/// Track → Encounter mount. All rendering lives in [EncounterPane]. +class EncounterScreen extends StatelessWidget { + const EncounterScreen({super.key}); + + @override + Widget build(BuildContext context) => const EncounterPane(); +} + +/// The one combat surface. Full mode (default) is the Track → Encounter +/// manager; [compact] renders the Run dashboard glance (Task 2). +/// /// Initiative tracker: combatants from character sheets (live first-track /// link) or ad-hoc, turn pointer + round counter, statuses/defeated, and an /// end-of-encounter summary into the journal. -class EncounterScreen extends ConsumerWidget { - const EncounterScreen({super.key}); +class EncounterPane extends ConsumerWidget { + const EncounterPane({super.key, this.compact = false}); + + /// Compact = read-and-act glance: rows + next turn + roll-all only. + final bool compact; @override Widget build(BuildContext context, WidgetRef ref) { From d8cc1f027d9c738e5fc34fbb34edd7bb87f664a9 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Sat, 22 Aug 2026 10:43:15 -0400 Subject: [PATCH 4/7] feat(encounter): compact glance mode on EncounterPane --- lib/features/encounter_screen.dart | 130 ++++++++++++++++++++++++-- test/encounter_pane_compact_test.dart | 66 +++++++++++++ 2 files changed, 188 insertions(+), 8 deletions(-) create mode 100644 test/encounter_pane_compact_test.dart diff --git a/lib/features/encounter_screen.dart b/lib/features/encounter_screen.dart index e3db11e..0b92586 100644 --- a/lib/features/encounter_screen.dart +++ b/lib/features/encounter_screen.dart @@ -5,10 +5,13 @@ import '../engine/combat.dart'; import '../engine/dice_notation.dart'; import '../engine/lonelog_combat.dart'; import '../engine/models.dart'; +import '../shared/destination.dart'; +import '../shared/shell_route.dart'; import '../shared/tag_dialog.dart'; import '../state/providers.dart'; import 'inspire.dart'; import 'quick_ref_view.dart'; +import 'sheet_widgets.dart'; /// Track → Encounter mount. All rendering lives in [EncounterPane]. class EncounterScreen extends StatelessWidget { @@ -38,15 +41,126 @@ class EncounterPane extends ConsumerWidget { return async.when( loading: () => const Center(child: CircularProgressIndicator()), error: (e, _) => Center(child: Text('Error: $e')), - data: (s) => Column( - children: [ - _header(context, ref, s), - Expanded( - child: s.combatants.isEmpty - ? _empty(context) - : _list(context, ref, s, chars), + data: (s) => compact + ? _compact(context, ref, s) + : Column( + children: [ + _header(context, ref, s), + Expanded( + child: s.combatants.isEmpty + ? _empty(context) + : _list(context, ref, s, chars), + ), + _addButtons(context, ref), + ], + ), + ); + } + + /// Run-dashboard glance: rows + next-turn/roll-all + open-full link. + /// Emits the historical run-init-* keys so Run tests and muscle memory + /// survive the merge. No Card surface — the host panel supplies chrome. + Widget _compact(BuildContext context, WidgetRef ref, EncounterState s) { + final theme = Theme.of(context); + final notifier = ref.read(encounterProvider.notifier); + final rows = []; + for (var i = 0; i < s.combatants.length; i++) { + final c = s.combatants[i]; + final current = i == s.turnIndex; + rows.add(InkWell( + key: Key('run-init-row-${c.id}'), + onTap: (c.statBlock != null && !c.statBlock!.isEmpty) + ? () => _showCompactStatBlock(context, c) + : null, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 3), + child: Row(children: [ + CircleAvatar( + radius: 14, + backgroundColor: current + ? theme.colorScheme.primaryContainer + : theme.colorScheme.surfaceContainerHighest, + child: + Text('${c.initiative}', style: theme.textTheme.labelMedium), + ), + const SizedBox(width: 10), + Expanded( + child: Text(c.name, + style: c.defeated + ? const TextStyle(decoration: TextDecoration.lineThrough) + : (current + ? TextStyle(color: theme.colorScheme.primary) + : null)), + ), + if (c.track != null) + Text('${c.track!.current}/${c.track!.max}', + style: theme.textTheme.bodySmall), + ]), + ), + )); + } + + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (s.combatants.isEmpty) + Text('No encounter yet.', + key: const Key('run-init-empty'), + style: TextStyle(color: Theme.of(context).colorScheme.outline)) + else + ...rows, + const SizedBox(height: 8), + Row(children: [ + Flexible( + child: FilledButton.tonal( + key: const Key('run-init-next'), + onPressed: + s.combatants.isEmpty ? null : () => notifier.nextTurn(), + child: const Text('Next turn'), + ), + ), + const SizedBox(width: 8), + Flexible( + child: OutlinedButton( + key: const Key('run-init-roll-all'), + onPressed: s.combatants.isEmpty + ? null + : () => notifier.rollInitiativeForAll(), + child: const Text('Roll all init'), + ), + ), + const SizedBox(width: 8), + Flexible( + child: TextButton( + key: const Key('run-init-open-full'), + onPressed: () => ref + .read(shellRouteProvider.notifier) + .goTo(Destination.track, subtab: 'encounter'), + child: const Text('Open encounter'), + ), + ), + ]), + ], + ); + } + + void _showCompactStatBlock(BuildContext context, Combatant c) { + showDialog( + context: context, + builder: (_) => AlertDialog( + title: Text(c.name), + content: SingleChildScrollView( + child: StatBlockView( + block: c.statBlock!, + curHp: c.track?.current, + maxHp: c.track?.max, + ), + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('Close'), ), - _addButtons(context, ref), ], ), ); diff --git a/test/encounter_pane_compact_test.dart b/test/encounter_pane_compact_test.dart new file mode 100644 index 0000000..a329325 --- /dev/null +++ b/test/encounter_pane_compact_test.dart @@ -0,0 +1,66 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:loreseer/engine/models.dart'; +import 'package:loreseer/features/encounter_screen.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +void main() { + void seed(List> combatants) { + SharedPreferences.setMockInitialValues({ + 'loreseer.encounter.v1.default': jsonEncode({ + 'round': 2, + 'turnIndex': 0, + 'combatants': combatants, + }), + 'loreseer.sessions.v1': jsonEncode({ + 'active': 'default', + 'sessions': [ + {'id': 'default', 'name': 'Campaign 1'} + ], + }), + }); + } + + Future pump(WidgetTester tester) async { + await tester.pumpWidget(const ProviderScope( + child: + MaterialApp(home: Scaffold(body: EncounterPane(compact: true))))); + await tester.pumpAndSettle(); + } + + testWidgets('compact renders glance rows and actions, no manager UI', + (tester) async { + seed([ + { + 'id': 'g1', + 'name': 'Goblin', + 'initiative': 12, + 'track': {'current': 4, 'max': 7}, + }, + ]); + await pump(tester); + + expect(find.byKey(const Key('run-init-row-g1')), findsOneWidget); + expect(find.text('Goblin'), findsOneWidget); + expect(find.text('4/7'), findsOneWidget); + expect(find.byKey(const Key('run-init-next')), findsOneWidget); + expect(find.byKey(const Key('run-init-roll-all')), findsOneWidget); + expect(find.byKey(const Key('run-init-open-full')), findsOneWidget); + + // Manager affordances absent in compact mode. + expect(find.byKey(const Key('enc-attack-g1')), findsNothing); + expect(find.byKey(const Key('enc-minus-0')), findsNothing); + expect(find.byKey(const Key('enc-statblock-g1')), findsNothing); + expect(find.byKey(const Key('add-adhoc')), findsNothing); + expect(find.byKey(const Key('end-encounter')), findsNothing); + }); + + testWidgets('compact empty state', (tester) async { + seed([]); + await pump(tester); + expect(find.byKey(const Key('run-init-empty')), findsOneWidget); + }); +} From 62fbd516475e3075b8e12c4fad8a08a3ed0b1e29 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Sat, 22 Aug 2026 10:53:10 -0400 Subject: [PATCH 5/7] feat(run): initiative slot mounts shared EncounterPane; _InitiativePanel deleted --- CLAUDE.md | 9 +++ lib/features/run_screen.dart | 103 +++-------------------------------- 2 files changed, 16 insertions(+), 96 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index b8f9241..8e6f38d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -19,6 +19,15 @@ Working rules for this repo: ## Project notes +- **Combat merge (2026-08-22, consolidation epic sub-project 2)** — ONE + combat widget: `EncounterPane({compact})` in `encounter_screen.dart` + renders both the full Track → Encounter manager (`EncounterScreen` is now + a thin mount) and the Run dashboard glance (`_InitiativeSlot` wraps + `EncounterPane(compact: true)`; the old `_InitiativePanel` is deleted). + Compact keeps the historical `run-init-*` keys + a `run-init-open-full` + jump to Track → Encounter and shows no manager affordances. Pure widget + merge — no model/persistence change. See + `docs/superpowers/specs/2026-08-22-combat-merge-design.md`. - **Tracking merge (2026-08-22, consolidation epic sub-project 1)** — Threads, Tracks, and Rumors are ONE entity: `Thread` carries `ThreadStage {rumor, active, done}` (JSON `stage`, omitted at active; legacy diff --git a/lib/features/run_screen.dart b/lib/features/run_screen.dart index d70ecc4..3f3ed20 100644 --- a/lib/features/run_screen.dart +++ b/lib/features/run_screen.dart @@ -4,10 +4,10 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../engine/dice_notation.dart'; import '../engine/models.dart'; import '../engine/oracle.dart'; +import 'encounter_screen.dart'; import 'inspire.dart'; import 'quick_ref_view.dart'; import 'reference_view.dart'; -import 'sheet_widgets.dart'; import '../shared/destination.dart'; import '../shared/shell_route.dart'; import '../state/play_context.dart'; @@ -39,7 +39,7 @@ class RunScreen extends ConsumerWidget { key: const Key('run-screen'), builder: (context, c) { final wide = c.maxWidth >= kRunWideBreakpoint; - const initiative = _InitiativePanel(); + const initiative = _InitiativeSlot(); const quickref = _QuickRefPanel(); const party = _PartyPanel(); const scene = _ScenePanel(); @@ -166,108 +166,19 @@ class _FoldingPanel extends StatelessWidget { } } -class _InitiativePanel extends ConsumerWidget { - const _InitiativePanel(); +/// Initiative slot: Run-side chrome around the shared [EncounterPane] +/// glance. The pane owns rendering; this owns the panel card + title. +class _InitiativeSlot extends ConsumerWidget { + const _InitiativeSlot(); @override Widget build(BuildContext context, WidgetRef ref) { - final theme = Theme.of(context); final enc = ref.watch(encounterProvider).valueOrNull ?? const EncounterState(); - final notifier = ref.read(encounterProvider.notifier); - final rows = []; - for (var i = 0; i < enc.combatants.length; i++) { - final c = enc.combatants[i]; - final current = i == enc.turnIndex; - rows.add(InkWell( - key: Key('run-init-row-${c.id}'), - onTap: (c.statBlock != null && !c.statBlock!.isEmpty) - ? () => _showStatBlock(context, c) - : null, - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 3), - child: Row(children: [ - CircleAvatar( - radius: 14, - backgroundColor: current - ? theme.colorScheme.primaryContainer - : theme.colorScheme.surfaceContainerHighest, - child: - Text('${c.initiative}', style: theme.textTheme.labelMedium), - ), - const SizedBox(width: 10), - Expanded( - child: Text(c.name, - style: c.defeated - ? const TextStyle(decoration: TextDecoration.lineThrough) - : (current - ? TextStyle(color: theme.colorScheme.primary) - : null)), - ), - if (c.track != null) - Text('${c.track!.current}/${c.track!.max}', - style: theme.textTheme.bodySmall), - ]), - ), - )); - } - return _Panel( k: const Key('run-panel-initiative'), title: 'Initiative · Round ${enc.round}', - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (enc.combatants.isEmpty) - Text('No encounter yet.', - key: const Key('run-init-empty'), style: _dimStyle(context)) - else - ...rows, - const SizedBox(height: 8), - Row(children: [ - Flexible( - child: FilledButton.tonal( - key: const Key('run-init-next'), - onPressed: - enc.combatants.isEmpty ? null : () => notifier.nextTurn(), - child: const Text('Next turn'), - ), - ), - const SizedBox(width: 8), - Flexible( - child: OutlinedButton( - key: const Key('run-init-roll-all'), - onPressed: enc.combatants.isEmpty - ? null - : () => notifier.rollInitiativeForAll(), - child: const Text('Roll all init'), - ), - ), - ]), - ], - ), - ); - } - - void _showStatBlock(BuildContext context, Combatant c) { - showDialog( - context: context, - builder: (_) => AlertDialog( - title: Text(c.name), - content: SingleChildScrollView( - child: StatBlockView( - block: c.statBlock!, - curHp: c.track?.current, - maxHp: c.track?.max, - ), - ), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context), - child: const Text('Close'), - ), - ], - ), + child: const EncounterPane(compact: true), ); } } From 709b4ec1277e70a8c4594c22baf5470f759dea51 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Sat, 22 Aug 2026 11:04:36 -0400 Subject: [PATCH 6/7] fix(encounter): open-full navigation test + scoped watch + comment cleanup --- lib/features/encounter_screen.dart | 12 +++++++---- test/encounter_pane_compact_test.dart | 31 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/features/encounter_screen.dart b/lib/features/encounter_screen.dart index 0b92586..e39c5bd 100644 --- a/lib/features/encounter_screen.dart +++ b/lib/features/encounter_screen.dart @@ -22,7 +22,7 @@ class EncounterScreen extends StatelessWidget { } /// The one combat surface. Full mode (default) is the Track → Encounter -/// manager; [compact] renders the Run dashboard glance (Task 2). +/// manager; [compact] renders the Run dashboard glance. /// /// Initiative tracker: combatants from character sheets (live first-track /// link) or ad-hoc, turn pointer + round counter, statuses/defeated, and an @@ -36,8 +36,6 @@ class EncounterPane extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final async = ref.watch(encounterProvider); - final chars = - ref.watch(charactersProvider).valueOrNull ?? const []; return async.when( loading: () => const Center(child: CircularProgressIndicator()), error: (e, _) => Center(child: Text('Error: $e')), @@ -49,7 +47,13 @@ class EncounterPane extends ConsumerWidget { Expanded( child: s.combatants.isEmpty ? _empty(context) - : _list(context, ref, s, chars), + : _list( + context, + ref, + s, + ref.watch(charactersProvider).valueOrNull ?? + const [], + ), ), _addButtons(context, ref), ], diff --git a/test/encounter_pane_compact_test.dart b/test/encounter_pane_compact_test.dart index a329325..7fb50af 100644 --- a/test/encounter_pane_compact_test.dart +++ b/test/encounter_pane_compact_test.dart @@ -5,6 +5,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:loreseer/engine/models.dart'; import 'package:loreseer/features/encounter_screen.dart'; +import 'package:loreseer/shared/destination.dart'; +import 'package:loreseer/shared/shell_route.dart'; import 'package:shared_preferences/shared_preferences.dart'; void main() { @@ -63,4 +65,33 @@ void main() { await pump(tester); expect(find.byKey(const Key('run-init-empty')), findsOneWidget); }); + + testWidgets('run-init-open-full navigates to Track/Encounter', + (tester) async { + seed([ + { + 'id': 'g1', + 'name': 'Goblin', + 'initiative': 12, + 'track': {'current': 4, 'max': 7}, + }, + ]); + final container = ProviderContainer(); + addTearDown(container.dispose); + await tester.pumpWidget(UncontrolledProviderScope( + container: container, + child: + const MaterialApp(home: Scaffold(body: EncounterPane(compact: true))), + )); + await tester.pumpAndSettle(); + + expect(container.read(shellRouteProvider).destination, + isNot(Destination.track)); + + await tester.tap(find.byKey(const Key('run-init-open-full'))); + await tester.pumpAndSettle(); + + expect(container.read(shellRouteProvider).destination, Destination.track); + expect(container.read(shellRouteProvider).subtab, 'encounter'); + }); } From d4a945fc47d73c8cc42c936d8b210f76faace687 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Sat, 22 Aug 2026 11:17:38 -0400 Subject: [PATCH 7/7] style: drop unused import in compact test --- test/encounter_pane_compact_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/test/encounter_pane_compact_test.dart b/test/encounter_pane_compact_test.dart index 7fb50af..4563c40 100644 --- a/test/encounter_pane_compact_test.dart +++ b/test/encounter_pane_compact_test.dart @@ -3,7 +3,6 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:loreseer/engine/models.dart'; import 'package:loreseer/features/encounter_screen.dart'; import 'package:loreseer/shared/destination.dart'; import 'package:loreseer/shared/shell_route.dart';