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"
browser.devtools.panels.create(
"Context Stack", // Tab title
"Smoke and Rails", // Tab title
"train icon.png", // Icon for your panel (optional)
"panel.html", // HTML page for your panel content
);

View File

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

View File

@ -5,17 +5,28 @@ export abstract class Drawable {
}
export abstract class Debuggable extends Drawable {
constructor(...debugKeys: (keyof Debug)[]) {
constructor(...debugKeys: [boolean | keyof Debug, ...(keyof Debug)[]]) {
super();
if (import.meta.env.DEV) {
let drawFirst = false;
if (typeof debugKeys[0] === "boolean") {
drawFirst = debugKeys.shift() as boolean;
}
const draw = this.draw.bind(this);
console.log("Adding debug draw");
this.draw = (...args: unknown[]) => {
this.draw = drawFirst
? (...args: unknown[]) => {
draw(...args);
const debug = getContextItem<Debug>("debug");
if (debugKeys.some((k) => debug[k])) {
this.debugDraw(...args);
if (debugKeys.some((k) => debug[k as keyof Debug])) {
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 { Follower } from "../physics/follower.ts";
import { Mover } from "../physics/mover.ts";
import { getContext, getContextItem } from "../lib/context.ts";
import { getContextItem } from "../lib/context.ts";
import { Doodler, Vector } from "@bearmetal/doodler";
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 { map } from "../math/lerp.ts";
export class Train extends Debuggable {
nodes: Vector[] = [];
@ -59,7 +55,6 @@ export class Train extends Debuggable {
if (!this.speed) return;
this.t = this.t + this.speed * dTime * 10;
// % this.path.evenPoints.length; // This should probably be on the track system
// console.log(this.t);
let currentOffset = 0;
for (const car of this.cars) {
// This needs to be moved to the car itself
@ -98,8 +93,7 @@ export class Train extends Debuggable {
}
}
override debugDraw(...args: unknown[]): void {
console.log("Train debug draw");
override debugDraw(): void {
const debug = getContextItem<Debug>("debug");
const doodler = getContextItem<Doodler>("doodler");
if (debug.path) {
@ -140,7 +134,7 @@ export class Train extends Debuggable {
}
}
export class TrainCar {
export class TrainCar extends Debuggable {
img: HTMLImageElement;
imgWidth: number;
imgHeight: number;
@ -158,6 +152,7 @@ export class TrainCar {
h: number,
sprite?: ISprite,
) {
super(true, "car");
this.img = img;
this.sprite = sprite;
this.imgWidth = w;
@ -190,16 +185,16 @@ export class TrainCar {
origin.copy().sub(this.imgWidth / 2, this.imgHeight / 2),
);
});
const debug = getContextItem<Debug>("debug");
if (debug.car) {
}
override debugDraw(...args: unknown[]): void {
if (!this.points) return;
const doodler = getContextItem<Doodler>("doodler");
doodler.drawLine(this.points, {
color: "blue",
weight: 3,
});
}
}
}
interface ISprite {
at: Vector;

View File

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