join games in progress

This commit is contained in:
Mashy 2019-03-14 15:49:51 +10:00
parent 2eae21f12f
commit 9a5f92cf7f
5 changed files with 22 additions and 9 deletions

View File

@ -5,6 +5,7 @@ const X = MENU_MAIN.x();
const Y = MENU_MAIN.y();
const WIDTH = MENU_MAIN.width();
const HEIGHT = MENU_MAIN.height();
const NULL_UUID = '00000000-0000-0000-0000-000000000000';
class HomeRankings extends Phaser.Scene {
constructor() {
@ -20,10 +21,17 @@ class HomeRankings extends Phaser.Scene {
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
this.game.events.emit('SET_PLAYER', player);
if (player.ready) {
this.registry.set('player', player);
this.registry.get('ws').sendInstanceReady(player.instance);
} else {
this.game.events.emit('SET_PLAYER', player);
}
});
const name = player.instance === NULL_UUID ? 'Normal Mode' : `${player.instance.substring(0, 5)}`;
const disp = player.ready ? name.concat(' - in progress') : name;
this.add
.text(joinNormal.getCenter().x, joinNormal.getCenter().y, `${player.instance}`, TEXT.NORMAL)
.text(joinNormal.getCenter().x, joinNormal.getCenter().y, disp, TEXT.NORMAL)
.setOrigin(0.5, 0.5);
};

View File

@ -134,7 +134,9 @@ class ItemList extends Phaser.Scene {
}
create() {
const { vbox } = this.registry.get('player');
const player = this.registry.get('player');
if (!player) return false;
const { vbox } = player;
this.registry.events.on('changedata', this.updateData, this);
this.registry.events.on('setdata', this.updateData, this);
if (!vbox.bound) return false;

View File

@ -23,7 +23,8 @@ class MenuCrypList 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);
this.drawCryps(this.registry.get('player').cryps);
const player = this.registry.get('player');
if (player) this.drawCryps(player.cryps);
}
updateData(parent, key, data) {

View File

@ -43,8 +43,8 @@ class Menu extends Phaser.Scene {
this.registry.set('inMenu', true);
// Request the latest player state when we load the scene
const { instance } = this.registry.get('player');
this.registry.get('ws').sendPlayerState(instance);
const player = this.registry.get('player');
this.registry.get('ws').sendPlayerState(player.instance);
return true;
}

View File

@ -11,9 +11,11 @@ class MenuScore extends Phaser.Scene {
}
create() {
const { score } = this.registry.get('player');
this.add.text(X, Y, `Wins: ${score.wins}`, TEXT.HEADER);
this.add.text(X, Y + HEIGHT * 0.1, `Losses: ${score.losses}`, TEXT.HEADER);
const player = this.registry.get('player');
if (!player) return false;
this.add.text(X, Y, `Wins: ${player.score.wins}`, TEXT.HEADER);
this.add.text(X, Y + HEIGHT * 0.1, `Losses: ${player.score.losses}`, TEXT.HEADER);
return true;
}
cleanUp() {