Validators using zod
This commit is contained in:
+12
-11
@@ -26,23 +26,24 @@ Deno.test("a bedrock geo.json becomes an entity model with only what the engine
|
||||
|
||||
// per face uvs and parents that come later aren't supported
|
||||
const per_face = { origin: [0, 0, 0], size: [1, 1, 1], uv: { north: { uv: [0, 0], uv_size: [1, 1] } } };
|
||||
const bad = entity_model_from_geo({
|
||||
"minecraft:geometry": [{
|
||||
description: { texture_width: 16, texture_height: 16 },
|
||||
bones: [{ name: "leg", parent: "body", cubes: [per_face] }, { name: "body" }],
|
||||
}],
|
||||
}, "a:b");
|
||||
assertEquals(bad.model, undefined);
|
||||
assert(bad.problems.some((p) => p.includes("parent body must be a bone before it")), String(bad.problems));
|
||||
assert(bad.problems.some((p) => p.includes("per face uvs aren't supported")), String(bad.problems));
|
||||
const geo_problems = (bones: unknown[]) => {
|
||||
const geometry = { description: { texture_width: 16, texture_height: 16 }, bones };
|
||||
const { model, problems } = entity_model_from_geo({ "minecraft:geometry": [geometry] }, "a:b");
|
||||
assertEquals(model, undefined);
|
||||
return problems;
|
||||
};
|
||||
const late_parent = geo_problems([{ name: "leg", parent: "body" }, { name: "body" }]);
|
||||
assert(late_parent.some((p) => p.includes("parent body must be a bone before it")), String(late_parent));
|
||||
const per_face_problems = geo_problems([{ name: "leg", cubes: [per_face] }]);
|
||||
assert(per_face_problems.some((p) => p.includes("per face uvs aren't supported")), String(per_face_problems));
|
||||
assertEquals(entity_model_from_geo({ format_version: "1.12.0" }, "a:b").model, undefined);
|
||||
});
|
||||
|
||||
Deno.test("an entity needs a texture and a size", () => {
|
||||
assertEquals(validate_entity({ id: "a:b", model: "a:b", texture: "a:b", width: 0.5, height: 1 }), []);
|
||||
assertEquals(validate_entity({ id: "a:b", model: "a:b", texture: "a:b", width: 0, height: 1, max_health: -1 }), [
|
||||
"width must be a number of blocks above 0, at most 16",
|
||||
"max_health must be a number, 0 or more",
|
||||
"width must be above 0",
|
||||
"max_health must be 0 or more",
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user