stop menu wip
This commit is contained in:
parent
3cf0f5d374
commit
24060accab
@ -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;
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user