ctx.schematics.ids
This commit is contained in:
@@ -737,6 +737,8 @@ export interface SchematicApi {
|
||||
// StructureTemplateManager.get. undefined for an id nothing registered. for reading what's in it before placing it,
|
||||
// like where a room's doorways are
|
||||
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
|
||||
// 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
|
||||
|
||||
@@ -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.
|
||||
|
||||
`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
|
||||
items' list in its data and no container.
|
||||
|
||||
|
||||
@@ -1210,6 +1210,7 @@ export class ModRuntime {
|
||||
const registered = game().schematics.get(id);
|
||||
return registered && { ...structuredClone(registered.schematic), id };
|
||||
},
|
||||
ids: () => [...game().schematics.keys()],
|
||||
place: (id, placement) => game().place_schematic(id, placement),
|
||||
},
|
||||
menus: {
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
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 () => {
|
||||
const t = await place_setup();
|
||||
assertStringIncludes(String(t.game.mods.storage.testmod?.post), "registered twice");
|
||||
|
||||
Reference in New Issue
Block a user