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.
This commit is contained in:
parent
1298648e97
commit
429102105b
|
|
@ -24,12 +24,19 @@ const ICON_X_OFFSET = -145;
|
||||||
// How far (px) a grid travels off screen when switching categories.
|
// How far (px) a grid travels off screen when switching categories.
|
||||||
const GRID_TRAVEL = GAME_WIDTH + 800;
|
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 {
|
export default class GameMenuScene extends Phaser.Scene {
|
||||||
constructor() { super('GameMenu'); }
|
constructor() { super('GameMenu'); }
|
||||||
|
|
||||||
init(data) {
|
init(data) {
|
||||||
// Set when coming back from the opponent picker — restore that category.
|
// Category to restore on entry: the explicit one (coming back from the
|
||||||
this._initialCategory = (data && data.category) || null;
|
// 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
|
// scene.start() reuses the existing scene instance, so instance props from
|
||||||
// the previous visit survive — reset them so this create() starts clean
|
// the previous visit survive — reset them so this create() starts clean
|
||||||
// (otherwise showCategory()'s "same category" guard swallows the restore).
|
// (otherwise showCategory()'s "same category" guard swallows the restore).
|
||||||
|
|
@ -152,6 +159,7 @@ export default class GameMenuScene extends Phaser.Scene {
|
||||||
showCategory(key) {
|
showCategory(key) {
|
||||||
if (key === this._currentCategory) return;
|
if (key === this._currentCategory) return;
|
||||||
this._currentCategory = key;
|
this._currentCategory = key;
|
||||||
|
lastCategory = key;
|
||||||
|
|
||||||
if (this._hintText) { this._hintText.destroy(); this._hintText = null; }
|
if (this._hintText) { this._hintText.destroy(); this._hintText = null; }
|
||||||
if (this._titleText) {
|
if (this._titleText) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue