ok no more debugging for now

This commit is contained in:
Emmaline Autumn 2025-02-15 21:39:32 -07:00
parent 7914eb444a
commit b30a241d09
5 changed files with 38 additions and 31 deletions

View File

@ -1,6 +1,6 @@
// Create a new devtools panel named "Context Stack" // Create a new devtools panel named "Context Stack"
browser.devtools.panels.create( browser.devtools.panels.create(
"Context Stack", // Tab title "Smoke and Rails", // Tab title
"train icon.png", // Icon for your panel (optional) "train icon.png", // Icon for your panel (optional)
"panel.html", // HTML page for your panel content "panel.html", // HTML page for your panel content
); );

View File

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Context Stack</title> <title>Smoke and Rails</title>
<style> <style>
body { body {
font-family: sans-serif; font-family: sans-serif;
@ -40,9 +40,9 @@
</head> </head>
<body> <body>
<h1>Context Stack</h1> <h2>Smoke and Rails Debugger</h2>
<div id="contextContainer"></div>
<button id="refresh">Refresh</button> <button id="refresh">Refresh</button>
<div id="contextContainer"></div>
<script src="panel.js"></script> <script src="panel.js"></script>
</body> </body>
</html> </html>

View File

@ -5,18 +5,29 @@ export abstract class Drawable {
} }
export abstract class Debuggable extends Drawable { export abstract class Debuggable extends Drawable {
constructor(...debugKeys: (keyof Debug)[]) { constructor(...debugKeys: [boolean | keyof Debug, ...(keyof Debug)[]]) {
super(); super();
if (import.meta.env.DEV) { if (import.meta.env.DEV) {
let drawFirst = false;
if (typeof debugKeys[0] === "boolean") {
drawFirst = debugKeys.shift() as boolean;
}
const draw = this.draw.bind(this); const draw = this.draw.bind(this);
console.log("Adding debug draw"); this.draw = drawFirst
this.draw = (...args: unknown[]) => { ? (...args: unknown[]) => {
draw(...args); draw(...args);
const debug = getContextItem<Debug>("debug"); const debug = getContextItem<Debug>("debug");
if (debugKeys.some((k) => debug[k])) { if (debugKeys.some((k) => debug[k as keyof Debug])) {
this.debugDraw(...args); this.debugDraw();
}
} }
}; : (...args: unknown[]) => {
const debug = getContextItem<Debug>("debug");
if (debugKeys.some((k) => debug[k as keyof Debug])) {
this.debugDraw();
}
draw(...args);
};
} }
} }

View File

@ -1,12 +1,8 @@
import { ComplexPath, PathSegment } from "../math/path.ts"; import { getContextItem } from "../lib/context.ts";
import { Follower } from "../physics/follower.ts";
import { Mover } from "../physics/mover.ts";
import { getContext, getContextItem } from "../lib/context.ts";
import { Doodler, Vector } from "@bearmetal/doodler"; import { Doodler, Vector } from "@bearmetal/doodler";
import { Spline, TrackSegment, TrackSystem } from "../track/system.ts"; import { Spline, TrackSegment, TrackSystem } from "../track/system.ts";
import { ResourceManager } from "../lib/resources.ts";
import { map } from "../math/lerp.ts";
import { Debuggable } from "../lib/debuggable.ts"; import { Debuggable } from "../lib/debuggable.ts";
import { map } from "../math/lerp.ts";
export class Train extends Debuggable { export class Train extends Debuggable {
nodes: Vector[] = []; nodes: Vector[] = [];
@ -59,7 +55,6 @@ export class Train extends Debuggable {
if (!this.speed) return; if (!this.speed) return;
this.t = this.t + this.speed * dTime * 10; this.t = this.t + this.speed * dTime * 10;
// % this.path.evenPoints.length; // This should probably be on the track system // % this.path.evenPoints.length; // This should probably be on the track system
// console.log(this.t);
let currentOffset = 0; let currentOffset = 0;
for (const car of this.cars) { for (const car of this.cars) {
// This needs to be moved to the car itself // This needs to be moved to the car itself
@ -98,8 +93,7 @@ export class Train extends Debuggable {
} }
} }
override debugDraw(...args: unknown[]): void { override debugDraw(): void {
console.log("Train debug draw");
const debug = getContextItem<Debug>("debug"); const debug = getContextItem<Debug>("debug");
const doodler = getContextItem<Doodler>("doodler"); const doodler = getContextItem<Doodler>("doodler");
if (debug.path) { if (debug.path) {
@ -140,7 +134,7 @@ export class Train extends Debuggable {
} }
} }
export class TrainCar { export class TrainCar extends Debuggable {
img: HTMLImageElement; img: HTMLImageElement;
imgWidth: number; imgWidth: number;
imgHeight: number; imgHeight: number;
@ -158,6 +152,7 @@ export class TrainCar {
h: number, h: number,
sprite?: ISprite, sprite?: ISprite,
) { ) {
super(true, "car");
this.img = img; this.img = img;
this.sprite = sprite; this.sprite = sprite;
this.imgWidth = w; this.imgWidth = w;
@ -190,14 +185,14 @@ export class TrainCar {
origin.copy().sub(this.imgWidth / 2, this.imgHeight / 2), origin.copy().sub(this.imgWidth / 2, this.imgHeight / 2),
); );
}); });
}
const debug = getContextItem<Debug>("debug"); override debugDraw(...args: unknown[]): void {
if (debug.car) { if (!this.points) return;
doodler.drawLine(this.points, { const doodler = getContextItem<Doodler>("doodler");
color: "blue", doodler.drawLine(this.points, {
weight: 3, color: "blue",
}); weight: 3,
} });
} }
} }

View File

@ -4,8 +4,9 @@ export function strip(): Plugin {
const p: Plugin = { const p: Plugin = {
name: "debug-strip", name: "debug-strip",
enforce: "pre", enforce: "pre",
apply: "build",
transform(code: string, id: string) { transform(code: string, id: string) {
if (!id.endsWith(".ts")) { if (!id.endsWith(".ts") || import.meta.env.DEV) {
return code; return code;
} }