Return to home page

This commit is contained in:
Mashy 2019-02-25 13:43:59 +10:00
parent c6329de8ab
commit 0008b8e398
7 changed files with 35 additions and 106 deletions

View File

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

View File

@ -48,6 +48,7 @@ function renderCryps() {
}
if (key === 'menu') {
if (!data || game.registry.get('inMenu')) return false;
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_WIDTH = CRYP_LIST.width();
const TEXT_MARGIN = 24;
const KEY_MAP = [
'keydown-ONE',
'keydown-TWO',
@ -24,7 +22,7 @@ class HomeCrypList extends Phaser.Scene {
updateData(parent, key, data) {
if (key === 'cryps') {
if (key === 'crypList') {
KEY_MAP.forEach(k => this.input.keyboard.removeListener(k));
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.registry.events.on('changedata', 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;
@ -65,7 +63,6 @@ class HomeCrypList extends Phaser.Scene {
this.activeCryps.push(crypInteract);
crypInteract.setAlpha(1);
}
console.log(this.activeCryps);
});
crypInteract.itemSelect = () => {
@ -124,19 +121,7 @@ class HomeCrypList extends Phaser.Scene {
.text(joinInstance.getCenter().x, joinInstance.getCenter().y, 'Join Instance', TEXT.HEADER)
.setOrigin(0.5, 0.5);
// 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);
return this;
}
cleanUp() {

View File

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

View File

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

View File

@ -16,94 +16,28 @@ class MenuNavigation extends Phaser.Scene {
}
create() {
const ws = this.registry.get('ws');
// const ws = this.registry.get('ws');
this.cameras.main.setViewport(X, Y, WIDTH, HEIGHT);
const play = 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
const ready = this.add
.rectangle(BTN_WIDTH * 3, 0, BTN_WIDTH, BTN_HEIGHT, 0x222222)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => this.scene.restart());
.setOrigin(0);
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);
}
ready.on('pointerdown', () => {
// Put player in game
});
addPvpModes(ws) {
const hostPvp = this.add
.rectangle(BTN_WIDTH, 0, BTN_WIDTH, BTN_HEIGHT, 0x440000)
const leave = this.add
.rectangle(BTN_WIDTH * 3, BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT, 0x440000)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
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);
});
.on('pointerdown', () => this.registry.set('home', true));
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);
}

View File

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