Skip to content

Commit e4d10a1

Browse files
authored
feat: add hacky pause button (#31)
1 parent c6232c2 commit e4d10a1

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/index.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<div id="top-bar">
1212
<button id="save-button" class="save-button" title="Save">Save</button>
1313
<button id="load-button" class="load-button" title="Load">Load</button>
14+
<button id="pause-button" class="load-button" title="Pause">Pause</button>
1415
<div id="app-title">GEduNet</div>
1516
</div>
1617
<div id="bottom-screen" class="row container">

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
selectElement,
2020
} from "./types/viewportManager";
2121
import { DataGraph } from "./types/graphs/datagraph";
22+
import { packetTicker } from "./types/packet";
2223

2324
const WORLD_WIDTH = 10000;
2425
const WORLD_HEIGHT = 10000;
@@ -348,5 +349,19 @@ export class RightBar {
348349
input.click();
349350
};
350351

352+
const pauseButton = document.getElementById("pause-button");
353+
let paused = false;
354+
pauseButton.onclick = () => {
355+
paused = !paused;
356+
if (paused) {
357+
pauseButton.textContent = "Resume";
358+
packetTicker.stop();
359+
} else {
360+
pauseButton.textContent = "Pause";
361+
packetTicker.start();
362+
}
363+
};
364+
packetTicker.start();
365+
351366
console.log("initialized!");
352367
})();

src/types/packet.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Graphics, Ticker } from "pixi.js";
22
import { Edge, Position } from "./edge";
33

4+
export const packetTicker = new Ticker();
5+
46
export class Packet extends Graphics {
57
speed: number;
68
progress = 0;
@@ -27,7 +29,8 @@ export class Packet extends Graphics {
2729
this.currentPath = path;
2830
this.currentEdge = this.currentPath.shift();
2931
this.currentStart = start;
30-
Ticker.shared.add(this.updateProgress, this);
32+
// TODO: use global ticker, and add "shouldProgress" flag
33+
packetTicker.add(this.updateProgress, this);
3134
}
3235

3336
updateProgress(ticker: Ticker) {

0 commit comments

Comments
 (0)