Skip to content

Commit 0cf029a

Browse files
committed
fix debug button
1 parent a760187 commit 0cf029a

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

demo/internal/canvas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {TimingFunc} from "../../internal/animate/timing";
22
import {Coord, Point} from "../../internal/types";
33
import {expandHandle, forPoints, mod, rad} from "../../internal/util";
4-
import {debug} from "../internal/debug";
4+
import {isDebug} from "../internal/debug";
55
import {sizes, colors} from "../internal/layout";
66

77
export const forceStyles = (ctx: CanvasRenderingContext2D, fn: () => void) => {
@@ -35,7 +35,7 @@ export const rotateAround = (
3535
options.ctx.rotate(options.angle);
3636
},
3737
() => {
38-
if (debug) {
38+
if (isDebug()) {
3939
tempStyles(
4040
options.ctx,
4141
() => (options.ctx.fillStyle = colors.debug),

demo/internal/debug.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// If debug is initially set to false it will not be toggleable.
2-
export let debug = true;
2+
let debug = true;
3+
export const isDebug = () => {
4+
return debug;
5+
};
36

47
const debugListeners: ((debug: boolean) => void)[] = [];
58
export const onDebugStateChange = (fn: (debug: boolean) => void) => {

demo/internal/layout.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {tempStyles} from "./canvas";
2-
import {debug, onDebugStateChange} from "./debug";
2+
import {isDebug, onDebugStateChange} from "./debug";
33

44
export const colors = {
55
debug: "green",
@@ -28,7 +28,10 @@ export interface AnimationPainter {
2828
(timestamp: number): void;
2929
}
3030

31-
const cells: Cell[][] = [];
31+
// Global cell state.
32+
const cells = ((window as any).cells as Cell[][]) || [];
33+
((window as any).cells as Cell[][]) = cells;
34+
3235
const containerElement = document.querySelector(".container");
3336
if (!containerElement) throw "missing container";
3437

@@ -41,7 +44,7 @@ const reveal = () => {
4144
redraw();
4245
};
4346
howItWorksElement.addEventListener("click", reveal);
44-
if (document.location.hash) setTimeout(reveal);
47+
if (document.location.hash || isDebug()) setTimeout(reveal);
4548

4649
export const sizes = (): {width: number; pt: number} => {
4750
const sectionStyle = window.getComputedStyle(
@@ -132,7 +135,7 @@ const redraw = () => {
132135

133136
// Draw canvas debug info.
134137
const drawDebug = () => {
135-
if (debug) {
138+
if (isDebug()) {
136139
tempStyles(
137140
cell.ctx,
138141
() => (cell.ctx.strokeStyle = colors.debug),
@@ -157,7 +160,7 @@ const redraw = () => {
157160
const frameTime = Date.now() - startTime;
158161
cell.ctx.clearRect(0, 0, cellWidth, cellHeight);
159162
drawDebug();
160-
if (debug) {
163+
if (isDebug()) {
161164
tempStyles(
162165
cell.ctx,
163166
() => (cell.ctx.fillStyle = colors.debug),

0 commit comments

Comments
 (0)