Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(sdk): an app says what its resources are called

esengine520aae04226a
diff --git a/desktop b/desktop
index 6e7e16277..f0c0a1b16 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 6e7e1627793adb5b1bae807889b79c554760478f
+Subproject commit f0c0a1b16a8d0da311a570368243bb5300a361db
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 5906db100..bdb5b6a46 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -736,6 +736,7 @@ getRegisteredResourceNames: () => string[]
getResource: <T>(resource: ResourceDef<T>) => T
getResourceByName: (name: string) => unknown | undefined
getResourceChangeTick: (name: string) => number
+getResourceEntries: () => Array<[string, unknown]>
getSystemTimings: () => ReadonlyMap<string, number> | null
getTargetFrameRate: () => number
hasResource: <T>(resource: ResourceDef<T>) => boolean
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 22dcc59b4..bfa98022c 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -736,6 +736,7 @@ getRegisteredResourceNames: () => string[]
getResource: <T>(resource: ResourceDef<T>) => T
getResourceByName: (name: string) => unknown | undefined
getResourceChangeTick: (name: string) => number
+getResourceEntries: () => Array<[string, unknown]>
getSystemTimings: () => ReadonlyMap<string, number> | null
getTargetFrameRate: () => number
hasResource: <T>(resource: ResourceDef<T>) => boolean
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 83e9d7883..cf1d23960 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -731,6 +731,7 @@ getRegisteredResourceNames: () => string[]
getResource: <T>(resource: ResourceDef<T>) => T
getResourceByName: (name: string) => unknown | undefined
getResourceChangeTick: (name: string) => number
+getResourceEntries: () => Array<[string, unknown]>
getSystemTimings: () => ReadonlyMap<string, number> | null
getTargetFrameRate: () => number
hasResource: <T>(resource: ResourceDef<T>) => boolean
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 5ba14d953..eb80293c2 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -731,6 +731,7 @@ getRegisteredResourceNames: () => string[]
getResource: <T>(resource: ResourceDef<T>) => T
getResourceByName: (name: string) => unknown | undefined
getResourceChangeTick: (name: string) => number
+getResourceEntries: () => Array<[string, unknown]>
getSystemTimings: () => ReadonlyMap<string, number> | null
getTargetFrameRate: () => number
hasResource: <T>(resource: ResourceDef<T>) => boolean
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index 87cd23f07..0823c7e29 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -731,6 +731,7 @@ getRegisteredResourceNames: () => string[]
getResource: <T>(resource: ResourceDef<T>) => T
getResourceByName: (name: string) => unknown | undefined
getResourceChangeTick: (name: string) => number
+getResourceEntries: () => Array<[string, unknown]>
getSystemTimings: () => ReadonlyMap<string, number> | null
getTargetFrameRate: () => number
hasResource: <T>(resource: ResourceDef<T>) => boolean
diff --git a/sdk/src/app/app.ts b/sdk/src/app/app.ts
index d8b0401d3..006a1874f 100644
--- a/sdk/src/app/app.ts
+++ b/sdk/src/app/app.ts
@@ -888,6 +888,15 @@ export class App {
return this.resources_.getRegisteredNames();
}
+ /**
+ * Every resource this app holds, as `[name, value]` — what an inspector
+ * shows. Includes the slots only a read has materialised, which
+ * {@link getRegisteredResourceNames} (insert-only) does not.
+ */
+ getResourceEntries(): Array<[string, unknown]> {
+ return this.resources_.entries();
+ }
+
// =========================================================================
// Scene Management
// =========================================================================
diff --git a/sdk/src/ecs/resource.ts b/sdk/src/ecs/resource.ts
index 4af57b7be..243b8542d 100644
--- a/sdk/src/ecs/resource.ts
+++ b/sdk/src/ecs/resource.ts
@@ -207,14 +207,22 @@ export class ResourceStorage {
* would report present the moment any system took it as a parameter.
*/
private defaulted_ = new Set<symbol>();
+ /** What each slot is called, so nobody has to reconstruct it from a symbol. */
+ private names_ = new Map<symbol, string>();
+
+ /** Record what a slot is called, whichever door reached it. */
+ private note_(resource: ResourceDef<unknown>): void {
+ this.names_.set(resource._id, resource._name);
+ if (resource._name && !resource._name.startsWith('Resource_')) {
+ this.nameRegistry_.set(resource._name, resource);
+ }
+ }
insert<T>(resource: ResourceDef<T>, value: T): void {
this.resources_.set(resource._id, value);
this.defaulted_.delete(resource._id);
this.ticks_.set(resource._id, ++this.globalTick_);
- if (resource._name && !resource._name.startsWith('Resource_')) {
- this.nameRegistry_.set(resource._name, resource as ResourceDef<unknown>);
- }
+ this.note_(resource as ResourceDef<unknown>);
}
get<T>(resource: ResourceDef<T>): T {
@@ -223,6 +231,7 @@ export class ResourceStorage {
// into the shared ResourceDef or a sibling world.
this.resources_.set(resource._id, deepClone(resource._default));
this.defaulted_.add(resource._id);
+ this.names_.set(resource._id, resource._name);
}
return this.resources_.get(resource._id) as T;
}
@@ -231,6 +240,7 @@ export class ResourceStorage {
this.resources_.set(resource._id, value);
this.defaulted_.delete(resource._id);
this.ticks_.set(resource._id, ++this.globalTick_);
+ this.note_(resource as ResourceDef<unknown>);
}
has<T>(resource: ResourceDef<T>): boolean {
@@ -242,9 +252,21 @@ export class ResourceStorage {
this.defaulted_.delete(resource._id);
this.resMutPool_.delete(resource._id);
this.ticks_.delete(resource._id);
+ this.names_.delete(resource._id);
this.nameRegistry_.delete(resource._name);
}
+ /**
+ * Every slot this storage holds, as `[name, value]` — including one only a
+ * read has materialised, which is most of them in a running game.
+ *
+ * The name is the declaration's. Reconstructing it from the id's
+ * description is a second author of what a resource is called.
+ */
+ entries(): Array<[string, unknown]> {
+ return [...this.resources_].map(([id, value]) => [this.names_.get(id) ?? '', value]);
+ }
+
getChangeTick(resource: ResourceDef<unknown>): number {
return this.ticks_.get(resource._id) ?? 0;
}
diff --git a/sdk/tests/resource.test.ts b/sdk/tests/resource.test.ts
index 1bc992790..99fb901af 100644
--- a/sdk/tests/resource.test.ts
+++ b/sdk/tests/resource.test.ts
@@ -315,3 +315,29 @@ describe('ResourceStorage', () => {
});
});
});
+
+/** What an inspector shows: the DECLARED name, never one recovered from the id. */
+describe('ResourceStorage.entries', () => {
+ it('answers the DECLARED name, not the symbol that addresses it', () => {
+ const storage = new ResourceStorage();
+ storage.insert(defineResource({ total: 0 }, 'EntriesScore'), { total: 3 });
+
+ expect(storage.entries()).toEqual([['EntriesScore', { total: 3 }]]);
+ });
+
+ it('includes a slot only a READ has materialised — most of them, in a running game', () => {
+ const storage = new ResourceStorage();
+ storage.get(defineResource({ phase: 'menu' }, 'EntriesPhase'));
+
+ expect(storage.entries()).toEqual([['EntriesPhase', { phase: 'menu' }]]);
+ });
+
+ it('drops a removed one rather than reporting it under an empty name', () => {
+ const storage = new ResourceStorage();
+ const Gone = defineResource(0, 'EntriesGone');
+ storage.insert(Gone, 1);
+ storage.remove(Gone);
+
+ expect(storage.entries()).toEqual([]);
+ });
+});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index cf3ebc115..d44b330c5 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -30,6 +30,10 @@ export const NOTES_FLOOR = 'v0.65.0';
export const NOTED = {
'fix(sdk): a reloaded bundle addresses the world it is reloading into':
{ note: 'A hot reload no longer empties the running game of every resource' },
+ 'feat(sdk): an app says what its resources are called':
+ { internal: 'the door it replaces was only ever wrong between two unreleased commits — a creator sees the same resource names either way' },
+ 'fix(editor): the resource door reads the declared name, and the live check asks about it':
+ { internal: 'the same unreleased window — and the live check it extends is a criterion, which a creator never runs' },
'feat(corpus): a room that is actually lit, and a gate that keeps it lit':
{ note: 'A room in the corpus is actually lit.' },