diff --git a/client/src/events.js b/client/src/events.js index 39390c9c..01758958 100644 --- a/client/src/events.js +++ b/client/src/events.js @@ -20,6 +20,7 @@ function registerEvents(registry, events, tutorial) { function setAccount(account) { registry.set('account', account); + registry.set('menu', true); events.emit('ACCOUNT', account); } diff --git a/client/src/scenes/combat.js b/client/src/scenes/combat.js index 47b091cb..32eecbfb 100644 --- a/client/src/scenes/combat.js +++ b/client/src/scenes/combat.js @@ -112,8 +112,9 @@ class Combat extends Phaser.Scene { 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.registry.set('menu', true); + this.registry.set('game', null); this.scene.get('CombatLog').cleanUp(); this.scene.get('CombatCryps').cleanUp(); diff --git a/client/src/scenes/cryps.js b/client/src/scenes/cryps.js index d0c581ed..8dd86cf0 100644 --- a/client/src/scenes/cryps.js +++ b/client/src/scenes/cryps.js @@ -21,7 +21,6 @@ function renderCryps() { }, scene: [ Header, - Menu, ], }; @@ -29,11 +28,13 @@ function renderCryps() { 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; + if (key === 'menu') { + if (data) return game.scene.add('Menu', Menu, true); + } + + if (key === 'game') { + if (!data || game.registry.get('inGame')) return false; return game.scene.add('Combat', Combat, true); } } diff --git a/client/src/scenes/menu.js b/client/src/scenes/menu.js index 9ef13a55..d8690e4c 100644 --- a/client/src/scenes/menu.js +++ b/client/src/scenes/menu.js @@ -34,14 +34,14 @@ class Menu extends Phaser.Scene { // Scene switch to statsheet called by MenuCrypRows scene displaySkills(cryp) { if (cryp) { - this.scene.add('StatSheet', StatSheet); - this.scene.run('StatSheet', cryp); - this.scene.sleep(); + this.scene.manager.add('StatSheet', StatSheet, true, cryp); + this.cleanUp(); } return true; } cleanUp() { + console.log('rip menu'); this.registry.events.off('changedata', this.updateData, this); this.registry.events.off('setdata', this.updateData, this); diff --git a/client/src/scenes/passives.js b/client/src/scenes/passives.js index 394fa916..39002977 100644 --- a/client/src/scenes/passives.js +++ b/client/src/scenes/passives.js @@ -140,6 +140,13 @@ class PhaserPassives extends Phaser.Scene { update(delta) { this.controls.update(delta); } + + cleanUp() { + this.registry.events.off('changedata', this.updateData, this); + this.registry.events.off('setdata', this.updateData, this); + this.scene.remove(); + + } } module.exports = PhaserPassives; diff --git a/client/src/scenes/statsheet.js b/client/src/scenes/statsheet.js index 389d51b4..b809697e 100644 --- a/client/src/scenes/statsheet.js +++ b/client/src/scenes/statsheet.js @@ -1,9 +1,10 @@ const Phaser = require('phaser'); +const { POSITIONS: { STATS } } = require('./constants'); + const Passives = require('./passives'); const Stats = require('./statsheet.stats'); const Skills = require('./statsheet.skills'); -const { POSITIONS: { STATS } } = require('./constants'); const addButton = require('./statsheet.button'); const menuOrig = STATS.height() * 0.5; @@ -16,22 +17,26 @@ class StatSheet extends Phaser.Scene { } create(cryp) { - console.log(cryp); this.cryp = cryp; this.stats = new Stats(this, cryp); this.addControls(cryp); this.addSkills(cryp); this.skills = true; + this.registry.events.on('changedata', this.updateData, this); + this.registry.events.on('setdata', this.updateData, this); } + updateData(parent, key, data) { + if (key === 'menu') { + if (data) return this.cleanUp(); + } + return true; + } + + addControls(cryp) { const menuCback = () => { - this.registry.events.off('changedata', this.updateData, this); - this.registry.set('game', null); - this.scene.switch('Menu'); // Switch back to menu - this.scene.remove('Skills'); - this.scene.remove('Passives'); - this.scene.remove(); + this.registry.set('menu', true); }; const passiveCback = () => { if (this.passives) return false; @@ -60,28 +65,34 @@ class StatSheet extends Phaser.Scene { } addSkills(cryp) { - this.scene.add('Skills', Skills); - this.scene.run('Skills', cryp); + this.scene.manager.add('Skills', Skills, true, cryp); } addPassives(cryp) { - this.scene.add('Passives', Passives); - this.scene.run('Passives', cryp); + this.scene.manager.add('Passives', Skills, true, cryp); } removePassives() { if (!this.passives) return false; - this.scene.remove('Passives'); + this.scene.get('Passives').cleanUp(); this.passives = false; return true; } removeSkills() { if (!this.skills) return false; - this.scene.remove('Skills'); + this.scene.get('Skills').cleanUp(); this.skills = false; return true; } + + cleanUp() { + this.registry.events.off('changedata', this.updateData, this); + this.registry.events.off('setdata', this.updateData, this); + this.removePassives(); + this.removeSkills(); + this.scene.remove(); + } } module.exports = StatSheet; diff --git a/client/src/scenes/statsheet.skills.js b/client/src/scenes/statsheet.skills.js index 752dbaab..ffd29aab 100644 --- a/client/src/scenes/statsheet.skills.js +++ b/client/src/scenes/statsheet.skills.js @@ -24,7 +24,6 @@ class Skills extends Phaser.Scene { this.cryp = cryp; this.forget = false; // Destroy the old registry event if it exists - this.registry.events.off('changedata', this.updateData, this); this.registry.events.on('changedata', this.updateData, this); this.add.text(X_ORIG_KNOWN, Y_ORIG, 'Skills', TEXT.HEADER); this.addKnownSkills(cryp); @@ -96,6 +95,11 @@ class Skills extends Phaser.Scene { this.addKnownSkills(cryp); } } + + cleanUp() { + this.registry.events.off('changedata', this.updateData, this); + this.scene.remove(); + } } module.exports = Skills;