mnml/client/src/scenes/statsheet.js
2018-12-21 19:31:59 +10:00

88 lines
2.5 KiB
JavaScript

const Phaser = require('phaser');
const Passives = require('./passives');
const Stats = require('./statsheet.stats');
const Skills = require('./statsheet.skills');
const { POSITIONS: { STATS } } = require('./constants');
const addButton = require('./statsheet.button');
const menuOrig = STATS.height() * 0.5;
const menuHeight = STATS.height() * 0.1;
const menuPad = STATS.height() * 0.01;
class StatSheet extends Phaser.Scene {
constructor() {
super({ key: 'StatSheet' });
}
create(cryp) {
console.log(cryp);
this.cryp = cryp;
this.stats = new Stats(this, cryp);
this.addControls(cryp);
this.addSkills(cryp);
this.skills = true;
}
addControls(cryp) {
const menuCback = () => {
this.registry.events.off('changedata', this.updateData, this);
this.registry.set('game', null);
this.scene.switch('Menu'); // Switch back to menu
this.scene.remove('Skills');
this.scene.remove('Passives');
this.scene.remove();
};
const passiveCback = () => {
if (this.passives) return false;
this.removeSkills();
this.addPassives(cryp);
this.passives = true;
return true;
};
const skillCback = () => {
if (this.skills) return false;
this.removePassives();
this.addSkills(cryp);
this.skills = true;
return true;
};
const clearCback = () => {
this.removePassives();
this.removeSkills();
return true;
};
addButton(this, 0, menuOrig, menuCback, 'Main Menu');
addButton(this, 0, menuOrig + (menuHeight + menuPad), passiveCback, 'View Passives');
addButton(this, 0, menuOrig + (menuHeight + menuPad) * 2, skillCback, 'View Skills');
addButton(this, 0, menuOrig + (menuHeight + menuPad) * 3, clearCback, 'View Cryp');
}
addSkills(cryp) {
this.scene.add('Skills', Skills);
this.scene.run('Skills', cryp);
}
addPassives(cryp) {
this.scene.add('Passives', Passives);
this.scene.run('Passives', cryp);
}
removePassives() {
if (!this.passives) return false;
this.scene.remove('Passives');
this.passives = false;
return true;
}
removeSkills() {
if (!this.skills) return false;
this.scene.remove('Skills');
this.skills = false;
return true;
}
}
module.exports = StatSheet;