2023-06-22 17:47:04 +02:00
|
|
|
import { svgNodes } from "..";
|
|
|
|
import { SVGTRansition } from "../graphics/SVGTransition";
|
|
|
|
import { Positionable } from "../types";
|
|
|
|
import { Edge } from "./Edge";
|
|
|
|
|
|
|
|
export class Transition implements Positionable {
|
|
|
|
renderedElement: SVGTRansition;
|
|
|
|
name = "noname";
|
|
|
|
inEdges: Edge[] = [];
|
|
|
|
outEdges: Edge[] = [];
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
constructor(name: string, x: number, y: number) {
|
|
|
|
this.name = name;
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.renderedElement = new SVGTRansition(this);
|
|
|
|
this.renderedElement.appendIt(svgNodes);
|
|
|
|
this.renderedElement.onMove((event) => this.updatePosition(event.x, event.y));
|
|
|
|
}
|
2023-06-27 09:19:06 +02:00
|
|
|
#canFireC = false;
|
2023-06-22 17:47:04 +02:00
|
|
|
canFire() {
|
2023-06-27 09:19:06 +02:00
|
|
|
this.#canFireC = false;
|
2023-06-22 17:47:04 +02:00
|
|
|
for (const inE of this.inEdges) {
|
|
|
|
if (!inE.canSuck()) {
|
|
|
|
this.renderedElement.setCanFire(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const outE of this.outEdges) {
|
|
|
|
if (!outE.canPush()) {
|
|
|
|
this.renderedElement.setCanFire(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.renderedElement.setCanFire(true);
|
2023-06-27 09:19:06 +02:00
|
|
|
this.#canFireC = true;
|
2023-06-22 17:47:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
fire() {
|
2023-06-28 16:06:31 +02:00
|
|
|
let canFire = this.#canFireC
|
2023-06-27 09:19:06 +02:00
|
|
|
let canFireNow = this.canFire()
|
2023-06-28 16:06:31 +02:00
|
|
|
if(canFire && !canFireNow){
|
2023-06-27 09:19:06 +02:00
|
|
|
// TODO: koflikt.
|
|
|
|
}
|
2023-06-28 16:06:31 +02:00
|
|
|
if (!canFire || !canFireNow) return false;
|
2023-06-22 17:47:04 +02:00
|
|
|
for (const inE of this.inEdges) {
|
|
|
|
inE.suck();
|
|
|
|
}
|
|
|
|
for (const outE of this.outEdges) {
|
|
|
|
outE.push();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
updatePosition(x: number, y: number) {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.renderedElement.translate(x, y);
|
|
|
|
for (const inE of this.inEdges) {
|
|
|
|
inE.updatePosition();
|
|
|
|
}
|
|
|
|
for (const outE of this.outEdges) {
|
|
|
|
outE.updatePosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|