ctx.schematics.ids

This commit is contained in:
2026-11-22 16:09:11 -03:00
parent df7a1a94d6
commit 527f2fb5a7
4 changed files with 16 additions and 0 deletions
+2
View File
@@ -737,6 +737,8 @@ export interface SchematicApi {
// StructureTemplateManager.get. undefined for an id nothing registered. for reading what's in it before placing it, // StructureTemplateManager.get. undefined for an id nothing registered. for reading what's in it before placing it,
// like where a room's doorways are // like where a room's doorways are
get(id: Id): Schematic | undefined; get(id: Id): Schematic | undefined;
// every registered schematic's id, the files' and the ones scripts registered, in the order they were registered
ids(): Id[];
// puts a registered schematic in the world, all of it at once, replacing what was there, air too. replaced blocks // puts a registered schematic in the world, all of it at once, replacing what was there, air too. replaced blocks
// get their on_break. blocks it has data for get that data as it is, the rest their on_create, then everything // get their on_break. blocks it has data for get that data as it is, the rest their on_create, then everything
// placed tells the blocks beside it. its entities come with new uuids. throws for an id nothing registered, or a // placed tells the blocks beside it. its entities come with new uuids. throws for an id nothing registered, or a
+7
View File
@@ -88,6 +88,13 @@ const doorways = room.blocks.filter((block) => room.palette[block.i].id === "cop
Positions in it are from its lowest corner, before it's turned. Changing the copy doesn't change what `place` puts. Positions in it are from its lowest corner, before it's turned. Changing the copy doesn't change what `place` puts.
`ids` gives every registered schematic's id, the files' and the ones scripts registered, in the order they were
registered, like for a tool that lets players pick one:
```ts
const rooms = ctx.schematics.ids().filter((id) => id.startsWith("copper_tools:room_"));
```
Until `import_data` is built, a block's exported data goes back in as it is, so a chest placed from a schematic has its Until `import_data` is built, a block's exported data goes back in as it is, so a chest placed from a schematic has its
items' list in its data and no container. items' list in its data and no container.
+1
View File
@@ -1210,6 +1210,7 @@ export class ModRuntime {
const registered = game().schematics.get(id); const registered = game().schematics.get(id);
return registered && { ...structuredClone(registered.schematic), id }; return registered && { ...structuredClone(registered.schematic), id };
}, },
ids: () => [...game().schematics.keys()],
place: (id, placement) => game().place_schematic(id, placement), place: (id, placement) => game().place_schematic(id, placement),
}, },
menus: { menus: {
+6
View File
@@ -288,6 +288,12 @@ Deno.test("get gives a copy of a registered schematic with its id, a file's or a
assertEquals(t.game.world.get_block_id(10, 100, 20), "bworld:oak_planks"); assertEquals(t.game.world.get_block_id(10, 100, 20), "bworld:oak_planks");
}); });
Deno.test("ids gives every registered schematic's id, the files' first, without the ones that failed", async () => {
const t = await place_setup();
const ids = t.schematics.ids().filter((id) => id.startsWith("testmod:"));
assertEquals(ids, ["testmod:post", "testmod:hut", "testmod:partial"]);
});
Deno.test("a mod's schematics/<name>.cbsm files are registered as <mod id>:<name> before its scripts run", async () => { Deno.test("a mod's schematics/<name>.cbsm files are registered as <mod id>:<name> before its scripts run", async () => {
const t = await place_setup(); const t = await place_setup();
assertStringIncludes(String(t.game.mods.storage.testmod?.post), "registered twice"); assertStringIncludes(String(t.game.mods.storage.testmod?.post), "registered twice");