47 lines
No EOL
1.5 KiB
TypeScript
47 lines
No EOL
1.5 KiB
TypeScript
import { svgNodes, update } from "..";
|
|
import { SVGNode } from "../graphics/SVGNode";
|
|
import { Positionable } from "../types";
|
|
import { Edge } from "./Edge";
|
|
|
|
export class Node implements Positionable {
|
|
renderedElement: SVGNode;
|
|
x: number = 0;
|
|
y: number = 0;
|
|
name: string;
|
|
capacity = 1;
|
|
marks = 0;
|
|
|
|
updateList: Edge[] = [];
|
|
|
|
constructor(name, x, y) {
|
|
this.name = name;
|
|
this.x = x;
|
|
this.y = y;
|
|
this.renderedElement = new SVGNode(this);
|
|
this.renderedElement.appendIt(svgNodes);
|
|
this.renderedElement.onMove((event) => this.updatePosition(event.x, event.y));
|
|
this.renderedElement.onClick((event) => {
|
|
let aws = parseInt(prompt("Gabe die maximale Anzahl an Marken ein:", this.capacity + "") || "");
|
|
if (isNaN(aws) || !isFinite(aws) || aws < 1) return;
|
|
this.capacity = aws;
|
|
aws = parseInt(prompt("Gabe die aktuelle Anzahl an Marken ein:", this.marks + "") || "");
|
|
if (isNaN(aws) || !isFinite(aws) || aws < 1) return;
|
|
this.marks = aws;
|
|
//if (this.marks < this.capacity) this.marks++
|
|
update();
|
|
});
|
|
}
|
|
|
|
updatePoints() {
|
|
this.renderedElement.setMarks(this.marks, this.capacity);
|
|
}
|
|
|
|
updatePosition(x: number, y: number) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.renderedElement.translate(x, y);
|
|
for (const elem of this.updateList) {
|
|
elem.updatePosition();
|
|
}
|
|
}
|
|
} |