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) {