From 429102105b072d22aca29da477bca23d1a8dafc4 Mon Sep 17 00:00:00 2001 From: Brian Fertig Date: Mon, 31 Aug 2026 22:45:22 -0600 Subject: [PATCH] Persist last selected category across menu restarts - Track the most recently chosen category in module scope so it survives scene.start() reusing the same instance. - Fall back to that value when entering the menu without explicit category data, restoring the user's previous selection instead of defaulting. --- src/scenes/GameMenuScene.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/scenes/GameMenuScene.js b/src/scenes/GameMenuScene.js index 8f660b2..b63afc6 100644 --- a/src/scenes/GameMenuScene.js +++ b/src/scenes/GameMenuScene.js @@ -24,12 +24,19 @@ const ICON_X_OFFSET = -145; // How far (px) a grid travels off screen when switching categories. const GRID_TRAVEL = GAME_WIDTH + 800; +// The most recently selected category. Module scope so it survives scene +// restarts (scene.start() reuses the instance) and also covers paths that +// start the menu without category data — the menu always returns to where +// the user last was. +let lastCategory = null; + export default class GameMenuScene extends Phaser.Scene { constructor() { super('GameMenu'); } init(data) { - // Set when coming back from the opponent picker — restore that category. - this._initialCategory = (data && data.category) || null; + // Category to restore on entry: the explicit one (coming back from the + // opponent picker) or the most recently selected one. + this._initialCategory = (data && data.category) || lastCategory; // scene.start() reuses the existing scene instance, so instance props from // the previous visit survive — reset them so this create() starts clean // (otherwise showCategory()'s "same category" guard swallows the restore). @@ -152,6 +159,7 @@ export default class GameMenuScene extends Phaser.Scene { showCategory(key) { if (key === this._currentCategory) return; this._currentCategory = key; + lastCategory = key; if (this._hintText) { this._hintText.destroy(); this._hintText = null; } if (this._titleText) {