const Phaser = require('phaser'); const MenuCrypList = require('./menu.cryps.list'); const MenuGameList = require('./menu.game.list'); const Combat = require('./combat'); // const ItemList = require('./item.list'); const StatSheet = require('./statsheet'); 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); this.scene.add('MenuCrypList', MenuCrypList, true); this.scene.add('MenuGameList', MenuGameList, true); this.sys.events.on('wake', () => { this.wakeMenuScenes(); }); return true; } wakeMenuScenes() { this.registry.events.on('changedata', this.updateData, this); this.registry.events.on('setdata', this.updateData, this); this.scene.add('MenuCrypList', MenuCrypList, true); this.scene.add('MenuGameList', MenuGameList, true); console.log(this.scene.isActive()); } updateData(parent, key, data) { if (key === 'itemList') { // return this.renderItemList(); } if (key === 'game' && this.scene.isActive()) { this.cleanUp(); this.scene.add('Combat', Combat); this.scene.run('Combat', data); this.scene.sleep(); } return true; } // Scene switch to statsheet called by MenuCrypRows scene displaySkills(cryp) { if (cryp) { this.cleanUp(); this.scene.add('StatSheet', StatSheet); this.scene.run('StatSheet', cryp); this.scene.sleep(); } return true; } renderItemList() { const ws = this.registry.get('ws'); const itemList = this.registry.get('itemList'); if (this.itemList) { this.itemList.cleanup(); this.itemList.destroy(true); } // this.itemList = new ItemList({ list: this, ws, itemList, events: this.game.events }); } cleanUp() { // Remove all the scenes except header and this scene (menu) this.registry.events.off('changedata', this.updateData, this); this.registry.events.off('setdata', this.updateData, this); const ACTIVE_SCENES = ['Header', 'Menu']; Object.keys(this.scene.manager.keys).forEach((key) => { if (!ACTIVE_SCENES.includes(key)) { // Remove listeners and scene this.scene.get(key).cleanUp(); } }); } } module.exports = Menu;