This commit is contained in:
ntr
2019-03-19 19:57:49 +11:00
parent cd26efb42d
commit 4b848f1e02
8 changed files with 64 additions and 24 deletions
+5
View File
@@ -41,6 +41,10 @@ function registerEvents(registry, events, tutorial) {
registry.set('vbox', items);
}
function setScores(scores) {
registry.set('scores', scores);
}
function setPlayerList(list) {
registry.set('playerList', list);
registry.set('homeInstances', true);
@@ -208,6 +212,7 @@ function registerEvents(registry, events, tutorial) {
setWs,
setGameList,
setZone,
setScores,
};
}
+1
View File
@@ -27,6 +27,7 @@ class HomeRankings extends Phaser.Scene {
this.registry.get('ws').sendInstanceReady(player.instance);
} else {
this.game.events.emit('SET_PLAYER', player);
this.registry.get('ws').sendInstanceScores(player.instance);
}
});
const name = player.instance === NULL_UUID ? 'Normal Mode' : `${player.instance.substring(0, 5)}`;
+10 -1
View File
@@ -131,7 +131,7 @@ class ItemList extends Phaser.Scene {
}
updateData(parent, key, data) {
if (key === 'player') {
if (key === 'player' || key === 'scores') {
this.registry.events.off('changedata', this.updateData, this);
this.registry.events.off('setdata', this.updateData, this);
this.scene.restart();
@@ -140,6 +140,7 @@ class ItemList extends Phaser.Scene {
create() {
const player = this.registry.get('player');
const scores = this.registry.get('scores') || [];
if (!player) return false;
const { vbox } = player;
this.registry.events.on('changedata', this.updateData, this);
@@ -256,6 +257,14 @@ class ItemList extends Phaser.Scene {
} return false;
};
this.add.text(ITEM_WIDTH * 11, ITEM_HEIGHT * 1.1, `Scoreboard`, TEXT.HEADER);
scores.forEach(([name, score], i) => {
console.log(name);
const SCORE_X = ITEM_WIDTH * 11;
const SCORE_Y = ITEM_HEIGHT * 1.1 * (i + 2);
this.add.text(SCORE_X, SCORE_Y, `${name} | ${score.wins} - ${score.losses}`, TEXT.NORMAL);
});
// Add Handlers
this.input.on('dragstart', (pointer, item) => {
if (!(item instanceof Item)) return false;
+12
View File
@@ -152,6 +152,11 @@ function createSocket(events) {
send({ method: 'instance_ready', params: { instance_id: instanceId } });
}
function sendInstanceScores(instanceId) {
send({ method: 'instance_scores', params: { instance_id: instanceId } });
}
// -------------
// Incoming
// -------------
@@ -196,6 +201,11 @@ function createSocket(events) {
events.setPlayer(player);
}
function instanceScores(response) {
const [structName, scores] = response;
events.setScores(scores);
}
// -------------
// Setup
// -------------
@@ -212,6 +222,7 @@ function createSocket(events) {
account_create: accountLogin,
account_cryps: accountCryps,
account_players: accountPlayerList,
instance_scores: instanceScores,
zone_create: res => console.log(res),
zone_state: zoneState,
zone_close: res => console.log(res),
@@ -308,6 +319,7 @@ function createSocket(events) {
sendZoneClose,
sendInstanceJoin,
sendInstanceReady,
sendInstanceScores,
sendPlayerCrypsSet,
sendPlayerState,
sendVboxAccept,