diff --git a/client/src/events.js b/client/src/events.js index 49a87225..a7a921bf 100644 --- a/client/src/events.js +++ b/client/src/events.js @@ -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) { diff --git a/client/src/scenes/cryps.js b/client/src/scenes/cryps.js index 132f16f3..350c2753 100644 --- a/client/src/scenes/cryps.js +++ b/client/src/scenes/cryps.js @@ -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; } diff --git a/client/src/scenes/menu.js b/client/src/scenes/menu.js index 2456f98d..95e25aa2 100644 --- a/client/src/scenes/menu.js +++ b/client/src/scenes/menu.js @@ -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); diff --git a/client/src/scenes/specsheet.js b/client/src/scenes/specsheet.js index afc00da0..e8b09162 100644 --- a/client/src/scenes/specsheet.js +++ b/client/src/scenes/specsheet.js @@ -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; diff --git a/client/src/socket.js b/client/src/socket.js index 3252e48c..4340b7f7 100644 --- a/client/src/socket.js +++ b/client/src/socket.js @@ -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);