mnml/client/src/scenes/cryp.page.js
2018-12-17 23:56:16 +11:00

62 lines
2.0 KiB
JavaScript

const Phaser = require('phaser');
const { TEXT, SKILLS, POSITIONS: { STATS } } = require('./constants');
class CrypPage extends Phaser.GameObjects.Group {
constructor(scene, cryp) {
super(scene);
this.id = cryp.id;
this.scene = scene;
this.ws = scene.registry.get('ws');
const TEXT_MARGIN = STATS.textMargin();
const crypStat = (stat, i) => {
const STAT_X = STATS.x();
const STAT_Y = (i * TEXT_MARGIN) + STATS.y() + TEXT_MARGIN;
const text = scene.add.text(STAT_X, STAT_Y, `${stat.stat}: ${stat.base}`, TEXT.NORMAL);
this.add(text);
};
const knownSkill = (skill, i) => {
const SKILL_X = STATS.knownX();
const SKILL_Y = (i * TEXT_MARGIN) + STATS.y() + TEXT_MARGIN;
const text = scene.add.text(SKILL_X, SKILL_Y, skill.skill, TEXT.NORMAL)
.setInteractive();
text.on('pointerdown', () => {
this.ws.sendCrypForget(cryp.id, skill.skill);
});
this.add(text);
};
const learnable = (skill, i) => {
const SKILL_X = STATS.learnableX();
const SKILL_Y = (i * TEXT_MARGIN) + STATS.y() + TEXT_MARGIN;
const text = scene.add.text(SKILL_X, SKILL_Y, `${skill.name}\n${skill.description}`, TEXT.NORMAL)
.setInteractive();
text.on('pointerdown', () => {
this.ws.sendCrypLearn(cryp.id, skill);
});
this.add(text);
text.cryp = cryp;
};
const CRYP_STATS = [cryp.stamina, cryp.phys_dmg, cryp.spell_dmg];
this.add(scene.add.text(STATS.x(), STATS.y(), cryp.name, TEXT.HEADER));
CRYP_STATS.forEach(crypStat);
this.add(scene.add.text(STATS.knownX(), STATS.y(), 'Skills', TEXT.HEADER));
cryp.skills.forEach(knownSkill);
this.add(scene.add.text(STATS.learnableX(), STATS.y(), 'Learnable', TEXT.HEADER));
SKILLS.LEARNABLE.forEach(learnable);
}
}
module.exports = CrypPage;