class RectangleNode { constructor(x, y, scene, type, ...option) { switch (type.toString().toLowerCase()) { case 'attack': this.rect = new Phaser.GameObjects.Image(scene, x, y, 'attackN'); this.node = new Attack(); this.canAddNode = false; this.line = scene.add.graphics(); break; case 'move' : this.rect = new Phaser.GameObjects.Image(scene, x, y, 'moveN'); this.node = new Move(option[0]); this.canAddNode = false; this.line = scene.add.graphics(); if (option[0] === true) { this.rect.setFrame(0); } else { this.rect.setFrame(2); } break; case 'condition': this.rect = new Phaser.GameObjects.Image(scene, x, y, 'conditionN'); this.node = new Condition(option[0], option[1], option[2], option[3], option[4]); this.canAddNode = true; this.lRect = []; this.scene = scene; this.line = scene.add.graphics(); let line; if (option[0].name.toString().toLowerCase() === 'myself') { line = 0; } else { line = 1; } let shield = 0; if (option[1] === true) { //shield shield = Math.floor(option[3] * 3); } if (option[2] === true) { //range } this.rect.setFrame(line * 4 + shield); break; case 'waria': this.rect = new Phaser.GameObjects.Image(scene, x, y, 'logoWaria'); this.canAddNode = true; this.lRect = []; this.scene = scene; this.scene.add.existing(this.rect); break; default: console.log("Création d'un node echoué"); return; } if (type.toString().toLowerCase() !== 'waria') { } this.rect.setOrigin(0.5, 0); this.rect.displayHeight = HEIGHT_WINDOW / 6; this.rect.scaleX = this.rect.scaleY; } getX() { return this.rect.x; } addRect(node) { if (this.canAddNode === true) { this.lRect.push(node); this.addLine(node); let rect = this.scene.add.existing(node.rect); rect.setInteractive(); this.scene.input.setDraggable(rect); if (this.node !== undefined) { this.node.addNode(node.node); } } } setLine(x, y) { this.xOrigin = x; this.yOrigin = y; this.updateLine(true); } updateLine(force) { if ((force === true || this.xLine !== this.rect.x || this.yLine !== this.rect.y) && this.line !== undefined) { this.xLine = this.rect.x; this.yLine = this.rect.y; this.line.clear(); this.line.lineStyle(10, 0xffffff, 1); this.line.lineBetween(this.xOrigin, this.yOrigin, this.rect.x, this.rect.y + this.rect.displayHeight / 10); } if (this.canAddNode === true) { this.lRect.forEach(node => this.addLine(node)); } } addLine(node) { node.setLine(this.rect.x, this.rect.y + this.rect.displayHeight * 0.9); } getNodes() { if (this.node === undefined) { let lNodes = []; this.lRect.forEach(function (element) { if (element.node !== undefined) { if (element.lRect !== undefined) { element.node.clearNodes(); element.lRect.forEach(rect => element.node.addNode(rect.node)); } lNodes.push(element.node); } }); return lNodes; } } }