Merge branch 'master' of ssh://cryps.gg:40022/~/cryps

This commit is contained in:
ntr 2019-02-25 15:28:28 +11:00
commit 7ab27d51d2
7 changed files with 35 additions and 106 deletions

View File

@ -6,6 +6,11 @@ function registerEvents(registry, events, tutorial) {
tutorial('homepage'); tutorial('homepage');
} }
function setCrypList(cryps) {
registry.set('crypList', cryps);
}
function setWs(ws) { function setWs(ws) {
registry.set('ws', ws); registry.set('ws', ws);
} }
@ -32,13 +37,16 @@ function registerEvents(registry, events, tutorial) {
registry.set('menu', true); registry.set('menu', true);
} }
function setVbox(items) { function setVbox(items) {
registry.set('vbox', items); registry.set('vbox', items);
} }
function setInstance(instance) { function setPlayer(player) {
registry.set('instance', instance); if (!registry.get('inMenu')) {
setMenu();
setCryps(player.cryps);
}
setVbox(player.vbox);
} }
function setZone(zone) { function setZone(zone) {
@ -185,9 +193,10 @@ function registerEvents(registry, events, tutorial) {
setAccount, setAccount,
setActiveSkill, setActiveSkill,
setCryps, setCryps,
setCrypList,
setGame, setGame,
setInstance,
setMenu, setMenu,
setPlayer,
setVbox, setVbox,
setWs, setWs,
setGameList, setGameList,

View File

@ -48,6 +48,7 @@ function renderCryps() {
} }
if (key === 'menu') { if (key === 'menu') {
if (!data || game.registry.get('inMenu')) return false;
if (data) return game.scene.add('Menu', Menu, true); if (data) return game.scene.add('Menu', Menu, true);
} }

View File

@ -7,8 +7,6 @@ const genAvatar = require('./avatar');
const ROW_HEIGHT = CRYP_LIST.height() * 0.2; const ROW_HEIGHT = CRYP_LIST.height() * 0.2;
const ROW_WIDTH = CRYP_LIST.width(); const ROW_WIDTH = CRYP_LIST.width();
const TEXT_MARGIN = 24;
const KEY_MAP = [ const KEY_MAP = [
'keydown-ONE', 'keydown-ONE',
'keydown-TWO', 'keydown-TWO',
@ -24,7 +22,7 @@ class HomeCrypList extends Phaser.Scene {
updateData(parent, key, data) { updateData(parent, key, data) {
if (key === 'cryps') { if (key === 'crypList') {
KEY_MAP.forEach(k => this.input.keyboard.removeListener(k)); KEY_MAP.forEach(k => this.input.keyboard.removeListener(k));
this.scene.restart(); this.scene.restart();
} }
@ -34,7 +32,7 @@ class HomeCrypList extends Phaser.Scene {
// this.cameras.main.setViewport(CRYP_LIST.x(), CRYP_LIST.y(), CRYP_LIST.width(), CRYP_LIST.height()); // this.cameras.main.setViewport(CRYP_LIST.x(), CRYP_LIST.y(), CRYP_LIST.width(), CRYP_LIST.height());
this.registry.events.on('changedata', this.updateData, this); this.registry.events.on('changedata', this.updateData, this);
this.registry.events.on('setdata', this.updateData, this); this.registry.events.on('setdata', this.updateData, this);
const cryps = this.registry.get('cryps'); const cryps = this.registry.get('crypList');
if (!cryps) return true; if (!cryps) return true;
@ -65,7 +63,6 @@ class HomeCrypList extends Phaser.Scene {
this.activeCryps.push(crypInteract); this.activeCryps.push(crypInteract);
crypInteract.setAlpha(1); crypInteract.setAlpha(1);
} }
console.log(this.activeCryps);
}); });
crypInteract.itemSelect = () => { crypInteract.itemSelect = () => {
@ -124,19 +121,7 @@ class HomeCrypList extends Phaser.Scene {
.text(joinInstance.getCenter().x, joinInstance.getCenter().y, 'Join Instance', TEXT.HEADER) .text(joinInstance.getCenter().x, joinInstance.getCenter().y, 'Join Instance', TEXT.HEADER)
.setOrigin(0.5, 0.5); .setOrigin(0.5, 0.5);
return this;
// Dialog to view all cryps
// const crypList = this.add
// .rectangle(ROW_WIDTH * 0.55, ROW_HEIGHT * 3.5, ROW_WIDTH * 0.4, ROW_HEIGHT, 0xff9215)
// .setInteractive()
// .setOrigin(0)
// .on('pointerdown', () => {
// // this.game.events.emit('CRYP_LIST');
// // Placeholder will give a full list of all cryps in the center
// });
// this.add
// .text(crypList.getCenter().x, crypList.getCenter().y, 'Cryp List (soon)', TEXT.NORMAL)
// .setOrigin(0.5, 0.5);
} }
cleanUp() { cleanUp() {

View File

@ -18,13 +18,13 @@ class Home extends Phaser.Scene {
this.registry.events.on('changedata', this.updateData, this); this.registry.events.on('changedata', this.updateData, this);
this.registry.events.on('setdata', this.updateData, this); this.registry.events.on('setdata', this.updateData, this);
this.scene.manager.add('HomeCryps', HomeCryps, true); this.scene.manager.add('HomeCryps', HomeCryps, true);
return true; return true;
} }
updateData(parent, key, data) { updateData(parent, key, data) {
if (!data) return false; if (!data) return false;
if (key === 'menu') { if (key === 'menu') {
console.log(this.scene.manager);
this.cleanUp(); this.cleanUp();
} return true; } return true;
} }

View File

@ -38,7 +38,7 @@ class Menu extends Phaser.Scene {
this.scene.manager.add('MenuCrypList', MenuCrypList, true); this.scene.manager.add('MenuCrypList', MenuCrypList, true);
this.scene.manager.add('MenuNavigation', MenuNavigation, true); this.scene.manager.add('MenuNavigation', MenuNavigation, true);
this.scene.manager.add('ItemList', ItemList, true); this.scene.manager.add('ItemList', ItemList, true);
this.registry.set('inMenu', true);
return true; return true;
} }
@ -47,6 +47,7 @@ class Menu extends Phaser.Scene {
// Controls which scene shows in the main top right section // Controls which scene shows in the main top right section
switch (key) { switch (key) {
case 'game': return this.cleanUp(); case 'game': return this.cleanUp();
case 'home': return this.cleanUp();
case 'zone': return this.newMainScene('Zones', Zones, data); case 'zone': return this.newMainScene('Zones', Zones, data);
case 'gameList': return this.newMainScene('GameList', GameList, data); case 'gameList': return this.newMainScene('GameList', GameList, data);
case 'crypStats': return this.newMainScene('StatSheet', StatSheet, data); case 'crypStats': return this.newMainScene('StatSheet', StatSheet, data);
@ -74,6 +75,7 @@ class Menu extends Phaser.Scene {
} }
cleanUp() { cleanUp() {
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);
// Delete scenes which could be showing before switching to battle scene // Delete scenes which could be showing before switching to battle scene
@ -82,6 +84,7 @@ class Menu extends Phaser.Scene {
}; };
FIXED_MENU_SCENES.forEach(removeScenes); FIXED_MENU_SCENES.forEach(removeScenes);
MAIN_MENU_SCENES.forEach(removeScenes); MAIN_MENU_SCENES.forEach(removeScenes);
this.registry.set('inMenu', false);
this.scene.remove(); this.scene.remove();
} }

View File

@ -16,94 +16,28 @@ class MenuNavigation extends Phaser.Scene {
} }
create() { create() {
const ws = this.registry.get('ws'); // const ws = this.registry.get('ws');
this.cameras.main.setViewport(X, Y, WIDTH, HEIGHT); this.cameras.main.setViewport(X, Y, WIDTH, HEIGHT);
const play = this.add const ready = this.add
.rectangle(BTN_WIDTH * 3, BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT, 0x222222)
.setInteractive()
.setOrigin(0);
const playText = this.add
.text(play.getCenter().x, play.getCenter().y, 'Play Cryps', TEXT.HEADER)
.setOrigin(0.5, 0.5);
play.on('pointerdown', () => {
this.selectMode(ws);
play.destroy();
playText.destroy();
});
}
selectMode(ws) {
this.buttons = this.add.group();
const pvp = this.add
.rectangle(BTN_WIDTH * 2, 0, BTN_WIDTH, BTN_HEIGHT, 0x440000)
.setInteractive()
.setOrigin(0);
const pvpText = this.add
.text(pvp.getCenter().x, pvp.getCenter().y, 'Play PVP', TEXT.HEADER)
.setOrigin(0.5, 0.5);
const pve = this.add
.rectangle(BTN_WIDTH * 2, BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT, 0x004400)
.setInteractive()
.setOrigin(0);
const pveText = this.add
.text(pve.getCenter().x, pve.getCenter().y, 'Play PVE', TEXT.HEADER)
.setOrigin(0.5, 0.5);
pve.on('pointerdown', () => {
pve.destroy();
pveText.destroy();
pvp.destroy();
pvpText.destroy();
});
pvp.on('pointerdown', () => {
this.addPvpModes(ws);
pve.destroy();
pveText.destroy();
pvp.destroy();
pvpText.destroy();
});
const cancel = this.add
.rectangle(BTN_WIDTH * 3, 0, BTN_WIDTH, BTN_HEIGHT, 0x222222) .rectangle(BTN_WIDTH * 3, 0, BTN_WIDTH, BTN_HEIGHT, 0x222222)
.setInteractive() .setInteractive()
.setOrigin(0) .setOrigin(0);
.on('pointerdown', () => this.scene.restart());
this.add this.add
.text(cancel.getCenter().x, cancel.getCenter().y, 'Cancel', TEXT.HEADER) .text(ready.getCenter().x, ready.getCenter().y, 'Ready', TEXT.HEADER)
.setOrigin(0.5, 0.5); .setOrigin(0.5, 0.5);
} ready.on('pointerdown', () => {
// Put player in game
});
addPvpModes(ws) { const leave = this.add
const hostPvp = this.add .rectangle(BTN_WIDTH * 3, BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT, 0x440000)
.rectangle(BTN_WIDTH, 0, BTN_WIDTH, BTN_HEIGHT, 0x440000)
.setInteractive() .setInteractive()
.setOrigin(0) .setOrigin(0)
.on('pointerdown', () => { .on('pointerdown', () => this.registry.set('home', true));
const team = this.registry.get('cryps').filter(c => c.active).map(c => c.id);
ws.sendGamePvp(team);
});
this.add
.text(hostPvp.getCenter().x, hostPvp.getCenter().y, 'Host PVP game', TEXT.HEADER)
.setOrigin(0.5, 0.5);
}
addPveModes(ws) {
const quickPve = this.add
.rectangle(BTN_WIDTH, BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT, 0x222222)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
const team = this.registry.get('cryps').filter(c => c.active).map(c => c.id);
ws.sendGamePve(team);
});
this.add this.add
.text(quickPve.getCenter().x, quickPve.getCenter().y, 'Quick Game', TEXT.HEADER) .text(leave.getCenter().x, leave.getCenter().y, 'Leave', TEXT.HEADER)
.setOrigin(0.5, 0.5); .setOrigin(0.5, 0.5);
} }

View File

@ -159,7 +159,7 @@ function createSocket(events) {
function accountCryps(response) { function accountCryps(response) {
const [structName, cryps] = response; const [structName, cryps] = response;
events.setCryps(cryps); events.setCrypList(cryps);
} }
function gameState(response) { function gameState(response) {
@ -182,10 +182,7 @@ function createSocket(events) {
function playerState(response) { function playerState(response) {
const [structName, player] = response; const [structName, player] = response;
events.setMenu(); events.setPlayer(player);
events.setCryps(player.cryps);
events.setInstance(player.instance);
events.setVbox(player.vbox);
} }
// ------------- // -------------