From 010b90bef5617b002421f93731e04b21b4b012a3 Mon Sep 17 00:00:00 2001 From: Hadrian Burkhardt Date: Mon, 2 Nov 2026 06:14:48 +0100 Subject: [PATCH] Require an earned rewarded ad for every puzzle hint --- README.md | 6 +- docs/CODE_MAP.md | 8 +- integration_test/cottage_test.dart | 4 +- integration_test/notebook_test.dart | 2 +- lib/main.dart | 28 ++---- test/widget_test.dart | 148 ++++++++++++++++++++++++++-- 6 files changed, 158 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index af46702..47e690b 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,11 @@ Android is the tested target. iOS project scaffolding and test AdMob configurati - A saved ribbon bookmark, opened note, inspected repair, viewed pages and current reading place. - Twelve 7×7 picture puzzles across three chapters, with overlapping-area deductions on entries 3–12. Chapters II and III retain their briefing/puzzle/reveal structure, with swipes between those pages too. Chapter contents shows four entries at a time. Reading ahead keeps unfinished boards and completion awards separate. - Deterministic daily grids and generated Easy, Medium and Hard 5×5 practice. The grades measure deduction-chain depth, not expert-level difficulty. Every board has a unique solution and needs no guessing. -- Undo and unlimited free explained hints in the story. Daily and classic puzzles have one free explained hint, then optional rewarded hints. Rewarded hints require the AdMob reward callback. An unavailable ad never blocks the board. +- Undo and optional explained hints in every mode. Each hint, including the first, requires a voluntary rewarded ad and its AdMob reward callback. Declining, closing without a reward or unavailable ads leaves the grid unchanged; solving and reading remain available. - Expanded story passages connect the harbour key, crossing, bell signals and reunion with Mara. All added passages are narrated; original takes continue seamlessly into the new sections. - Solved patterns remain available when turning back from discoveries, including after restarting. Discoveries blend the exact pixel symbol into the watercolour, keep a small copy of the symbol visible, and offer a replay. - Local daily streaks, independent difficulty levels and exactly-once puzzle completion awards. -- AdMob/UMP consent, optional rewarded hints, practice interstitials after every fourth completion and one-time campaign chapter transitions. No ads interrupt opening notebook leaves or recorded readings. +- AdMob/UMP consent, optional rewarded hints, practice interstitials after every fourth completion and one-time campaign chapter transitions. Automatic ads do not interrupt opening notebook leaves or recorded readings; puzzle hints show ads only after confirmation. Progress starts fresh in Flutter, as requested. Old Java `lumen.xml` saves are **not imported or read**. Flutter keeps its own local preferences through `shared_preferences`; no account or game backend is required. Uninstalling loses local progress, and the daily date follows the device calendar. @@ -76,7 +76,7 @@ flutter drive --driver test_driver/integration_test.dart \ --dart-define=QA_TEST=true -d YOUR_ANDROID_DEVICE ``` -The thirty-five unit/widget tests cover 40 Java reference boards (including signed 64-bit seeds), 300 graded generated boards, solver counts against 300 exhaustive small systems, all twelve campaign solutions, bounded campaign comparison chains, solved-grid inspection after restart, discovery animation/replay, repeated free story hints, streaks, fresh progress, read-ahead, completion awards, campaign read-ahead restoration, gesture isolation, swipes over text and blank paper, cancelled drags, vertical scrolling, landscape and larger text; it also checks every cottage leaf with the real font at 1.5× text, all four hint controls, legacy route migration and exactly-once completion after restart. Reference parity protects the port’s rules; it is not used to migrate saves. +The thirty-eight unit/widget tests cover 40 Java reference boards (including signed 64-bit seeds), 300 graded generated boards, solver counts against 300 exhaustive small systems, all twelve campaign solutions, bounded campaign comparison chains, solved-grid inspection after restart, discovery animation/replay, reward-gated hints in every mode, declined/unavailable ads and duplicate/stale reward callbacks, streaks, fresh progress, read-ahead, completion awards, campaign read-ahead restoration, gesture isolation, swipes over text and blank paper, cancelled drags, vertical scrolling, landscape and larger text; it also checks every cottage leaf with the real font at 1.5× text, all four hint controls, legacy route migration and exactly-once completion after restart. Reference parity protects the port’s rules; it is not used to migrate saves. The physical-device integration test uses a disposable in-memory game plus an isolated QA disk round-trip. It plays all five real WAV files, checks pause/resume, explores the six leaves, verifies bookmarks/discoveries, solves match and lantern puzzles and checks exactly-once awards. Screenshots are saved in `artifacts/flutter-check/`. The release smoke script requires an active, unmuted 24 kHz media track in the tablet’s audio mixer as well as exercising the actual play/pause/resume UI and restores the last page after process restart, without injecting puzzle fixtures. The release build includes a targeted R8 keep rule for the database constructor used reflectively by AdMob’s WorkManager dependency. Advertising is disabled for the automated story tests; real UMP startup is checked separately in the normal build. Reward delivery, cancellation and ad no-fill still need manual release testing with your final AdMob configuration. diff --git a/docs/CODE_MAP.md b/docs/CODE_MAP.md index 7915ba5..1d57d10 100644 --- a/docs/CODE_MAP.md +++ b/docs/CODE_MAP.md @@ -296,7 +296,7 @@ All writes go through `Progress.set` (memory is updated synchronously, disk is w | `grid_` | digit string | `Game._save` | Marks per board (`0` empty, `1` lit, `2` crossed) | | `done_` | bool | `Game.check` | Exactly-once completion and win lock | | `solved` | int | `Game.check` | Lifetime completions | -| `hint_` | bool | `hint()` | Tracks hint use; daily/classic later hints need a rewarded ad, campaign hints stay free | +| `hint_` | legacy bool | no longer written | Old free-hint tracking is ignored; every hint now requires a separate earned ad reward | | `lastDaily` | int (epoch day) | daily completion | Streak bookkeeping | | `streak` | int | daily completion | Consecutive daily completions | | `campaignUnlocked` | int 0–11 | campaign completion | Furthest solved campaign level | @@ -355,7 +355,7 @@ Board key formats (``): - `Ads.supported` is false on the web, when `enabled`/`adsEnabled` is false (both test suites pass `adsEnabled: false`) and on platforms other than Android/iOS. - `start()` requests UMP consent, shows the form if required, then initialises the SDK and preloads one rewarded and one interstitial ad. -- Hint flow: campaign hints are always free and explained. Daily/classic boards keep the first-free policy (`hint_`); later hints require confirmation and `ads.hint(give)`. If no ad is available the user sees "No ad available. Please try again later." and no hint is consumed. +- Hint flow: every hint in campaign, daily and classic requires explicit confirmation and `ads.hint(give)`, including the first hint. The grid changes only in the reward callback; a local guard permits at most one hint per rewarded ad. Late callbacks check the active puzzle key and route. `Notebook.ads` permits deterministic reward/cancel/no-fill tests without bypassing the production gate. If no ad is available the user sees "No ad available. Please try again later." and no hint is consumed. - Interstitials: `nextPractice()` after every fourth classic completion; `nextCampaign()` at most once per fourth campaign step (`storyAd_`). `between(next)` always calls `next()` if ads are unavailable, stale (≥58 min) or unconsented. - `privacy()` opens the privacy options form only when UMP requires it; otherwise `main.dart` shows the local privacy explanation. - Ad unit IDs default to Google test IDs; production overrides come from `ADMOB_APP_ID` (Gradle), `ADMOB_REWARDED_ID` and `ADMOB_INTERSTITIAL_ID` (Dart defines). @@ -369,7 +369,7 @@ Board key formats (``): | `test/ambience_test.dart` | Scene mapping, voice ducking, mute/background stop, stale loading requests, backend failure/recovery and disposal | | `integration_test/soundscape_test.dart` | Real-device decoding of all 24 new continuations, bridge/narration mixing, saved mute and automatic Mara-to-narrator handoff | | `test/puzzle_test.dart` | 40 Java reference boards (signed 64-bit seeds), 300 graded boards, solver counts vs. exhaustive search, campaign uniqueness/no-guess, streaks, fresh progress, read-ahead, daily awards and practice levels | -| `test/widget_test.dart` | Pattern-to-art timing/replay, back-to-solved-grid navigation, repeated free story hints, page swipes vs. grid drags, swipes over text/blank paper, vertical scrolling and cancelled drags, small/landscape/1.5× text, landscape two-column puzzle leaf, illustrated campaign reveals and pixel fallback at 1.5× text | +| `test/widget_test.dart` | Pattern-to-art timing/replay, back-to-solved-grid navigation, rewarded hints in all modes, declined/unavailable ads and duplicate/stale callbacks, page swipes vs. grid drags, swipes over text/blank paper, vertical scrolling and cancelled drags, small/landscape/1.5× text, landscape two-column puzzle leaf, illustrated campaign reveals and pixel fallback at 1.5× text | | `integration_test/notebook_test.dart` | On-device QA flow: six leaves, real WAV playback and pause/resume, bookmarks/discoveries, match and lantern solves, exactly-once awards, QA disk round-trip, screenshots | | `integration_test/cottage_test.dart` | All sixteen leaves, larger-text portrait/landscape, bookmarks, legacy-key marks, all four awards, all 23 narrator tracks and isolated test persistence; eight screenshots | | `integration_test/discovery_art_test.dart` | QA tablet screenshots of all twelve discoveries and the opening match memory, portrait/landscape at 1.5× text; checks reachable controls and unchanged awards | @@ -446,7 +446,7 @@ Each run checks four discoveries in both orientations at 1.5× text, including n - **Story page 3 is index 2.** Solving the opening match puzzle awards the first campaign entry (`story_v1_0`) and jumps to story page 4 (`showStory(3)`), skipping the campaign reveal. - **`showStory()` sets campaign mode and the page record’s campaign index (0 if absent).** Daily and classic starts set their own mode afterwards; keep that order. - **`startPractice` discards stale results** with `_request`. Do not remove that guard when refactoring. -- **Hints are applied immediately.** `Game.applyHint()` writes a mark and pushes an undo snapshot; the free/ad gate lives in `_NotebookState.hint()` via `hint_`, not in the domain. +- **Hints are applied immediately.** `Game.applyHint()` writes a mark and pushes an undo snapshot; the rewarded-ad gate lives in `_NotebookState.hint()`, not in the domain. - **Read-ahead never bypasses access.** `reveal(i, readAhead: true)` still redirects when `i > accessible`. - **Streaks use UTC epoch days.** Do not compare local `DateTime` values directly; `visibleStreak` drops to zero when the last completion is older than yesterday. - **`Puzzle.deductionRounds` throws** if a board cannot be solved by singles (plus area comparisons). Generation and tests assume no guessing. diff --git a/integration_test/cottage_test.dart b/integration_test/cottage_test.dart index 425f309..885e89f 100644 --- a/integration_test/cottage_test.dart +++ b/integration_test/cottage_test.dart @@ -121,9 +121,9 @@ void main() { greaterThan(tester.view.physicalSize.height), ); expect(game.cells, marks); - await tester.ensureVisible(find.text('Hint · free')); + await tester.ensureVisible(find.text('Hint · rewarded ad')); await tester.pumpAndSettle(); - expect(find.text('Hint · free').hitTestable(), findsOneWidget); + expect(find.text('Hint · rewarded ad').hitTestable(), findsOneWidget); final lastCell = tester.getRect(find.byKey(const ValueKey('cell-48'))); expect( lastCell.bottom, diff --git a/integration_test/notebook_test.dart b/integration_test/notebook_test.dart index 2e86d4f..0cf781a 100644 --- a/integration_test/notebook_test.dart +++ b/integration_test/notebook_test.dart @@ -81,7 +81,7 @@ void main() { await tap('Next leaf →'); expect(g.storyIndex, 2); expect( - tester.getBottomRight(find.text('Hint · free')).dy, + tester.getBottomRight(find.text('Hint · rewarded ad')).dy, lessThan(tester.getTopLeft(find.text('Contents')).dy), ); await shot('03-puzzle'); diff --git a/lib/main.dart b/lib/main.dart index fdea249..40b03e9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -69,10 +69,12 @@ class Notebook extends StatefulWidget { required this.game, required this.adsEnabled, this.narrator, + this.ads, }); final Game game; final bool adsEnabled; final Narrator? narrator; + final Ads? ads; @override State createState() => _NotebookState(); } @@ -93,7 +95,7 @@ class _NotebookState extends State with WidgetsBindingObserver { narrator = widget.narrator ?? Narrator(g.book.tracks); ambience = Ambience(); narrator.addListener(_syncAtmosphere); - ads = Ads(enabled: widget.adsEnabled); + ads = widget.ads ?? Ads(enabled: widget.adsEnabled); g.addListener(_changed); _route = route; WidgetsBinding.instance.addObserver(this); @@ -1033,17 +1035,7 @@ class _NotebookState extends State with WidgetsBindingObserver { ), ), const SizedBox(width: 8), - Expanded( - child: InkButton( - g.mode == Mode.campaign - ? 'Hint · free' - : prefs.flag('hint_${g.key}') - ? 'Hint · rewarded ad' - : 'Hint · free', - hint, - size: 22, - ), - ), + Expanded(child: InkButton('Hint · rewarded ad', hint, size: 22)), ], ), ]; @@ -1183,8 +1175,10 @@ class _NotebookState extends State with WidgetsBindingObserver { Future hint() async { final requested = g.key; + var granted = false; void give() async { - if (!mounted || + if (granted || + !mounted || g.key != requested || g.won || !(g.screen == Screen.game || @@ -1192,6 +1186,7 @@ class _NotebookState extends State with WidgetsBindingObserver { g.storyPage.type == StoryPageType.puzzle)) { return; } + granted = true; final h = g.applyHint(); if (h == null) return; await message( @@ -1207,11 +1202,6 @@ class _NotebookState extends State with WidgetsBindingObserver { } } - if (g.mode == Mode.campaign || !prefs.flag('hint_$requested')) { - await prefs.set('hint_$requested', true); - give(); - return; - } if (!await confirm( 'A little nudge?', 'Watch a rewarded ad for one explained hint.', @@ -1341,7 +1331,7 @@ class _NotebookState extends State with WidgetsBindingObserver { void rules() => message( 'Find the light', - 'Light exactly as many cells as the number beside each row and above each column.\n\nTap to cycle: empty → light → crossed out → empty. Mark every cell to finish. Small dots mark fixed clues.\n\nA, B and C are overlapping areas with their own totals. Shared cells count in both areas. Compare clues and subtract their shared parts to find new deductions.\n\nEvery story grid reveals an object. Later pages require area comparisons; all are solvable without guessing. Classic practice grades the length of simpler row and column chains.\n\nStory hints are always free and explained. Daily and classic puzzles offer one free hint, then optional rewarded hints. Streaks count consecutive daily completions on this device.', + 'Light exactly as many cells as the number beside each row and above each column.\n\nTap to cycle: empty → light → crossed out → empty. Mark every cell to finish. Small dots mark fixed clues.\n\nA, B and C are overlapping areas with their own totals. Shared cells count in both areas. Compare clues and subtract their shared parts to find new deductions.\n\nEvery story grid reveals an object. Later pages require area comparisons; all are solvable without guessing. Classic practice grades the length of simpler row and column chains.\n\nWatch a rewarded ad for each explained hint. Hints are optional, and your puzzle remains available if no ad can be shown. Streaks count consecutive daily completions on this device.', close: 'Got it', ); Future privacy() async { diff --git a/test/widget_test.dart b/test/widget_test.dart index c684b68..2062bba 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -6,10 +6,27 @@ import 'package:lumen/domain/game.dart'; import 'package:lumen/domain/puzzle.dart'; import 'package:lumen/main.dart'; import 'package:lumen/services/progress.dart'; +import 'package:lumen/services/ads.dart'; import 'package:lumen/ui/board.dart'; import 'package:lumen/ui/discovery.dart'; import 'package:lumen/ui/paper.dart'; +class _RewardAds extends Ads { + _RewardAds({this.autoReward = false}) : super(enabled: false); + final bool autoReward; + bool available = true; + int requests = 0; + VoidCallback? reward; + @override + Future hint(VoidCallback earned) async { + requests++; + if (!available) return false; + reward = earned; + if (autoReward) earned(); + return true; + } +} + void main() { testWidgets('atmosphere controls fit large text and remember mute', ( tester, @@ -130,29 +147,136 @@ void main() { }, ); - testWidgets('campaign help stays free after the first explained hint', ( + testWidgets('every story hint needs a separate earned ad reward', ( tester, ) async { final book = (await tester.runAsync(Book.load))!; final g = Game(book, Progress.memory({'story_access_level': 11})); + final ads = _RewardAds(); g.startCampaign(8); - await tester.pumpWidget(LumenApp(game: g, adsEnabled: false)); + await tester.pumpWidget( + MaterialApp( + home: Notebook(game: g, adsEnabled: false, ads: ads), + ), + ); await tester.pumpAndSettle(); for (var i = 0; i < 2; i++) { final before = List.of(g.cells); - final hint = find.text('Hint · free'); + final hint = find.text('Hint · rewarded ad'); await tester.ensureVisible(hint); await tester.pumpAndSettle(); await tester.tap(hint); await tester.pumpAndSettle(); - expect(g.cells, isNot(before)); - expect(find.text('Watch ad'), findsNothing); + expect(g.cells, before); + await tester.tap(find.text('Watch ad')); + await tester.pumpAndSettle(); + expect(ads.requests, i + 1); + expect(g.cells, before, reason: 'Showing an ad alone earns no hint'); + ads.reward!(); + await tester.pumpAndSettle(); + expect( + List.generate( + g.cells.length, + (c) => c, + ).where((c) => g.cells[c] != before[c]).length, + 1, + ); + final after = List.of(g.cells); + ads.reward!(); + await tester.pumpAndSettle(); + expect(g.cells, after, reason: 'One reward can grant only one hint'); await tester.tap(find.text('Keep going')); await tester.pumpAndSettle(); } expect(g.solved, 0); await tester.pumpWidget(const SizedBox()); }); + + testWidgets( + 'declining, unavailable or unfinished ads leave the puzzle untouched', + (tester) async { + final book = (await tester.runAsync(Book.load))!; + final g = Game(book, Progress.memory({'story_access_level': 11})); + final ads = _RewardAds(); + g.startCampaign(8); + await tester.pumpWidget( + MaterialApp( + home: Notebook(game: g, adsEnabled: false, ads: ads), + ), + ); + await tester.pumpAndSettle(); + Future request() async { + final hint = find.text('Hint · rewarded ad'); + await tester.ensureVisible(hint); + await tester.pumpAndSettle(); + await tester.tap(hint); + await tester.pumpAndSettle(); + } + + final before = List.of(g.cells); + await request(); + await tester.tap(find.text('Keep thinking')); + await tester.pumpAndSettle(); + expect(ads.requests, 0); + expect(g.cells, before); + ads.available = false; + await request(); + await tester.tap(find.text('Watch ad')); + await tester.pumpAndSettle(); + expect( + find.text('No ad available. Please try again later.'), + findsOneWidget, + ); + expect(g.cells, before); + ads.available = true; + await request(); + await tester.tap(find.text('Watch ad')); + await tester.pumpAndSettle(); + expect(g.cells, before); + g.startCampaign(9); + await tester.pumpAndSettle(); + final next = List.of(g.cells); + ads.reward!(); + await tester.pumpAndSettle(); + expect( + g.cells, + next, + reason: 'A late reward cannot alter another puzzle', + ); + await tester.pumpWidget(const SizedBox()); + }, + ); + + for (final mode in [Mode.daily, Mode.classic]) { + testWidgets('the first $mode hint also requires an ad', (tester) async { + final book = (await tester.runAsync(Book.load))!; + final g = Game(book, Progress.memory()); + if (mode == Mode.daily) { + g.startDaily(DateTime(2026, 11, 2)); + } else { + await tester.runAsync(() => g.startPractice()); + } + final ads = _RewardAds(); + await tester.pumpWidget( + MaterialApp( + home: Notebook(game: g, adsEnabled: false, ads: ads), + ), + ); + await tester.pumpAndSettle(); + final before = List.of(g.cells); + final hint = find.text('Hint · rewarded ad'); + await tester.ensureVisible(hint); + await tester.pumpAndSettle(); + await tester.tap(hint); + await tester.pumpAndSettle(); + expect(find.text('Watch ad'), findsOneWidget); + expect(g.cells, before); + await tester.tap(find.text('Keep thinking')); + await tester.pumpAndSettle(); + expect(ads.requests, 0); + await tester.pumpWidget(const SizedBox()); + }); + } testWidgets( 'object illustrations remain hidden until their own pattern is solved', (tester) async { @@ -269,7 +393,11 @@ void main() { size: size, textScaler: const TextScaler.linear(1.5), ), - child: Notebook(game: g, adsEnabled: false), + child: Notebook( + game: g, + adsEnabled: false, + ads: _RewardAds(autoReward: true), + ), ), ), ); @@ -279,11 +407,13 @@ void main() { final page = book.pages[i]; if (page.type == StoryPageType.puzzle) { final before = List.of(g.cells); - final hint = find.text('Hint · free'); + final hint = find.text('Hint · rewarded ad'); await tester.ensureVisible(hint); await tester.pumpAndSettle(); await tester.tap(hint); await tester.pumpAndSettle(); + await tester.tap(find.text('Watch ad')); + await tester.pumpAndSettle(); expect(g.cells, isNot(before), reason: page.id); await tester.tap(find.text('Keep going')); await tester.pumpAndSettle(); @@ -592,7 +722,7 @@ void main() { tester.getTopLeft(find.text('A spark in the drawer')).dx, greaterThan(lastCell.right), ); - expect(find.text('Hint · free'), findsOneWidget); + expect(find.text('Hint · rewarded ad'), findsOneWidget); expect(find.text('Next leaf →'), findsOneWidget); expect(tester.takeException(), isNull); @@ -604,7 +734,7 @@ void main() { final storyLast = tester.getRect(find.byKey(const ValueKey('cell-48'))); expect(storyLast.bottom, lessThan(height * .94)); expect( - tester.getTopLeft(find.text('Hint · free')).dx, + tester.getTopLeft(find.text('Hint · rewarded ad')).dx, greaterThan(storyLast.right), ); expect(find.text('Next leaf →'), findsOneWidget);