stop menu wip
This commit is contained in:
parent
3cf0f5d374
commit
24060accab
@ -34,12 +34,14 @@ class Combat extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
|
console.log('creating game');
|
||||||
this.registry.events.off('changedata', this.updateData);
|
this.registry.events.off('changedata', this.updateData);
|
||||||
this.registry.events.on('changedata', this.updateData, this);
|
this.registry.events.on('changedata', this.updateData, this);
|
||||||
this.input.keyboard.on('keydown_BACKSPACE', () => {
|
this.input.keyboard.on('keydown_BACKSPACE', () => {
|
||||||
this.endGame();
|
this.cleanUp();
|
||||||
}, 0, this);
|
}, 0, this);
|
||||||
this.registry.set('gamePhase', false);
|
this.registry.set('gamePhase', false);
|
||||||
|
this.registry.set('inGame', true);
|
||||||
this.registry.set('gameAnimating', false);
|
this.registry.set('gameAnimating', false);
|
||||||
this.account = this.registry.get('account');
|
this.account = this.registry.get('account');
|
||||||
this.fetchGame = throttle(() => {
|
this.fetchGame = throttle(() => {
|
||||||
@ -50,6 +52,7 @@ class Combat extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,17 +67,6 @@ class Combat extends Phaser.Scene {
|
|||||||
return true;
|
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() {
|
update() {
|
||||||
this.fetchGame();
|
this.fetchGame();
|
||||||
return true;
|
return true;
|
||||||
@ -115,6 +107,22 @@ class Combat extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
return true;
|
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;
|
module.exports = Combat;
|
||||||
|
|||||||
@ -2,6 +2,7 @@ const Phaser = require('phaser');
|
|||||||
|
|
||||||
const Header = require('./header');
|
const Header = require('./header');
|
||||||
const Menu = require('./menu');
|
const Menu = require('./menu');
|
||||||
|
const Combat = require('./combat');
|
||||||
|
|
||||||
function renderCryps() {
|
function renderCryps() {
|
||||||
const config = {
|
const config = {
|
||||||
@ -25,7 +26,20 @@ function renderCryps() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const game = new Phaser.Game(config);
|
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() {
|
function resize() {
|
||||||
const canvas = document.querySelector('canvas');
|
const canvas = document.querySelector('canvas');
|
||||||
|
|||||||
@ -3,7 +3,6 @@ const Phaser = require('phaser');
|
|||||||
const MenuCrypList = require('./menu.cryps.list');
|
const MenuCrypList = require('./menu.cryps.list');
|
||||||
const MenuGameList = require('./menu.game.list');
|
const MenuGameList = require('./menu.game.list');
|
||||||
|
|
||||||
const Combat = require('./combat');
|
|
||||||
const ItemList = require('./item.list');
|
const ItemList = require('./item.list');
|
||||||
const StatSheet = require('./statsheet');
|
const StatSheet = require('./statsheet');
|
||||||
|
|
||||||
@ -14,46 +13,19 @@ class Menu extends Phaser.Scene {
|
|||||||
|
|
||||||
create() {
|
create() {
|
||||||
this.registry.events.on('changedata', this.updateData, this);
|
this.registry.events.on('changedata', this.updateData, this);
|
||||||
this.registry.events.on('setdata', this.setData, this);
|
this.registry.events.on('setdata', this.updateData, this);
|
||||||
this.sys.events.on('wake', () => {
|
|
||||||
this.addMenuScenes();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
this.scene.manager.add('MenuCrypList', MenuCrypList, true);
|
||||||
|
this.scene.manager.add('MenuGameList', MenuGameList, true);
|
||||||
this.scene.manager.add('ItemList', ItemList, true);
|
this.scene.manager.add('ItemList', ItemList, true);
|
||||||
|
|
||||||
return 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) {
|
updateData(parent, key, data) {
|
||||||
// if (key === 'itemList') {
|
if (key === 'game') {
|
||||||
// return this.renderItemList(data);
|
if (data) return this.cleanUp();
|
||||||
// }
|
return this.scene.restart();
|
||||||
|
|
||||||
if (key === 'game' && this.scene.isActive()) {
|
|
||||||
this.cleanUp();
|
|
||||||
this.scene.manager.add('Combat', Combat, true, data);
|
|
||||||
this.scene.sleep();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -62,8 +34,6 @@ class Menu extends Phaser.Scene {
|
|||||||
// Scene switch to statsheet called by MenuCrypRows scene
|
// Scene switch to statsheet called by MenuCrypRows scene
|
||||||
displaySkills(cryp) {
|
displaySkills(cryp) {
|
||||||
if (cryp) {
|
if (cryp) {
|
||||||
this.cleanUp();
|
|
||||||
|
|
||||||
this.scene.add('StatSheet', StatSheet);
|
this.scene.add('StatSheet', StatSheet);
|
||||||
this.scene.run('StatSheet', cryp);
|
this.scene.run('StatSheet', cryp);
|
||||||
this.scene.sleep();
|
this.scene.sleep();
|
||||||
@ -72,21 +42,14 @@ class Menu extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanUp() {
|
cleanUp() {
|
||||||
// Remove all the scenes except header and this scene (menu)
|
|
||||||
this.registry.events.off('changedata', this.updateData, this);
|
this.registry.events.off('changedata', this.updateData, this);
|
||||||
this.registry.events.off('setdata', 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() {
|
this.scene.get('MenuCrypList').cleanUp();
|
||||||
// console.log(this.registry.get('itemList'));
|
this.scene.get('MenuGameList').cleanUp();
|
||||||
|
this.scene.get('ItemList').cleanUp();
|
||||||
|
|
||||||
|
this.scene.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user