Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ Working rules for this repo:

## Project notes

- **Unified inspiration catalog (2026-08-13, PR 3 of the streamline epic)** —
one browsable catalog over three sources: flavor generators + bundled
starter tables + My Tables. Pure `lib/engine/inspiration_catalog.dart`
(`CatalogEntry`/`CatalogKind`, `buildCatalog` — dedups a bundled starter
when the user library holds a same-name `kStarterTableSource` copy,
`matchesCatalogQuery`, `groupCatalogByCategory`) +
`starterTablesProvider` (STRICT asset load; the asset owns its own stable,
unique `starter-*` ids — no provider-side re-id).
Ask → Tables gained 'Starter tables' (`starter-roll-<id>`) + 'Generators'
(`gen-roll-<id>`) sections with unified search; the one-tap
`tables-starter-pack` import tile is RETIRED (starters render directly).
GenerateSheet gained `starter-chip-<id>` chips. Provenance unchanged:
generators log `gen-*`, tables log `'custom-table'`. See
`docs/superpowers/specs/2026-08-12-streamline-library-exclusive-capabilities-design.md`.
A legacy user who had imported a starter table then renamed or deleted it
sees the pristine bundled original reappear read-only in the catalog (dedup
is by name + `kStarterTableSource`, so once that match breaks the bundled
entry is no longer hidden) — accepted behavior, not a bug.
- **Single-select capabilities (2026-08-12, PR 2 of the streamline epic)** —
overlapping tools are radio choices, not stacking toggles. Pure
`kExclusiveGroups` (`{'hex-flavor': [verdant, hexcrawl]}`) +
Expand Down Expand Up @@ -930,8 +948,9 @@ Working rules for this repo:
content — the user authors every row. A bundled **starter pack**
(`assets/starter_tables.json`, generated by `build_starter_tables.py` — same
script-is-source-of-truth rail; 22 ORIGINAL-authored general-play tables
stamped `src: kStarterTableSource`) imports one-tap via `tables-starter-pack`
in My Tables (hidden once any starter-sourced table exists). Community
stamped `src: kStarterTableSource`) is surfaced read-only through the
unified inspiration catalog (see the 2026-08-13 bullet) rather than
imported. Community
collections (r/BehindTheTables via autorolltables) were evaluated and NOT
vendored — no reuse license on the content; only their topic coverage
informed the set. **Library taxonomy (community binder
Expand Down
502 changes: 502 additions & 0 deletions docs/superpowers/plans/2026-08-13-inspiration-catalog.md

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions lib/engine/inspiration_catalog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/// One inspiration catalog over three sources: the flavor generators, the
/// bundled read-only starter tables, and the user's My Tables. Both rolling
/// surfaces (Ask → Tables, GenerateSheet) render this list, so a table or
/// generator added in one place appears in both. Pure — no Flutter.
library;

import 'custom_table.dart';
import 'generator_registry.dart';

enum CatalogKind { generator, table }

class CatalogEntry {
const CatalogEntry({
required this.id,
required this.name,
required this.kind,
required this.category,
this.genre = '',
this.source = '',
this.editable = false,
this.gen,
this.table,
});
final String id;
final String name;
final CatalogKind kind;
final String category;
final String genre;
final String source;

/// True only for the user's own tables — the editor opens on these.
final bool editable;
final GeneratorDef? gen; // set when kind == generator
final CustomTable? table; // set when kind == table
}

/// Merges the three sources. A bundled starter is dropped when the user
/// library already holds a table with the same name and starter source —
/// legacy libraries imported the pack via the old one-tap button, and the
/// user's (possibly edited) copy wins.
List<CatalogEntry> buildCatalog({
required List<GeneratorDef> generators,
required List<CustomTable> starters,
required List<CustomTable> userTables,
}) {
final imported = {
for (final t in userTables)
if (t.source == kStarterTableSource) t.name,
};
return [
for (final g in generators)
CatalogEntry(
id: 'gen-${g.label.toLowerCase().replaceAll(' ', '-')}',
name: g.label,
kind: CatalogKind.generator,
category: g.section.label,
source: 'Built-in',
gen: g,
),
for (final t in starters)
if (!imported.contains(t.name))
CatalogEntry(
id: t.id,
name: t.name,
kind: CatalogKind.table,
category: t.category,
genre: t.genre,
source: t.source,
table: t,
),
for (final t in userTables)
CatalogEntry(
id: t.id,
name: t.name,
kind: CatalogKind.table,
category: t.category,
genre: t.genre,
source: t.source,
editable: true,
table: t,
),
];
}

/// Library search across the whole catalog (name/genre/category/source),
/// mirroring [matchesTableQuery]'s fields. [q] arrives lowercased.
bool matchesCatalogQuery(CatalogEntry e, String q) => [
e.name,
e.genre,
e.category,
e.source,
].any((f) => f.toLowerCase().contains(q));

/// Category-sorted grouping; entries keep their catalog order inside each
/// group (generators first, then starters, then user tables).
List<(String, List<CatalogEntry>)> groupCatalogByCategory(
List<CatalogEntry> entries) {
final byCat = <String, List<CatalogEntry>>{};
for (final e in entries) {
byCat.putIfAbsent(e.category, () => []).add(e);
}
final cats = byCat.keys.toList()..sort();
return [for (final c in cats) (c, byCat[c]!)];
}
36 changes: 36 additions & 0 deletions lib/features/generate_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../engine/custom_table.dart';
import '../engine/dice.dart';
import '../engine/generator_registry.dart';
import '../engine/inspiration_catalog.dart';
import '../engine/models.dart';
import '../engine/oracle.dart';
import '../engine/oracle_data.dart';
Expand Down Expand Up @@ -127,6 +128,13 @@ class _GenerateSheetState extends ConsumerState<GenerateSheet> {
final theme = Theme.of(context);
final tables =
ref.watch(customTablesProvider).valueOrNull ?? const <CustomTable>[];
final starters =
ref.watch(starterTablesProvider).valueOrNull ?? const <CustomTable>[];
final starterEntries = buildCatalog(
generators: const [],
starters: starters,
userTables: tables,
).where((e) => e.kind == CatalogKind.table && !e.editable).toList();
final bySection = <GenSection, List<GeneratorDef>>{};
for (final g in flavorGenerators) {
bySection.putIfAbsent(g.section, () => []).add(g);
Expand Down Expand Up @@ -248,6 +256,34 @@ class _GenerateSheetState extends ConsumerState<GenerateSheet> {
),
],
),
if (starterEntries.isNotEmpty) ...[
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 6),
child:
Text('Starter Tables', style: theme.textTheme.labelMedium),
),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
for (final e in starterEntries)
ActionChip(
key: Key('starter-chip-${e.id}'),
label: Text(e.name),
onPressed: () async {
final r = rollCustomTable(e.table!, Dice());
final id = await ref
.read(journalProvider.notifier)
.addResult(r.title, r.asText,
sourceTool: 'custom-table',
payload: r.toPayload());
if (!context.mounted) return;
Navigator.of(context).pop(id);
},
),
],
),
],
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 6),
child:
Expand Down
110 changes: 86 additions & 24 deletions lib/features/tables_screen.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../engine/custom_table.dart';
import '../engine/dice.dart';
import '../engine/generator_registry.dart';
import '../engine/inspiration_catalog.dart';
import '../engine/models.dart';
import '../engine/oracle.dart';
import '../engine/table_groups.dart';
Expand Down Expand Up @@ -45,6 +46,25 @@ class _TablesScreenState extends ConsumerState<TablesScreen> {
final q = _query.trim().toLowerCase();
final customTables =
ref.watch(customTablesProvider).valueOrNull ?? const <CustomTable>[];
final starters =
ref.watch(starterTablesProvider).valueOrNull ?? const <CustomTable>[];
final catalog = buildCatalog(
generators: flavorGenerators,
starters: starters,
userTables: customTables);
final gens = [
for (final e in catalog)
if (e.kind == CatalogKind.generator &&
(q.isEmpty || matchesCatalogQuery(e, q)))
e,
];
final starterEntries = [
for (final e in catalog)
if (e.kind == CatalogKind.table &&
!e.editable &&
(q.isEmpty || matchesCatalogQuery(e, q)))
e,
];
return Column(
children: [
Padding(
Expand Down Expand Up @@ -105,6 +125,58 @@ class _TablesScreenState extends ConsumerState<TablesScreen> {
if (_visibleMyTables(customTables, q) case final mine
when q.isEmpty || mine.isNotEmpty)
_myTablesSection(customTables, mine),
if (starterEntries.isNotEmpty)
ExpansionTile(
key: q.isEmpty
? const PageStorageKey('tables-starters')
: const ValueKey('tables-starters-search'),
initiallyExpanded: q.isNotEmpty,
title: Text('Starter tables',
style: theme.textTheme.titleMedium),
subtitle: const Text(
'A general-play core set: NPCs, places, hooks, rumors…'),
childrenPadding: const EdgeInsets.only(bottom: 4),
children: [
for (final e in starterEntries)
Card(
child: ListTile(
key: Key('starter-roll-${e.id}'),
title: Text(e.name),
subtitle: switch ([
if (e.genre.trim().isNotEmpty) e.genre.trim(),
if (e.category.trim().isNotEmpty) e.category.trim(),
].join(' · ')) {
'' => null,
final meta => Text(meta),
},
trailing: const Icon(Icons.casino_outlined),
onTap: () => _rollCustomTable(e.table!),
),
),
],
),
if (gens.isNotEmpty)
ExpansionTile(
key: q.isEmpty
? const PageStorageKey('tables-generators')
: const ValueKey('tables-generators-search'),
initiallyExpanded: q.isNotEmpty,
title: Text('Generators', style: theme.textTheme.titleMedium),
subtitle: const Text('One-tap story, NPC, and detail rolls'),
childrenPadding: const EdgeInsets.only(bottom: 4),
children: [
for (final e in gens)
Card(
child: ListTile(
key: Key('gen-roll-${e.id}'),
title: Text(e.name),
subtitle: Text(e.category),
trailing: const Icon(Icons.casino_outlined),
onTap: () => _rollGenerator(e),
),
),
],
),
for (final group in groups)
if (_matching(group, q) case final matches
when matches.isNotEmpty)
Expand Down Expand Up @@ -140,6 +212,19 @@ class _TablesScreenState extends ConsumerState<TablesScreen> {
showLoggedSnackBar(context, ref, id);
}

/// Roll a catalog generator and log it under its section's gen-* tag —
/// identical provenance to the same generator rolled from the composer's
/// GenerateSheet.
Future<void> _rollGenerator(CatalogEntry e) async {
final g = e.gen!;
final r = g.run(widget.oracle);
final id = await ref.read(journalProvider.notifier).addResult(
r.title, r.asText,
sourceTool: sourceToolFor(g.section), payload: r.toPayload());
if (!mounted) return;
showLoggedSnackBar(context, ref, id);
}

/// The user tables visible under the current genre filter + search query.
List<CustomTable> _visibleMyTables(List<CustomTable> all, String q) => [
for (final t in all)
Expand Down Expand Up @@ -234,33 +319,10 @@ class _TablesScreenState extends ConsumerState<TablesScreen> {
onTap: () => showCustomTableDialog(context, ref, null),
),
),
// One-tap import of the bundled starter set (original authored
// tables); hidden once any starter-sourced table is in the library.
if (!all.any((t) => t.source == kStarterTableSource))
Card(
child: ListTile(
key: const Key('tables-starter-pack'),
leading: const Icon(Icons.auto_awesome_outlined),
title: const Text('Add starter tables'),
subtitle: const Text(
'A general-play core set: NPCs, places, hooks, rumors…'),
onTap: _importStarterPack,
),
),
],
);
}

Future<void> _importStarterPack() async {
final raw = await rootBundle.loadString('assets/starter_tables.json');
final tables = decodeTablePack(raw);
await ref.read(customTablesProvider.notifier).addAll(tables);
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Added ${tables.length} starter tables')),
);
}

/// Keys in [group] whose display title matches the lowercased query [q]
/// (all of them when [q] is empty).
List<String> _matching(TableGroup group, String q) => q.isEmpty
Expand Down
11 changes: 11 additions & 0 deletions lib/state/providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ final dungeonDataProvider = FutureProvider<DungeonTables>((ref) async {
return DungeonTables.fromJson(jsonDecode(raw) as Map<String, dynamic>);
});

/// Loads the bundled starter tables as read-only catalog entries. STRICT on
/// purpose (bundled asset, build-verified). The asset itself owns stable,
/// unique `starter-*` semantic ids (verified by test/starter_tables_test.dart)
/// — no re-id here, since an index-based id renumbers every entry below an
/// insertion. Replaces the old one-tap import — starters now appear in the
/// catalog directly.
final starterTablesProvider = FutureProvider<List<CustomTable>>((ref) async {
final raw = await rootBundle.loadString('assets/starter_tables.json');
return decodeTablePack(raw);
});

String _newId() => DateTime.now().microsecondsSinceEpoch.toString();

/// Tolerant decode for USER-persisted JSON (never bundled assets): corrupt
Expand Down
Loading
Loading