Messy but working chicken
This commit is contained in:
+20
-2
@@ -1,9 +1,11 @@
|
||||
// deno task check-mods
|
||||
// validates every mod in mods/: manifests, data files, textures, references between them, and typechecks scripts
|
||||
import {
|
||||
entity_model_from_geo,
|
||||
FORMAT_VERSION,
|
||||
OreJson,
|
||||
validate_block,
|
||||
validate_entity,
|
||||
validate_item,
|
||||
validate_manifest,
|
||||
validate_model,
|
||||
@@ -66,6 +68,8 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
items: [],
|
||||
recipes: [],
|
||||
ores: [],
|
||||
entities: [],
|
||||
entity_models: [],
|
||||
textures: [],
|
||||
texture_files: new Map(),
|
||||
};
|
||||
@@ -97,7 +101,8 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
validate: (json: unknown) => string[],
|
||||
into: { file: string; json: T }[],
|
||||
) => {
|
||||
for (const file of walk(`${dir}/${folder}`, ".json")) {
|
||||
// models/<name>.geo.json are entity models, not block ones
|
||||
for (const file of walk(`${dir}/${folder}`, ".json").filter((file) => !file.endsWith(".geo.json"))) {
|
||||
const path = `${folder}/${file}`;
|
||||
const wrapper = read_json(`${dir}/${path}`, (m) => error(`${path}: ${m}`));
|
||||
if (wrapper === undefined) continue;
|
||||
@@ -114,6 +119,19 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
load_data("models", "model", validate_model, mod.models);
|
||||
load_data("items", "item", validate_item, mod.items);
|
||||
load_data("recipes", "recipe", validate_recipe, mod.recipes);
|
||||
load_data("entities", "entity", validate_entity, mod.entities);
|
||||
|
||||
for (const file of walk(`${dir}/models`, ".geo.json")) {
|
||||
const path = `models/${file}`;
|
||||
const json = read_json(`${dir}/${path}`, (m) => error(`${path}: ${m}`));
|
||||
if (json === undefined) continue;
|
||||
const { model, problems } = entity_model_from_geo(
|
||||
json,
|
||||
`${id}:${file.replace(/\.geo\.json$/, "").replaceAll("/", "_")}`,
|
||||
);
|
||||
for (const problem of problems) error(`${path}: ${problem}`);
|
||||
if (model) mod.entity_models.push({ file: path, json: model });
|
||||
}
|
||||
|
||||
if (exists(`${dir}/worldgen/ores.json`)) {
|
||||
const ores = read_json(`${dir}/worldgen/ores.json`, (m) => error(`worldgen/ores.json: ${m}`));
|
||||
@@ -129,7 +147,7 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
}
|
||||
|
||||
// a mod only registers ids in its own namespace
|
||||
for (const { file, json } of [...mod.blocks, ...mod.models, ...mod.items]) {
|
||||
for (const { file, json } of [...mod.blocks, ...mod.models, ...mod.items, ...mod.entities]) {
|
||||
if (json.id.split(":")[0] !== id) error(`${file}: ${json.id} isn't in this mod's namespace "${id}"`);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ export async function pack_mod(mod: LoadedMod): Promise<Uint8Array<ArrayBuffer>>
|
||||
items: mod.items.map((i) => i.json),
|
||||
recipes: mod.recipes.map((r) => r.json),
|
||||
ores: mod.ores.map((o) => o.json),
|
||||
entities: mod.entities.map((e) => e.json),
|
||||
entity_models: mod.entity_models.map((m) => m.json),
|
||||
},
|
||||
scripts,
|
||||
textures,
|
||||
|
||||
Reference in New Issue
Block a user