This commit is contained in:
jusax23 2023-06-27 09:19:06 +02:00
parent 99658a631a
commit 484e5022d1
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
4 changed files with 29 additions and 7 deletions

View file

@ -1,4 +1,4 @@
import { svgNodes } from "..";
import { svgNodes, update } from "..";
import { SVGNode } from "../graphics/SVGNode";
import { Positionable } from "../types";
import { Edge } from "./Edge";
@ -20,6 +20,10 @@ export class Node implements Positionable {
this.renderedElement = new SVGNode(this);
this.renderedElement.appendIt(svgNodes);
this.renderedElement.onMove((event) => this.updatePosition(event.x, event.y));
this.renderedElement.onClick((event) => {
if (this.marks < this.capacity) this.marks++
update();
})
}
updatePoints() {

View file

@ -18,7 +18,9 @@ export class Transition implements Positionable {
this.renderedElement.appendIt(svgNodes);
this.renderedElement.onMove((event) => this.updatePosition(event.x, event.y));
}
#canFireC = false;
canFire() {
this.#canFireC = false;
for (const inE of this.inEdges) {
if (!inE.canSuck()) {
this.renderedElement.setCanFire(false);
@ -32,10 +34,15 @@ export class Transition implements Positionable {
}
}
this.renderedElement.setCanFire(true);
this.#canFireC = true;
return true;
}
fire() {
if (!this.canFire()) return false;
let canFireNow = this.canFire()
if(this.#canFireC && !canFireNow){
// TODO: koflikt.
}
if (!this.#canFireC || !canFireNow) return false;
for (const inE of this.inEdges) {
inE.suck();
}

View file

@ -24,7 +24,7 @@ export class Tragable {
svg.addEventListener('mouseleave', event => {
selected = false;
});
svg.addEventListener('click', event => {
element.addEventListener('click', event => {
if (!selected) this.#clickCB(event);
});
}

View file

@ -15,14 +15,17 @@ svg.appendChild(svgNodes);
let transitions: Transition[] = [];
let nodes: Node[] = [];
function loop() {
async function loop() {
for (const trans of transitions) {
trans.canFire();
}
for (const trans of transitions) {
console.log(trans.name, trans.fire());
}
update();
}
function update() {
export function update() {
for (const nod of nodes) {
nod.updatePoints();
}
@ -36,12 +39,20 @@ window.onresize = () => {
}
window.onresize(null as any);
setInterval(loop, 1000);
let n1 = new Node("n1", 100, 100);
let n2 = new Node("n2", 100, 300);
let n3 = new Node("n3", 200, 200);
let t1 = new Transition("t1", 100, 200);
let t2 = new Transition("t2", 150, 250);
let t3 = new Transition("t3", 150, 150);
t1.inEdges.push(new Edge(n1, t1, true))
t1.outEdges.push(new Edge(n2, t1, false));
t2.inEdges.push(new Edge(n2, t2, true))
t2.outEdges.push(new Edge(n3, t2, false));
t3.inEdges.push(new Edge(n3, t3, true))
t3.outEdges.push(new Edge(n1, t3, false));
nodes.push(n1, n2);
transitions.push(t1);
nodes.push(n1, n2, n3);
transitions.push(t1, t2, t3);