debugable wip

This commit is contained in:
Emmaline Autumn 2025-03-27 20:26:14 -06:00
parent 9500f6dabf
commit 5a5e490aa5
2 changed files with 20 additions and 16 deletions

View File

@ -3,12 +3,14 @@ import { TrackSegment } from "../track/system.ts";
import { Train, TrainCar } from "../train/train.ts";
import { InputManager } from "./input.ts";
import { ResourceManager } from "./resources.ts";
import { Debuggable } from "./debuggable.ts";
interface ContextMap {
inputManager: InputManager;
doodler: ZoomableDoodler;
resources: ResourceManager;
debug: Debug;
debuggables: Debuggable[];
colors: [
string,
string,

View File

@ -12,22 +12,24 @@ export abstract class Debuggable extends Drawable {
if (typeof debugKeys[0] === "boolean") {
drawFirst = debugKeys.shift() as boolean;
}
const draw = this.draw.bind(this);
this.draw = drawFirst
? (...args: unknown[]) => {
draw(...args);
const debug = getContextItem<Debug>("debug");
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);
};
const debuggables = getContextItem("debuggables");
debuggables.push(this);
// const draw = this.draw.bind(this);
// this.draw = drawFirst
// ? (...args: unknown[]) => {
// draw(...args);
// const debug = getContextItem<Debug>("debug");
// 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);
// };
}
}