fixed statsheet

This commit is contained in:
Mashy
2018-12-23 23:48:36 +10:00
parent 24060accab
commit b36559ae9f
7 changed files with 49 additions and 24 deletions
+25 -14
View File
@@ -1,9 +1,10 @@
const Phaser = require('phaser');
const { POSITIONS: { STATS } } = require('./constants');
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;
@@ -16,22 +17,26 @@ class StatSheet extends Phaser.Scene {
}
create(cryp) {
console.log(cryp);
this.cryp = cryp;
this.stats = new Stats(this, cryp);
this.addControls(cryp);
this.addSkills(cryp);
this.skills = true;
this.registry.events.on('changedata', this.updateData, this);
this.registry.events.on('setdata', this.updateData, this);
}
updateData(parent, key, data) {
if (key === 'menu') {
if (data) return this.cleanUp();
}
return 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();
this.registry.set('menu', true);
};
const passiveCback = () => {
if (this.passives) return false;
@@ -60,28 +65,34 @@ class StatSheet extends Phaser.Scene {
}
addSkills(cryp) {
this.scene.add('Skills', Skills);
this.scene.run('Skills', cryp);
this.scene.manager.add('Skills', Skills, true, cryp);
}
addPassives(cryp) {
this.scene.add('Passives', Passives);
this.scene.run('Passives', cryp);
this.scene.manager.add('Passives', Skills, true, cryp);
}
removePassives() {
if (!this.passives) return false;
this.scene.remove('Passives');
this.scene.get('Passives').cleanUp();
this.passives = false;
return true;
}
removeSkills() {
if (!this.skills) return false;
this.scene.remove('Skills');
this.scene.get('Skills').cleanUp();
this.skills = false;
return true;
}
cleanUp() {
this.registry.events.off('changedata', this.updateData, this);
this.registry.events.off('setdata', this.updateData, this);
this.removePassives();
this.removeSkills();
this.scene.remove();
}
}
module.exports = StatSheet;