Implement tags !
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
entity_model_from_geo,
|
||||
FORMAT_VERSION,
|
||||
OreJson,
|
||||
type TagJson,
|
||||
validate_block,
|
||||
validate_entity,
|
||||
validate_item,
|
||||
@@ -11,6 +12,7 @@ import {
|
||||
validate_model,
|
||||
validate_ore,
|
||||
validate_recipe,
|
||||
validate_tag,
|
||||
} from "$/common/mod_data.ts";
|
||||
import { check_references, load_order, type LoadedMod, type ModReport } from "$/common/mod_check.ts";
|
||||
import { png_size, texture_size_problem } from "$/common/bmod.ts";
|
||||
@@ -70,6 +72,7 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
ores: [],
|
||||
entities: [],
|
||||
entity_models: [],
|
||||
tags: [],
|
||||
textures: [],
|
||||
texture_files: new Map(),
|
||||
};
|
||||
@@ -133,6 +136,26 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
if (model) mod.entity_models.push({ file: path, json: model });
|
||||
}
|
||||
|
||||
// tags/<registry>/<namespace>/<path>.json is the tag <namespace>:<path>, in any namespace: tags are shared
|
||||
for (const file of walk(`${dir}/tags`, ".json")) {
|
||||
const path = `tags/${file}`;
|
||||
const wrapper = read_json(`${dir}/${path}`, (m) => error(`${path}: ${m}`));
|
||||
if (wrapper === undefined) continue;
|
||||
const [registry, namespace, ...rest] = file.replace(/\.json$/, "").split("/");
|
||||
if (rest.length === 0) {
|
||||
error(`${path}: tag files go in tags/<registry>/<namespace>/, like tags/items/${id}/things.json`);
|
||||
continue;
|
||||
}
|
||||
if (!is_object(wrapper) || wrapper.format_version !== FORMAT_VERSION || !is_object(wrapper.tag)) {
|
||||
error(`${path}: must be { "format_version": ${FORMAT_VERSION}, "tag": { "values": [ ... ] } }`);
|
||||
continue;
|
||||
}
|
||||
const json = { ...wrapper.tag, registry, id: `${namespace}:${rest.join("/")}` };
|
||||
const problems = validate_tag(json);
|
||||
for (const problem of problems) error(`${path}: ${problem}`);
|
||||
if (problems.length === 0) mod.tags.push({ file: path, json: json as TagJson });
|
||||
}
|
||||
|
||||
if (exists(`${dir}/worldgen/ores.json`)) {
|
||||
const ores = read_json(`${dir}/worldgen/ores.json`, (m) => error(`worldgen/ores.json: ${m}`));
|
||||
if (!is_object(ores) || ores.format_version !== FORMAT_VERSION || !Array.isArray(ores.ores)) {
|
||||
|
||||
@@ -33,6 +33,7 @@ export async function pack_mod(mod: LoadedMod): Promise<Uint8Array<ArrayBuffer>>
|
||||
ores: mod.ores.map((o) => o.json),
|
||||
entities: mod.entities.map((e) => e.json),
|
||||
entity_models: mod.entity_models.map((m) => m.json),
|
||||
tags: mod.tags.map((t) => t.json),
|
||||
},
|
||||
scripts,
|
||||
textures,
|
||||
|
||||
Reference in New Issue
Block a user