Moved menu context switching out of main cryps

This commit is contained in:
Mashy 2019-01-16 17:58:15 +10:00
parent 31f48c0663
commit a9dd2e76cc
5 changed files with 43 additions and 48 deletions

View File

@ -52,21 +52,17 @@ function registerEvents(registry, events, tutorial) {
events.on('CRYP_ACTIVE', function crypActiveCb(cryp) {
const cryps = registry.get('cryps');
cryps.forEach((c) => {
if (c.id === cryp.id) {
if (c.active) return c.active = false;
return c.active = true;
}
return false;
});
for (let i = 0; i < cryps.length; i += 1) {
if (cryps[i].id === cryp.id) cryps[i].active = !cryps[i].active;
}
return setCryps(cryps);
});
const errMessages = {
select_cryps: 'Select your cryps before battle using the numbered buttons next to the cryp avatar',
complete_nodes: 'You need to complete the previously connected nodes first',
max_skills: 'Your cryp can only learn a maximum of 4 skills',
};
function errorPrompt(type) {

View File

@ -3,12 +3,7 @@ const Phaser = require('phaser');
const Header = require('./header');
const Menu = require('./menu');
const Combat = require('./combat');
const Zones = require('./zones');
const Background = require('./background');
const GameList = require('./game.list');
const StatSheet = require('./statsheet');
const SpecSheet = require('./specsheet');
function renderCryps() {
const config = {
@ -33,22 +28,6 @@ function renderCryps() {
const game = new Phaser.Game(config);
function newMainScene(key, scene, data) {
let addScene = true;
const ACTIVE_MAIN_SCENES = ['GameList', 'Zones', 'StatSheet', 'SpecSheet'];
ACTIVE_MAIN_SCENES.forEach((sKey) => {
if (game.scene.keys[sKey]) {
if (key === sKey) {
game.scene.keys[sKey].scene.restart(data);
addScene = false;
} else {
game.scene.keys[sKey].cleanUp();
}
}
});
if (addScene) game.scene.add(key, scene, true, data);
return true;
}
function changeData(parent, key, data) {
// Don't load other scenes if you're not logged in
@ -63,23 +42,6 @@ function renderCryps() {
return game.scene.add('Combat', Combat, true);
}
if (key === 'zone') {
newMainScene('Zones', Zones, data);
}
if (key === 'gameList') {
newMainScene('GameList', GameList, data);
}
if (key === 'crypStats') {
newMainScene('StatSheet', StatSheet, data);
}
if (key === 'crypSpec') {
newMainScene('SpecSheet', SpecSheet, data);
}
return true;
}

View File

@ -3,6 +3,10 @@ const Phaser = require('phaser');
const MenuCrypList = require('./menu.cryps.list');
const MenuNavigation = require('./menu.navigation');
const ItemList = require('./item.list');
const Zones = require('./zones');
const GameList = require('./game.list');
const StatSheet = require('./statsheet');
const SpecSheet = require('./specsheet');
class Menu extends Phaser.Scene {
constructor() {
@ -29,9 +33,41 @@ class Menu extends Phaser.Scene {
if (data) return this.cleanUp();
}
if (key === 'zone') {
this.newMainScene('Zones', Zones, data);
}
if (key === 'gameList') {
this.newMainScene('GameList', GameList, data);
}
if (key === 'crypStats') {
this.newMainScene('StatSheet', StatSheet, data);
}
if (key === 'crypSpec') {
this.newMainScene('SpecSheet', SpecSheet, data);
}
return true;
}
newMainScene(key, scene, data) {
let addScene = true;
const ACTIVE_MAIN_SCENES = ['GameList', 'Zones', 'StatSheet', 'SpecSheet'];
ACTIVE_MAIN_SCENES.forEach((sKey) => {
if (this.scene.manager.keys[sKey]) {
if (key === sKey) {
this.scene.manager.keys[sKey].scene.restart(data);
addScene = false;
} else {
this.scene.manager.keys[sKey].cleanUp();
}
}
});
if (addScene) this.scene.manager.add(key, scene, true, data);
}
cleanUp() {
this.registry.events.off('changedata', this.updateData, this);
this.registry.events.off('setdata', this.updateData, this);

View File

@ -10,7 +10,7 @@ const TEXT_MARGIN = 24;
const menuX = WIDTH / 10;
const menuY = HEIGHT * 0.8;
const menuWidth = WIDTH / 10;
const menuHeight = HEIGHT * 0.3;
const menuHeight = HEIGHT * 0.2;
const X_LEARN = WIDTH * 2 / 4;
const Y_SKILLS = HEIGHT * 0.5;

View File

@ -190,6 +190,7 @@ function createSocket(events) {
case 'no active zone': return sendZoneCreate();
case 'no cryps selected': return events.errorPrompt('select_cryps');
case 'node requirements not met': return events.errorPrompt('complete_nodes');
case 'cryp at max skills (4)': return events.errorPrompt('max_skills');
default: return errorToast(error);