diff --git a/js/PElems/Node.ts b/js/PElems/Node.ts index d885ad5..6f5dfda 100644 --- a/js/PElems/Node.ts +++ b/js/PElems/Node.ts @@ -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() { diff --git a/js/PElems/Transition.ts b/js/PElems/Transition.ts index cd8d832..468aca9 100644 --- a/js/PElems/Transition.ts +++ b/js/PElems/Transition.ts @@ -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(); } diff --git a/js/graphics/tragable.ts b/js/graphics/tragable.ts index 458fceb..3180e3b 100644 --- a/js/graphics/tragable.ts +++ b/js/graphics/tragable.ts @@ -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); }); } diff --git a/js/index.ts b/js/index.ts index 7527036..ea5fee8 100644 --- a/js/index.ts +++ b/js/index.ts @@ -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); \ No newline at end of file +nodes.push(n1, n2, n3); +transitions.push(t1, t2, t3); \ No newline at end of file