mnml/client/src/scenes/cryp.page.js

51 lines
1.4 KiB
JavaScript

const Phaser = require('phaser');
const { TEXT, SKILLS } = require('./constants');
const ROW_WIDTH = 400;
const ROW_HEIGHT = 200;
const ROW_FILL = 0x888888;
const TOP_MARGIN = 50;
const ROW_MARGIN = 50;
const TEXT_MARGIN = 24;
const xPos = i => 0;
const yPos = i => (i * ROW_HEIGHT + ROW_MARGIN) + TOP_MARGIN;
class CrypPage extends Phaser.GameObjects.Group {
constructor(scene, cryp) {
super(scene);
this.id = cryp.id;
this.scene = scene;
this.ws = scene.registry.get('ws');
this.add(scene.add.text(500, 500, cryp.name, TEXT.HEADER));
const knownSkill = (skill, i) => {
const text = scene.add.text(500, 500 + (TEXT_MARGIN * (i + 1)), skill.skill, TEXT.NORMAL)
.setInteractive();
text.on('pointerdown', () => {
this.ws.sendCrypForget(cryp.id, skill.skill);
});
this.add(text);
};
const learnable = (skill, i) => {
const text = scene.add.text(600, 0 + (TEXT_MARGIN * (i + 1)), skill, TEXT.NORMAL)
.setInteractive();
text.on('pointerdown', () => {
this.ws.sendCrypLearn(cryp.id, skill);
});
this.add(text);
text.cryp = cryp;
};
cryp.skills.forEach(knownSkill);
SKILLS.LEARNABLE.forEach(learnable);
}
}
module.exports = CrypPage;