55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
const Phaser = require('phaser');
|
|
|
|
class PassiveNode extends Phaser.GameObjects.Sprite {
|
|
constructor(scene, x, y, id, alloc, text) {
|
|
super(scene, x, y);
|
|
this.setTexture('eye');
|
|
this.scene = scene;
|
|
this.alloc = alloc;
|
|
this.text = (text.indexOf(',') > -1) ? text.split(',') : text;
|
|
this.id = id;
|
|
this.setPosition(x, y);
|
|
|
|
const nodeNoDigits = this.id.replace(/[0-9]/g, '');
|
|
switch (nodeNoDigits) {
|
|
case 'CNOTE':
|
|
this.setScale(0.25);
|
|
break;
|
|
case 'CLRG':
|
|
this.setScale(0.15);
|
|
break;
|
|
case 'CMED':
|
|
this.setScale(0.1);
|
|
break;
|
|
default:
|
|
this.setScale(0.05);
|
|
}
|
|
if (this.alloc) {
|
|
this.setTint(0xff0000);
|
|
}
|
|
}
|
|
|
|
allocate(alloc) {
|
|
this.alloc = (alloc !== undefined) ? alloc : !this.alloc;
|
|
this.updateNode();
|
|
}
|
|
|
|
updateNode() {
|
|
if (!this.alloc) {
|
|
this.clearTint();
|
|
} else {
|
|
this.setTint(0xff0000);
|
|
}
|
|
|
|
for (let i = 0; i < this.scene.passiveNodeData.length; i += 1) {
|
|
if (this.scene.passiveNodeData[i].id === this.id) {
|
|
this.scene.passiveNodeData[i].alloc = this.alloc;
|
|
break;
|
|
}
|
|
}
|
|
this.scene.drawPassiveEdges();
|
|
}
|
|
}
|
|
|
|
module.exports = PassiveNode;
|