Add instances from player list

This commit is contained in:
Mashy 2019-02-28 17:58:23 +10:00
parent 7589ae84d4
commit 8c89bd6841
3 changed files with 33 additions and 16 deletions

View File

@ -41,6 +41,10 @@ function registerEvents(registry, events, tutorial) {
registry.set('vbox', items);
}
function setPlayerList(list) {
registry.set('playerList', list);
}
function setPlayer(player) {
registry.set('player', player);
if (!registry.get('inMenu')) {
@ -198,6 +202,7 @@ function registerEvents(registry, events, tutorial) {
setGame,
setMenu,
setPlayer,
setPlayerList,
setVbox,
setWs,
setGameList,

View File

@ -7,7 +7,7 @@ const genAvatar = require('./avatar');
const ROW_HEIGHT = CRYP_LIST.height() * 0.2;
const ROW_WIDTH = CRYP_LIST.width();
const menuY = CRYP_LIST.height() * 1.6;
const menuY = CRYP_LIST.height();
const KEY_MAP = [
'keydown-ONE',
@ -35,6 +35,7 @@ class HomeCrypList extends Phaser.Scene {
this.registry.events.on('changedata', this.updateData, this);
this.registry.events.on('setdata', this.updateData, this);
const cryps = this.registry.get('crypList');
const playerList = this.registry.get('playerList');
if (!cryps) return true;
@ -97,21 +98,26 @@ class HomeCrypList extends Phaser.Scene {
.text(spawn.getCenter().x, spawn.getCenter().y, '+', TEXT.HEADER)
.setOrigin(0.5, 0.5);
const joinNormal = this.add
.rectangle(ROW_WIDTH * 0.3, menuY, ROW_WIDTH * 0.4, ROW_HEIGHT * 0.5, 0x888888)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
const playerCryps = [];
this.activeCryps.forEach(obj => playerCryps.push(obj.cryp.id));
ws.sendPlayerCrypsSet(NULL_UUID, playerCryps);
});
this.add
.text(joinNormal.getCenter().x, joinNormal.getCenter().y, 'Join Normal', TEXT.HEADER)
.setOrigin(0.5, 0.5);
const addInstance = (player, i) => {
const joinNormal = this.add
.rectangle(ROW_WIDTH * 0.1, menuY + ROW_HEIGHT * 0.75 * (i + 1), ROW_WIDTH, ROW_HEIGHT * 0.5, 0x888888)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
const playerCryps = [];
this.activeCryps.forEach(obj => playerCryps.push(obj.cryp.id));
ws.sendPlayerCrypsSet(player.instance, playerCryps);
});
this.add
.text(joinNormal.getCenter().x, joinNormal.getCenter().y, `${player.instance}`, TEXT.NORMAL)
.setOrigin(0.5, 0.5);
};
const joinInstance = this.add
.rectangle(ROW_WIDTH * 0.8, menuY, ROW_WIDTH * 0.4, ROW_HEIGHT * 0.5, 0x888888)
playerList.forEach(addInstance);
const newInstance = this.add
.rectangle(ROW_WIDTH * 0.4, menuY, ROW_WIDTH * 0.6, ROW_HEIGHT * 0.5, 0x888888)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
@ -120,7 +126,7 @@ class HomeCrypList extends Phaser.Scene {
ws.sendInstanceJoin(playerCryps);
});
this.add
.text(joinInstance.getCenter().x, joinInstance.getCenter().y, 'Join Instance', TEXT.HEADER)
.text(newInstance.getCenter().x, newInstance.getCenter().y, 'New Instance', TEXT.HEADER)
.setOrigin(0.5, 0.5);
return this;

View File

@ -160,6 +160,11 @@ function createSocket(events) {
sendAccountPlayers();
}
function accountPlayerList(res) {
const [struct, playerList] = res;
events.setPlayerList(playerList);
}
function accountCryps(response) {
const [structName, cryps] = response;
events.setCrypList(cryps);
@ -203,6 +208,7 @@ function createSocket(events) {
account_login: accountLogin,
account_create: accountLogin,
account_cryps: accountCryps,
account_players: accountPlayerList,
zone_create: res => console.log(res),
zone_state: zoneState,
zone_close: res => console.log(res),