Skip to content

Commit 8ab1e79

Browse files
committed
Merge branch 'wl-CG-0MLTFQZ6G09TVLDL-transcript-browser-storage' into main
2 parents 11ad928 + 6c3bc51 commit 8ab1e79

4 files changed

Lines changed: 768 additions & 0 deletions

File tree

example-games/golf/scenes/GolfScene.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { scoreGrid, scoreVisibleCards } from '../GolfScoring';
1919
import { AiPlayer, GreedyStrategy, RandomStrategy } from '../AiStrategy';
2020
import type { AiStrategy } from '../AiStrategy';
2121
import { TranscriptRecorder } from '../GameTranscript';
22+
import type { GameTranscript } from '../GameTranscript';
23+
import { TranscriptStore } from '../../../src/core-engine/TranscriptStore';
2224
import { HelpPanel, HelpButton } from '../../../src/ui';
2325
import type { HelpSection } from '../../../src/ui';
2426
import helpContent from '../help-content.json';
@@ -59,6 +61,9 @@ type TurnPhase =
5961

6062
// ── Scene ───────────────────────────────────────────────────
6163

64+
/** Shared TranscriptStore instance for the Golf game. */
65+
const transcriptStore = new TranscriptStore();
66+
6267
export class GolfScene extends Phaser.Scene {
6368
// Game state
6469
private session!: GolfSession;
@@ -674,6 +679,29 @@ export class GolfScene extends Phaser.Scene {
674679
this.helpButton?.destroy();
675680
}
676681

682+
// ── Transcript persistence ──────────────────────────────
683+
684+
/**
685+
* Auto-save a finalized transcript to browser storage.
686+
* Fires and forgets -- errors are logged but do not disrupt gameplay.
687+
*/
688+
private autoSaveTranscript(transcript: GameTranscript): void {
689+
transcriptStore.save('golf', transcript).then(
690+
(stored) => {
691+
if (stored) {
692+
console.info(
693+
`[GolfScene] Transcript saved (${stored.id}) via ${stored.gameType}`,
694+
);
695+
} else {
696+
console.warn('[GolfScene] Transcript not saved -- no storage backend available');
697+
}
698+
},
699+
(err) => {
700+
console.error('[GolfScene] Failed to auto-save transcript:', err);
701+
},
702+
);
703+
}
704+
677705
// ── End screen ──────────────────────────────────────────
678706

679707
private showEndScreen(): void {
@@ -691,6 +719,9 @@ export class GolfScene extends Phaser.Scene {
691719
const transcript = this.recorder.finalize();
692720
const results = transcript.results!;
693721

722+
// Auto-save transcript to browser storage
723+
this.autoSaveTranscript(transcript);
724+
694725
// Overlay
695726
// Full-screen input blocker to prevent clicks reaching objects behind
696727
const blocker = this.add.rectangle(

0 commit comments

Comments
 (0)