const Phaser = require('phaser'); const MenuCrypList = require('./menu.cryps.list'); const MenuNavigation = require('./menu.navigation'); const ItemList = require('./item.list'); class Menu extends Phaser.Scene { constructor() { super({ key: 'Menu', active: true }); } create() { this.registry.events.on('changedata', this.updateData, this); this.registry.events.on('setdata', this.updateData, this); // When we load the menu request the latest items // Item list will restart when the data comes in this.registry.get('ws').sendAccountItems(); this.scene.manager.add('MenuCrypList', MenuCrypList, true); this.scene.manager.add('MenuNavigation', MenuNavigation, true); this.scene.manager.add('ItemList', ItemList, true); return true; } updateData(parent, key, data) { if (key === 'game') { if (data) return this.cleanUp(); } return true; } cleanUp() { this.registry.events.off('changedata', this.updateData, this); this.registry.events.off('setdata', this.updateData, this); const ACTIVE_SCENES = ['MenuCrypList', 'MenuNavigation', 'GameList', 'StatSheet', 'ItemList', 'Zones']; ACTIVE_SCENES.forEach((sKey) => { if (this.scene.get(sKey)) this.scene.get(sKey).cleanUp(); }); this.scene.remove(); } } module.exports = Menu;