Update cryps on player update

This commit is contained in:
Mashy 2019-03-01 15:52:42 +10:00
parent a59de136ac
commit 92a249879d
3 changed files with 26 additions and 52 deletions

View File

@ -50,9 +50,7 @@ function registerEvents(registry, events, tutorial) {
registry.set('player', player); registry.set('player', player);
if (!registry.get('inMenu')) { if (!registry.get('inMenu')) {
setMenu(); setMenu();
setCryps(player.cryps);
} }
setVbox(player.vbox);
} }
function setZone(zone) { function setZone(zone) {

View File

@ -126,14 +126,15 @@ class ItemList extends Phaser.Scene {
} }
updateData(parent, key, data) { updateData(parent, key, data) {
if (key === 'vbox') { if (key === 'player') {
this.registry.events.off('changedata', this.updateData, this); this.registry.events.off('changedata', this.updateData, this);
this.registry.events.off('setdata', this.updateData, this); this.registry.events.off('setdata', this.updateData, this);
this.scene.restart(data); this.scene.restart();
} }
} }
create(vbox) { create() {
const { vbox } = this.registry.get('player');
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);
if (!vbox.bound) return false; if (!vbox.bound) return false;

View File

@ -23,24 +23,22 @@ class MenuCrypList extends Phaser.Scene {
// this.cameras.main.setViewport(CRYP_LIST.x(), CRYP_LIST.y(), CRYP_LIST.width(), CRYP_LIST.height()); // 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('changedata', this.updateData, this);
this.registry.events.on('setdata', this.updateData, this); this.registry.events.on('setdata', this.updateData, this);
this.addCrypRows(this.registry.get('cryps')); this.drawCryps(this.registry.get('player').cryps);
this.addControls();
} }
updateData(parent, key, data) { updateData(parent, key, data) {
if (key === 'cryps') { if (key === 'player') {
KEY_MAP.forEach(k => this.input.keyboard.removeListener(k)); console.log(data.cryps);
this.scene.restart(data); // KEY_MAP.forEach(k => this.input.keyboard.removeListener(k));
this.drawCryps(data.cryps);
} }
} }
addCrypRows(cryps) { drawCryps(cryps) {
if (!cryps) return true; if (!cryps) return true;
// We only display 3 cryps others can be viewed in cryp list (soon TM) if (this.crypGroup) this.crypGroup.destroy(true);
const crypDispLength = cryps.length < 3 ? cryps.length : 3; this.crypGroup = this.add.group();
const addCryp = (cryp, i) => {
for (let i = 0; i < crypDispLength; i += 1) {
const cryp = cryps[i];
const BOX_WIDTH = Math.floor(ROW_WIDTH / 5); const BOX_WIDTH = Math.floor(ROW_WIDTH / 5);
const ROW_X = i * BOX_WIDTH * 2; const ROW_X = i * BOX_WIDTH * 2;
const ROW_Y = CRYP_LIST.y(); const ROW_Y = CRYP_LIST.y();
@ -53,7 +51,6 @@ class MenuCrypList extends Phaser.Scene {
const FILL = Object.values(COLOURS)[i]; const FILL = Object.values(COLOURS)[i];
// Selection of cryps // Selection of cryps
const selectFn = () => { const selectFn = () => {
// this.game.events.emit('CRYP_ACTIVE', cryp);
this.registry.set('crypStats', cryp); this.registry.set('crypStats', cryp);
}; };
@ -63,22 +60,20 @@ class MenuCrypList extends Phaser.Scene {
.setInteractive() .setInteractive()
.setOrigin(0) .setOrigin(0)
.on('pointerdown', selectFn); .on('pointerdown', selectFn);
crypInteract.itemSelect = () => { crypInteract.itemSelect = () => {
crypInteract.setFillStyle(COLOURS.SELECT); crypInteract.setFillStyle(COLOURS.SELECT);
}; };
crypInteract.itemDeselect = () => { crypInteract.itemDeselect = () => {
crypInteract.setFillStyle(FILL, ACTIVE_FILL); crypInteract.setFillStyle(FILL, ACTIVE_FILL);
}; };
crypInteract.cryp = cryp; crypInteract.cryp = cryp;
this.add.image(
const crypImage = this.add.image(
crypInteract.getCenter().x, crypInteract.getCenter().x,
crypInteract.getCenter().y, crypInteract.getCenter().y,
'aztec', 'aztec',
genAvatar(cryp.name) genAvatar(cryp.name)
); );
// Cryp information box (names + skills) // Cryp information box (names + skills)
const crypInfo = this.add const crypInfo = this.add
.rectangle(ROW_X, ROW_Y, BOX_WIDTH * 2, ROW_HEIGHT * 2.5, FILL, ACTIVE_FILL) .rectangle(ROW_X, ROW_Y, BOX_WIDTH * 2, ROW_HEIGHT * 2.5, FILL, ACTIVE_FILL)
@ -86,14 +81,17 @@ class MenuCrypList extends Phaser.Scene {
.setInteractive() .setInteractive()
.on('pointerdown', selectFn); .on('pointerdown', selectFn);
this.add.text(crypInfo.getCenter().x, crypInfo.y + TEXT_MARGIN, cryp.name, TEXT.HEADER) const crypInfoText = this.add.text(crypInfo.getCenter().x, crypInfo.y + TEXT_MARGIN, cryp.name, TEXT.HEADER)
.setOrigin(0.5, 0.5); .setOrigin(0.5, 0.5);
this.crypGroup.addMultiple([crypInteract, crypImage, crypInfo, crypInfoText])
const crypGems = (stat, j) => { const crypGems = (stat, j) => {
this.add
// Placeholder for when gems are implemented // Placeholder for when gems are implemented
const gemText = this.add
.text(crypInfo.getCenter().x, crypInfo.y + TEXT_MARGIN * (2 + j), `${stat}: 0`, TEXT.NORMAL) .text(crypInfo.getCenter().x, crypInfo.y + TEXT_MARGIN * (2 + j), `${stat}: 0`, TEXT.NORMAL)
.setOrigin(0.5, 0.5); .setOrigin(0.5, 0.5);
this.crypGroup.add(gemText);
}; };
const CRYP_GEMS = [ const CRYP_GEMS = [
@ -104,39 +102,16 @@ class MenuCrypList extends Phaser.Scene {
CRYP_GEMS.forEach(crypGems); CRYP_GEMS.forEach(crypGems);
const crypSkill = (stat, j) => { const crypSkill = (stat, j) => {
this.add const skillText = this.add
.text(crypInfo.getCenter().x, crypInfo.y + TEXT_MARGIN * (6 + j), `${stat.skill}`, TEXT.NORMAL) .text(crypInfo.getCenter().x, crypInfo.y + TEXT_MARGIN * (6 + j), `${stat.skill}`, TEXT.NORMAL)
.setOrigin(0.5, 0.5); .setOrigin(0.5, 0.5);
this.crypGroup.add(skillText);
}; };
cryp.skills.forEach(crypSkill); cryp.skills.forEach(crypSkill);
} };
return true; cryps.forEach(addCryp);
}
addControls() { return true;
// Add Spawn Cryp Option
const spawn = this.add
.rectangle(ROW_WIDTH * 0.05, ROW_HEIGHT * 4, ROW_WIDTH * 0.2, ROW_HEIGHT * 0.5, 0x888888)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
this.game.events.emit('CRYP_SPAWN');
});
this.add
.text(spawn.getCenter().x, spawn.getCenter().y, '+', 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);
} }
cleanUp() { cleanUp() {