2023-06-28 18:22:29 +02:00
|
|
|
import { svgArrows, update } from "..";
|
2023-06-22 17:47:04 +02:00
|
|
|
import { SVGArrow } from "../graphics/SVGArrow";
|
|
|
|
import { Node } from "./Node";
|
|
|
|
import { Transition } from "./Transition";
|
|
|
|
|
|
|
|
export class Edge {
|
|
|
|
renderedElement: SVGArrow;
|
|
|
|
end: Node;
|
|
|
|
trans: Transition;
|
|
|
|
inEdge: boolean;
|
|
|
|
dimension = 1;
|
|
|
|
constructor(end: Node, trans: Transition, inEdge = true) {
|
|
|
|
this.end = end;
|
|
|
|
this.trans = trans;
|
|
|
|
this.inEdge = inEdge;
|
|
|
|
this.renderedElement = inEdge ? new SVGArrow(end, trans) : new SVGArrow(trans, end);
|
|
|
|
this.renderedElement.appendIt(svgArrows);
|
|
|
|
end.updateList.push(this);
|
2023-06-28 18:22:29 +02:00
|
|
|
this.renderedElement.onClick(() => {
|
|
|
|
let aws = parseInt(prompt("Gebe die Dimension ein:", this.dimension + "") || "");
|
|
|
|
if (isNaN(aws) || !isFinite(aws) || aws < 1) return;
|
|
|
|
this.dimension = aws;
|
|
|
|
this.renderedElement.setDimension(aws + "");
|
|
|
|
update();
|
|
|
|
})
|
2023-06-22 17:47:04 +02:00
|
|
|
}
|
|
|
|
canSuck() {
|
|
|
|
return this.end.marks >= this.dimension;
|
|
|
|
}
|
|
|
|
suck() {
|
|
|
|
this.end.marks -= this.dimension;
|
|
|
|
this.end.updatePoints();
|
|
|
|
}
|
|
|
|
canPush() {
|
|
|
|
return this.end.capacity >= this.end.marks + this.dimension;
|
|
|
|
}
|
|
|
|
push() {
|
|
|
|
this.end.marks += this.dimension;
|
|
|
|
this.end.updatePoints();
|
|
|
|
}
|
|
|
|
updatePosition() {
|
|
|
|
this.renderedElement.updatePosition();
|
|
|
|
}
|
|
|
|
}
|