Placing schematics
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
// schematics: blocks and entities from a box of the world, kept to be placed again somewhere else. a .cbsm file is
|
||||
// one encoded with msgpack. the short keys (i, s, p) are there to keep files small, see STRUCTURES.md
|
||||
import { decode, encode } from "@std/msgpack";
|
||||
import * as z from "zod";
|
||||
import { find_problems, id, json_object, type Problems, vec3 } from "./schema.ts";
|
||||
|
||||
export const SCHEMATIC_EXTENSION = ".cbsm";
|
||||
|
||||
@@ -62,3 +64,23 @@ export function decode_schematic(bytes: Uint8Array): Schematic {
|
||||
}
|
||||
return file.schematic;
|
||||
}
|
||||
|
||||
const int = z.int();
|
||||
const block_position = z.tuple([int.min(0), int.min(0), int.min(0)], "must be [x, y, z], whole numbers from 0");
|
||||
const schematic_schema = z.object({
|
||||
id: z.string().optional(),
|
||||
size: z.tuple([int.min(1), int.min(1), int.min(1)], "must be [x, y, z], whole numbers from 1"),
|
||||
palette: z.array(z.object({ id, s: z.record(z.string(), int.min(0)).optional() })),
|
||||
blocks: z.array(z.object({
|
||||
i: int.min(0),
|
||||
p: block_position,
|
||||
data: z.unknown().optional(),
|
||||
client_data: json_object.optional(),
|
||||
})),
|
||||
entities: z.array(z.object({ p: vec3, id, data: json_object })),
|
||||
});
|
||||
|
||||
// what's wrong with the shape of a schematic, without looking at whether its blocks and entities exist
|
||||
export function schematic_problems(json: unknown): Problems {
|
||||
return find_problems(schematic_schema, json);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user