Add various generic models
This commit is contained in:
+29
-25
@@ -3,7 +3,7 @@
|
||||
|
||||
import { assert, assertEquals, assertStringIncludes, assertThrows } from "@std/assert";
|
||||
import { validate_model } from "$/common/mod_data.ts";
|
||||
import type { ModelJson } from "$/common/block_models.ts";
|
||||
import type { ModelFileJson } from "$/common/block_models.ts";
|
||||
import { import_models } from "$/tools/importer/models.ts";
|
||||
import { convert_mcmeta, import_textures } from "$/tools/importer/textures.ts";
|
||||
|
||||
@@ -18,7 +18,7 @@ function resources(models: Record<string, unknown>, namespace = "gears"): string
|
||||
return root;
|
||||
}
|
||||
|
||||
function convert(models: Record<string, unknown>, path: string): ModelJson {
|
||||
function convert(models: Record<string, unknown>, path: string): ModelFileJson {
|
||||
const root = resources(models);
|
||||
const report = import_models(`${root}/assets/gears/models/${path}.json`);
|
||||
assertEquals(report.errors, []);
|
||||
@@ -47,65 +47,66 @@ Deno.test("a java block model becomes a bworld model that passes its checks", ()
|
||||
assertEquals(validate_model(model), []);
|
||||
// folders are joined into the id, the way textures in subfolders are named
|
||||
assertEquals(model.id, "gears:block_gear");
|
||||
assertEquals(model.textures, { "0": "gears:block_gear" });
|
||||
const [hub] = model.elements;
|
||||
// particle comes along too, since some models draw faces with it
|
||||
assertEquals(model.textures, { "0": "gears:block_gear", particle: "gears:block_gear" });
|
||||
const [hub] = model.elements!;
|
||||
assertEquals(Object.keys(hub.faces).sort(), ["bottom", "north", "top"]);
|
||||
assertEquals(hub.faces.top, { texture: "#0", uv: [0, 0, 8, 8], cullface: "top" });
|
||||
assertEquals(hub.faces.north?.rotation, 90);
|
||||
assertEquals(hub.rotation, { origin: [8, 8, 8], axis: "y", angle: 22.5 });
|
||||
});
|
||||
|
||||
Deno.test("a model gets its parents' elements and textures, its own textures winning", () => {
|
||||
Deno.test("a model keeps its parent, which bworld merges in when it loads", () => {
|
||||
const model = convert({
|
||||
"block/gear": GEAR,
|
||||
"block/gear_brass": { parent: "gears:block/gear", textures: { "0": "gears:block/brass_gear" } },
|
||||
}, "block/gear_brass");
|
||||
assertEquals(model.textures, { "0": "gears:block_brass_gear" });
|
||||
assertEquals(model.elements.length, GEAR.elements.length);
|
||||
assertEquals(model, {
|
||||
id: "gears:block_gear_brass",
|
||||
parent: "gears:block_gear",
|
||||
textures: { "0": "gears:block_brass_gear" },
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("vanilla parents like cube_all and stairs convert without minecraft's files", () => {
|
||||
Deno.test("minecraft's template parents become the base game's, and others need a remap", () => {
|
||||
const cube = convert(
|
||||
{ "block/casing": { parent: "minecraft:block/cube_all", textures: { all: "block/stone" } } },
|
||||
"block/casing",
|
||||
);
|
||||
assertEquals(validate_model(cube), []);
|
||||
assertEquals(Object.keys(cube.elements[0].faces).length, 6);
|
||||
assertEquals(cube.parent, "bworld:cube_all");
|
||||
// minecraft's block textures are taken to be the base game's of the same name
|
||||
assertEquals(cube.textures?.all, "bworld:stone");
|
||||
assertEquals(convert({ "block/steps": { parent: "block/stairs" } }, "block/steps").parent, "bworld:stairs");
|
||||
|
||||
const stairs = convert({
|
||||
"block/stairs": {
|
||||
parent: "block/stairs",
|
||||
textures: { top: "gears:block/a", bottom: "gears:block/a", side: "gears:block/a" },
|
||||
},
|
||||
}, "block/stairs");
|
||||
assertEquals(validate_model(stairs), []);
|
||||
assert(stairs.elements.length > 1);
|
||||
const root = resources({ "block/stand": { parent: "block/lectern" } });
|
||||
const report = import_models(`${root}/assets/gears/models/block/stand.json`);
|
||||
assertStringIncludes(report.errors[0].problems[0], "--remap");
|
||||
});
|
||||
|
||||
Deno.test("a folder converts into the same folders, with models that are only parents left out", () => {
|
||||
Deno.test("a folder converts into the same folders, models only there to be parents included", () => {
|
||||
const root = resources({
|
||||
"block/gear": GEAR,
|
||||
"block/large/gear": { parent: "gears:block/gear" },
|
||||
// block/block only holds display transforms, so this keeps its textures and nothing else
|
||||
"block/template": { parent: "block/block", textures: { "0": "gears:block/gear" } },
|
||||
});
|
||||
const output = Deno.makeTempDirSync();
|
||||
const report = import_models(root, { output });
|
||||
assertEquals(report.errors, []);
|
||||
assertEquals(report.parents, ["gears:block/template"]);
|
||||
for (const path of ["block/gear", "block/large/gear"]) {
|
||||
for (const path of ["block/gear", "block/large/gear", "block/template"]) {
|
||||
const json = JSON.parse(Deno.readTextFileSync(`${output}/${path}.json`));
|
||||
assertEquals(json.format_version, 1);
|
||||
assertEquals(validate_model(json.model), []);
|
||||
}
|
||||
assertEquals(JSON.parse(Deno.readTextFileSync(`${output}/block/template.json`)).model.parent, undefined);
|
||||
});
|
||||
|
||||
Deno.test("models that can't be converted are reported, not written", () => {
|
||||
const root = resources({
|
||||
"block/obj": { loader: "forge:obj", model: "gears:models/block/thing.obj" },
|
||||
"item/ingot": { parent: "item/generated", textures: { layer0: "gears:item/ingot" } },
|
||||
"block/orphan": { parent: "gears:block/nowhere" },
|
||||
// a sprite's child is a sprite too
|
||||
"item/shiny_ingot": { parent: "gears:item/ingot" },
|
||||
"block/tilted": {
|
||||
...GEAR,
|
||||
elements: [{ ...GEAR.elements[0], rotation: { angle: 30, axis: "x", origin: [8, 8, 8] } }],
|
||||
@@ -116,9 +117,12 @@ Deno.test("models that can't be converted are reported, not written", () => {
|
||||
});
|
||||
const output = Deno.makeTempDirSync();
|
||||
const report = import_models(root, { output });
|
||||
assertEquals(report.skipped.map(({ location }) => location).sort(), ["gears:block/obj", "gears:item/ingot"]);
|
||||
assertEquals(report.skipped.map(({ location }) => location).sort(), [
|
||||
"gears:block/obj",
|
||||
"gears:item/ingot",
|
||||
"gears:item/shiny_ingot",
|
||||
]);
|
||||
const errors = Object.fromEntries(report.errors.map(({ location, problems }) => [location, problems.join(" ")]));
|
||||
assertStringIncludes(errors["gears:block/orphan"], "gears:block/nowhere");
|
||||
assertStringIncludes(errors["gears:block/tilted"], "30");
|
||||
assertStringIncludes(errors["gears:block/a_b"] ?? errors["gears:block/a/b"], "--remap");
|
||||
assertEquals(report.written.length, 1);
|
||||
@@ -131,7 +135,7 @@ Deno.test("--remap renames locations before they become ids", () => {
|
||||
});
|
||||
const model = JSON.parse(report.written[0].text!).model;
|
||||
assertEquals(model.id, "cogs:big_gear");
|
||||
assertEquals(model.textures, { "0": "cogs:gear" });
|
||||
assertEquals(model.textures, { "0": "cogs:gear", particle: "cogs:gear" });
|
||||
});
|
||||
|
||||
// a png with only the header, which is all that's read to size it
|
||||
|
||||
Reference in New Issue
Block a user