From 24060accabbca0698e7edc17ba048e6f718e0a2c Mon Sep 17 00:00:00 2001 From: ntr Date: Sun, 23 Dec 2018 23:58:05 +1100 Subject: [PATCH] stop menu wip --- client/src/scenes/combat.js | 32 ++++++++++++-------- client/src/scenes/cryps.js | 16 +++++++++- client/src/scenes/menu.js | 59 +++++++------------------------------ 3 files changed, 46 insertions(+), 61 deletions(-) diff --git a/client/src/scenes/combat.js b/client/src/scenes/combat.js index 1fac2557..47b091cb 100644 --- a/client/src/scenes/combat.js +++ b/client/src/scenes/combat.js @@ -34,12 +34,14 @@ class Combat extends Phaser.Scene { } create() { + console.log('creating game'); this.registry.events.off('changedata', this.updateData); this.registry.events.on('changedata', this.updateData, this); this.input.keyboard.on('keydown_BACKSPACE', () => { - this.endGame(); + this.cleanUp(); }, 0, this); this.registry.set('gamePhase', false); + this.registry.set('inGame', true); this.registry.set('gameAnimating', false); this.account = this.registry.get('account'); this.fetchGame = throttle(() => { @@ -50,6 +52,7 @@ class Combat extends Phaser.Scene { } return false; }, 500); + return true; } @@ -64,17 +67,6 @@ class Combat extends Phaser.Scene { return true; } - endGame() { - this.registry.set('game', null); - this.scene.wake('Menu'); // Switch back to cryp list - this.scene.get('CombatLog').cleanUp(); - this.scene.get('CombatCryps').cleanUp(); - this.scene.get('CombatSkills').cleanUp(); - this.scene.get('CombatHitBox').cleanUp(); - this.scene.remove(); - return true; - } - update() { this.fetchGame(); return true; @@ -115,6 +107,22 @@ class Combat extends Phaser.Scene { } return true; } + + cleanUp() { + this.registry.events.off('changedata', this.updateData, this); + this.registry.events.off('setdata', this.updateData, this); + + this.registry.set('game', null); + this.registry.set('inGame', null); + + this.scene.get('CombatLog').cleanUp(); + this.scene.get('CombatCryps').cleanUp(); + this.scene.get('CombatSkills').cleanUp(); + this.scene.get('CombatHitBox').cleanUp(); + this.scene.remove(); + + return true; + } } module.exports = Combat; diff --git a/client/src/scenes/cryps.js b/client/src/scenes/cryps.js index 0baf09e6..d0c581ed 100644 --- a/client/src/scenes/cryps.js +++ b/client/src/scenes/cryps.js @@ -2,6 +2,7 @@ const Phaser = require('phaser'); const Header = require('./header'); const Menu = require('./menu'); +const Combat = require('./combat'); function renderCryps() { const config = { @@ -25,7 +26,20 @@ function renderCryps() { }; const game = new Phaser.Game(config); - // game.scene.sleep('Combat'); + + function changeData(parent, key, data) { + console.log(key, data); + if (key === 'game') { + if (!data) return game.scene.add('Menu', Menu, true); + + console.log(game.registry.get('inGame')); + if (game.registry.get('inGame')) return false; + return game.scene.add('Combat', Combat, true); + } + } + + game.registry.events.on('changedata', changeData); + game.registry.events.on('setdata', changeData); function resize() { const canvas = document.querySelector('canvas'); diff --git a/client/src/scenes/menu.js b/client/src/scenes/menu.js index ed5e1fac..9ef13a55 100644 --- a/client/src/scenes/menu.js +++ b/client/src/scenes/menu.js @@ -3,7 +3,6 @@ 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'); @@ -14,46 +13,19 @@ class Menu extends Phaser.Scene { create() { this.registry.events.on('changedata', this.updateData, this); - this.registry.events.on('setdata', this.setData, this); - this.sys.events.on('wake', () => { - this.addMenuScenes(); - }); + this.registry.events.on('setdata', this.updateData, this); + this.scene.manager.add('MenuCrypList', MenuCrypList, true); + this.scene.manager.add('MenuGameList', MenuGameList, true); this.scene.manager.add('ItemList', ItemList, true); + return true; } - addMenuScenes() { - 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.scene.manager.add('ItemList', ItemList, true); - } - - setData(parent, key, data) { - if (key === 'cryps') { - this.scene.add('MenuCrypList', MenuCrypList, true); - this.scene.add('MenuGameList', MenuGameList, true); - } - - if (key === 'game') { - this.cleanUp(); - this.scene.manager.add('Combat', Combat, true, data); - this.scene.sleep(); - } - } - updateData(parent, key, data) { - // if (key === 'itemList') { - // return this.renderItemList(data); - // } - - if (key === 'game' && this.scene.isActive()) { - this.cleanUp(); - this.scene.manager.add('Combat', Combat, true, data); - this.scene.sleep(); + if (key === 'game') { + if (data) return this.cleanUp(); + return this.scene.restart(); } return true; @@ -62,8 +34,6 @@ class Menu extends Phaser.Scene { // 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(); @@ -72,21 +42,14 @@ class Menu extends Phaser.Scene { } 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 - if (this.scene.get(key).cleanUp) this.scene.get(key).cleanUp(); - } - }); - } - update() { - // console.log(this.registry.get('itemList')); + this.scene.get('MenuCrypList').cleanUp(); + this.scene.get('MenuGameList').cleanUp(); + this.scene.get('ItemList').cleanUp(); + this.scene.remove(); } }