diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f7d8eff..6d3b02e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -175,6 +175,7 @@ debug.log(obj.getAnim("walk")); - (**v3001/4000**) added higher order easing functions linear, steps and cubic-bezier - (**v3001/4000**) added `textInput()` component +- (**v3001/4000**) now you can see custom properties in debug.inspect ## Bug fixes diff --git a/src/game/make.ts b/src/game/make.ts index d7a3f298..f370cf77 100644 --- a/src/game/make.ts +++ b/src/game/make.ts @@ -38,6 +38,7 @@ type MakeType = MakeTypeIsCLASS>; export function make(comps: CompList = []): GameObj> { const compStates = new Map(); + const anonymousCompStates: Comp[] = []; const cleanups = {} as Record unknown)[]>; const events = new KEventHandler(); const inputEvents: KEventController[] = []; @@ -203,7 +204,7 @@ export function make(comps: CompList = []): GameObj> { popTransform(); }, - // use a comp, or tag + // use a comp or a tag use(comp: Comp | Tag) { if (!comp) { return; @@ -235,6 +236,9 @@ export function make(comps: CompList = []): GameObj> { gc = cleanups[comp.id]; compStates.set(comp.id, comp); } + else { + anonymousCompStates.push(comp); + } for (const k in comp) { if (COMP_DESC.has(k)) { @@ -245,7 +249,7 @@ export function make(comps: CompList = []): GameObj> { if (!prop) continue; if (typeof prop.value === "function") { - // @ts-ignore Maybe a MAP would be better? + // @ts-ignore comp[k] = comp[k].bind(this); } @@ -539,6 +543,23 @@ export function make(comps: CompList = []): GameObj> { for (const [tag, comp] of compStates) { info[tag] = comp.inspect?.() ?? null; } + + for (const [i, comp] of anonymousCompStates.entries()) { + if (comp.inspect) { + info[i] = comp.inspect(); + continue; + } + + for (const [key, value] of Object.entries(comp)) { + if (typeof value === "function") { + continue; + } + else { + info[key] = `${key}: ${value}`; + } + } + } + return info; },