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

View File

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

View File

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