All the stone cutter recipes
This commit is contained in:
+25
-11
@@ -9,7 +9,9 @@
|
||||
import { import_blocks } from "./importer/blocks.ts";
|
||||
import { import_items } from "./importer/items.ts";
|
||||
import { import_models } from "./importer/models.ts";
|
||||
import { import_recipes } from "./importer/recipes.ts";
|
||||
import { DEFAULT_REMAPS, type ImportOptions, type ImportReport } from "./importer/resources.ts";
|
||||
import { import_tags } from "./importer/tags.ts";
|
||||
import { import_textures } from "./importer/textures.ts";
|
||||
|
||||
const KINDS: Record<string, (input: string, options: ImportOptions) => ImportReport> = {
|
||||
@@ -17,6 +19,8 @@ const KINDS: Record<string, (input: string, options: ImportOptions) => ImportRep
|
||||
texture: import_textures,
|
||||
blockstate: import_blocks,
|
||||
item: import_items,
|
||||
tag: import_tags,
|
||||
recipe: import_recipes,
|
||||
};
|
||||
|
||||
const USAGE = `deno run -A tools/importer.ts <kind> <file or folder> [options]
|
||||
@@ -26,6 +30,10 @@ kinds:
|
||||
texture textures, with their .png.mcmeta animations
|
||||
blockstate blockstates to blocks, with their states, models and items, and placeholder mining
|
||||
item item models to items, for the items that aren't a block's
|
||||
tag tags (data/<namespace>/tags) to tags/, entries that don't exist in the mods next to --output
|
||||
made optional
|
||||
recipe recipes to recipes/, for the types bworld has: stonecutting. ones naming items or tags that
|
||||
don't exist in the mods next to --output are left out
|
||||
|
||||
options:
|
||||
--output PATH the file (for one input file) or the folder to write. one model without it is printed
|
||||
@@ -35,8 +43,10 @@ options:
|
||||
--parents FOLDER another folder to follow parent models through, like another mod's resources. can be repeated
|
||||
--remap FILE json that renames locations before they become ids, longest match first, and leaves out
|
||||
locations that match a "skip" pattern:
|
||||
{ "textures": { "minecraft:block/": "bworld:" }, "models": {}, "skip": ["crimson"] }
|
||||
minecraft's block and item textures become bworld's of the same name unless it says otherwise`;
|
||||
{ "textures": { "minecraft:block/": "bworld:" }, "models": {}, "ids": {}, "tags": {},
|
||||
"skip": ["crimson"] }
|
||||
minecraft's block and item textures, blocks, items and tags become bworld's of the same name,
|
||||
and forge's shared tags c's, unless it says otherwise`;
|
||||
|
||||
function parse_args(args: string[]) {
|
||||
const positional: string[] = [];
|
||||
@@ -56,6 +66,8 @@ function parse_args(args: string[]) {
|
||||
options.remaps = {
|
||||
textures: { ...DEFAULT_REMAPS.textures, ...remap.textures },
|
||||
models: { ...DEFAULT_REMAPS.models, ...remap.models },
|
||||
ids: { ...DEFAULT_REMAPS.ids, ...remap.ids },
|
||||
tags: { ...DEFAULT_REMAPS.tags, ...remap.tags },
|
||||
...(remap.skip ? { skip: remap.skip } : {}),
|
||||
};
|
||||
} else if (arg.startsWith("--")) throw new Error(`unknown option ${arg}`);
|
||||
@@ -67,18 +79,20 @@ function parse_args(args: string[]) {
|
||||
function print_report(report: ImportReport) {
|
||||
const [first] = report.written;
|
||||
if (report.written.length === 1 && first.file === undefined) console.log(first.text?.trimEnd());
|
||||
for (const { location, reason } of report.skipped) console.error(`skipped ${location}: ${reason}`);
|
||||
// the same reason for many files is one line
|
||||
const by_reason = (entries: { location: string; reason: string }[]) => {
|
||||
const grouped = new Map<string, string[]>();
|
||||
for (const { location, reason } of entries) grouped.set(reason, [...(grouped.get(reason) ?? []), location]);
|
||||
return [...grouped].map(([reason, locations]) =>
|
||||
`${reason} (${locations.length === 1 ? locations[0] : `${locations.length} files`})`
|
||||
);
|
||||
};
|
||||
for (const line of by_reason(report.skipped)) console.error(`skipped: ${line}`);
|
||||
for (const { location, problems } of report.errors) {
|
||||
for (const problem of problems) console.error(`error in ${location}: ${problem}`);
|
||||
}
|
||||
// the same warning about many files is one line
|
||||
const warnings = new Map<string, string[]>();
|
||||
for (const { location, warning } of report.warnings) {
|
||||
warnings.set(warning, [...(warnings.get(warning) ?? []), location]);
|
||||
}
|
||||
for (const [warning, locations] of warnings) {
|
||||
console.error(`warning: ${warning} (${locations.length === 1 ? locations[0] : `${locations.length} files`})`);
|
||||
}
|
||||
const warnings = report.warnings.map(({ location, warning }) => ({ location, reason: warning }));
|
||||
for (const line of by_reason(warnings)) console.error(`warning: ${line}`);
|
||||
const converted = new Set(report.written.map(({ location }) => location)).size;
|
||||
console.error(
|
||||
`${converted} converted, ${report.skipped.length} skipped, ${report.errors.length} with errors`,
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// java recipes (data/<namespace>/recipe/**.json, recipes/ before 1.21) to bworld's recipes/, keeping their folders.
|
||||
// each type bworld has an equivalent for is converted, the rest are reported. a recipe naming an item or tag that
|
||||
// doesn't exist here is left out, since bworld's recipes have to be complete
|
||||
import { join } from "@std/path";
|
||||
import { FORMAT_VERSION } from "$/common/mod_data.ts";
|
||||
import { known_tag, tag_id } from "./tags.ts";
|
||||
import {
|
||||
DEFAULT_REMAPS,
|
||||
empty_report,
|
||||
format_json,
|
||||
type ImportOptions,
|
||||
type ImportReport,
|
||||
input_files,
|
||||
type Known,
|
||||
known_in,
|
||||
location_of,
|
||||
location_string,
|
||||
type Remaps,
|
||||
skip_pattern,
|
||||
skips,
|
||||
to_id,
|
||||
write_report,
|
||||
} from "./resources.ts";
|
||||
|
||||
// a converted recipe, or why it can't be
|
||||
type Converted = { recipe: Record<string, unknown> } | { skipped: string } | { error: string };
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
type Json = any;
|
||||
|
||||
interface Context {
|
||||
remaps: Remaps;
|
||||
known: Known | undefined;
|
||||
}
|
||||
|
||||
const CONVERTERS: Record<string, (json: Json, context: Context) => Converted> = {
|
||||
"minecraft:stonecutting": (json, context) => {
|
||||
const input = choice(json.ingredient, context);
|
||||
if ("skipped" in input || "error" in input) return input;
|
||||
const output = stack(json.result, json.count, context);
|
||||
if ("skipped" in output || "error" in output) return output;
|
||||
return { recipe: { type: "bworld:stonecutting", input: input.choice, output: output.stack } };
|
||||
},
|
||||
};
|
||||
|
||||
export function import_recipes(input: string, options: ImportOptions = {}): ImportReport {
|
||||
if (options.output === undefined) throw new Error("--output is needed for recipes");
|
||||
const context = { remaps: options.remaps ?? DEFAULT_REMAPS, known: known_in(options.output) };
|
||||
const report = empty_report();
|
||||
if (context.known === undefined) {
|
||||
report.warnings.push({
|
||||
location: options.output,
|
||||
warning: "--output isn't in a mod, so the items and tags recipes name aren't checked",
|
||||
});
|
||||
}
|
||||
const files = input_files(input, ["recipe", "recipes"], ".json", options.namespace, options.output);
|
||||
for (const { root, file } of files) {
|
||||
const where = location_of(root, file, ".json");
|
||||
const location = location_string(where);
|
||||
if (skips(location, context.remaps, report)) continue;
|
||||
const json = JSON.parse(Deno.readTextFileSync(file));
|
||||
const conditions = Object.keys(json).find((key) => key.endsWith("conditions"));
|
||||
const convert = CONVERTERS[json.type];
|
||||
const converted: Converted = conditions
|
||||
? { skipped: `it only loads under ${conditions}, like another mod being installed` }
|
||||
: convert
|
||||
? convert(json, context)
|
||||
: { skipped: `the importer can't convert ${json.type} recipes yet` };
|
||||
if ("skipped" in converted) report.skipped.push({ location, reason: converted.skipped });
|
||||
else if ("error" in converted) report.errors.push({ location, problems: [converted.error] });
|
||||
else {
|
||||
report.written.push({
|
||||
location,
|
||||
id: location,
|
||||
file: join(options.output, `${where.path}.json`),
|
||||
text: format_json({ format_version: FORMAT_VERSION, recipe: converted.recipe }) + "\n",
|
||||
});
|
||||
}
|
||||
}
|
||||
write_report(report);
|
||||
return report;
|
||||
}
|
||||
|
||||
// an ingredient as bworld's item choice: { item } an id, { tag } a #tag, a list any of which fits
|
||||
function choice(json: Json, context: Context): { choice: string | string[] } | { skipped: string } | {
|
||||
error: string;
|
||||
} {
|
||||
const one = (entry: Json): string | { skipped: string } | { error: string } => {
|
||||
if (typeof entry?.item === "string") {
|
||||
const id = to_id(entry.item, context.remaps.ids);
|
||||
return item_problem(entry.item, id, context) ?? id;
|
||||
}
|
||||
if (typeof entry?.tag === "string") {
|
||||
const id = tag_id(entry.tag, context.remaps);
|
||||
if (skip_pattern(entry.tag, context.remaps) !== undefined) {
|
||||
return { skipped: `it takes #${entry.tag}, which the remaps skip` };
|
||||
}
|
||||
return known_tag(context.known, "items", id)
|
||||
? `#${id}`
|
||||
: { skipped: `it takes #${id}, which nobody defines` };
|
||||
}
|
||||
return { error: `an ingredient of ${JSON.stringify(entry)} isn't an item or a tag` };
|
||||
};
|
||||
const entries = (Array.isArray(json) ? json : [json]).map(one);
|
||||
const problem = entries.find((entry) => typeof entry !== "string");
|
||||
if (problem !== undefined) return problem as { skipped: string } | { error: string };
|
||||
return { choice: entries.length === 1 ? entries[0] as string : entries as string[] };
|
||||
}
|
||||
|
||||
// a result as { id, count }: { id, count } since 1.20.5, { item, count } before, and an id with the recipe's count
|
||||
// before that
|
||||
function stack(json: Json, count: unknown, context: Context): { stack: { id: string; count: number } } | {
|
||||
skipped: string;
|
||||
} | { error: string } {
|
||||
const raw = typeof json === "string" ? json : json?.id ?? json?.item;
|
||||
if (typeof raw !== "string") return { error: `its result ${JSON.stringify(json)} isn't an item` };
|
||||
const id = to_id(raw, context.remaps.ids);
|
||||
const problem = item_problem(raw, id, context);
|
||||
if (problem) return problem;
|
||||
return { stack: { id, count: (typeof json === "object" ? json.count : undefined) ?? count ?? 1 } };
|
||||
}
|
||||
|
||||
function item_problem(raw: string, id: string, context: Context): { skipped: string } | undefined {
|
||||
if (skip_pattern(raw, context.remaps) !== undefined) return { skipped: `it uses ${raw}, which the remaps skip` };
|
||||
if (context.known && !context.known.ids.items.has(id)) {
|
||||
return { skipped: `it uses ${id}, which doesn't exist here` };
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
+55
-13
@@ -4,7 +4,9 @@
|
||||
// where things are in a java mod's resources, and what they're called in bworld. a resource location like
|
||||
// "create:block/cogwheel" (or "block/stone", which is minecraft's) becomes the id "create:block_cogwheel": bworld ids
|
||||
// have no folders, so the path's folders are joined with _, the same way check_mods names textures in subfolders
|
||||
import { ID_PATTERN } from "$/common/mod_data.ts";
|
||||
import { ID_PATTERN, type TagRegistry } from "$/common/mod_data.ts";
|
||||
import { registered_ids } from "$/common/mod_check.ts";
|
||||
import { load_and_check } from "$/tools/check_mods.ts";
|
||||
import { dirname, relative, resolve, SEPARATOR } from "@std/path";
|
||||
|
||||
export interface Location {
|
||||
@@ -32,6 +34,9 @@ export type Remap = Record<string, string>;
|
||||
export interface Remaps {
|
||||
textures: Remap;
|
||||
models: Remap;
|
||||
// blocks, items, entities and biomes, where tags and recipes name them
|
||||
ids: Remap;
|
||||
tags: Remap;
|
||||
// patterns (regular expressions) for locations to leave out of every kind, like a mod's blocks for content bworld
|
||||
// doesn't have: "crimson" leaves out create:crimson_window, its models and its textures
|
||||
skip?: string[];
|
||||
@@ -40,6 +45,10 @@ export interface Remaps {
|
||||
export const DEFAULT_REMAPS: Remaps = {
|
||||
textures: { "minecraft:block/": "bworld:", "minecraft:item/": "bworld:" },
|
||||
models: template_remaps(),
|
||||
// the base game's blocks and items are named like minecraft's, and its tags too. forge's shared tags were renamed
|
||||
// c, which is what bworld calls them
|
||||
ids: { "minecraft:": "bworld:" },
|
||||
tags: { "minecraft:": "bworld:", "forge:": "c:" },
|
||||
};
|
||||
|
||||
// minecraft's template models (cube_all, stairs, walls, panes, ...) are the base game's in models/templates, which are
|
||||
@@ -74,7 +83,12 @@ export function is_valid_id(id: string): boolean {
|
||||
return ID_PATTERN.test(id);
|
||||
}
|
||||
|
||||
// a folder of one kind of resource (models, textures, ...) for one namespace: assets/<namespace>/<kind>
|
||||
// what a mod's resources are in: assets/ for what clients draw, data/ for tags, recipes and the rest
|
||||
const TOPS = ["assets", "data"];
|
||||
|
||||
// a folder of one kind of resource (models, textures, ...) for one namespace: assets/<namespace>/<kind>, or
|
||||
// data/<namespace>/<kind>. some kinds' folder was renamed between versions, like recipes to recipe, so a kind can be
|
||||
// several names
|
||||
export interface ResourceRoot {
|
||||
namespace: string;
|
||||
dir: string;
|
||||
@@ -85,15 +99,17 @@ export interface ResourceRoot {
|
||||
|
||||
// the roots of a kind inside a folder: every assets/<namespace>/<kind> under it (only namespace's, when it's given), or
|
||||
// the folder itself when it's one or is inside one. a folder that's none of those is a root of the given namespace
|
||||
export function find_roots(input: string, kind: string, namespace?: string): ResourceRoot[] {
|
||||
export function find_roots(input: string, kind: string | string[], namespace?: string): ResourceRoot[] {
|
||||
const dir = resolve(input);
|
||||
const enclosing = enclosing_root(dir, kind);
|
||||
if (enclosing) return [enclosing];
|
||||
const roots: ResourceRoot[] = [];
|
||||
for (const assets of find_dirs(dir, "assets")) {
|
||||
for (const entry of read_dir(assets)) {
|
||||
if (entry.isDirectory && is_dir(`${assets}/${entry.name}/${kind}`)) {
|
||||
roots.push({ namespace: entry.name, dir: `${assets}/${entry.name}/${kind}` });
|
||||
for (const top of TOPS.flatMap((name) => find_dirs(dir, name))) {
|
||||
for (const entry of read_dir(top)) {
|
||||
for (const name of [kind].flat()) {
|
||||
if (entry.isDirectory && is_dir(`${top}/${entry.name}/${name}`)) {
|
||||
roots.push({ namespace: entry.name, dir: `${top}/${entry.name}/${name}` });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +127,7 @@ export interface InputFile {
|
||||
// assets/ folder is the namespace's, or the mod's that output is in
|
||||
export function input_files(
|
||||
input: string,
|
||||
kind: string,
|
||||
kind: string | string[],
|
||||
extension: string,
|
||||
namespace?: string,
|
||||
output?: string,
|
||||
@@ -125,7 +141,8 @@ export function input_files(
|
||||
}
|
||||
const roots = find_roots(input, kind, namespace);
|
||||
if (roots.length === 0) {
|
||||
throw new Error(`no ${kind} in ${input}: pass --namespace when it isn't inside assets/<namespace>/${kind}`);
|
||||
const name = [kind].flat()[0];
|
||||
throw new Error(`no ${name} in ${input}: pass --namespace when it isn't inside assets/<namespace>/${name}`);
|
||||
}
|
||||
const full = resolve(input);
|
||||
return roots.flatMap((root) => {
|
||||
@@ -135,10 +152,10 @@ export function input_files(
|
||||
}
|
||||
|
||||
// the assets/<namespace>/<kind> folder a path is in, if it's in one
|
||||
export function enclosing_root(path: string, kind: string): ResourceRoot | undefined {
|
||||
export function enclosing_root(path: string, kind: string | string[]): ResourceRoot | undefined {
|
||||
const parts = resolve(path).split(SEPARATOR);
|
||||
for (let i = parts.length - 1; i >= 2; i--) {
|
||||
if (parts[i] === kind && parts[i - 2] === "assets") {
|
||||
if ([kind].flat().includes(parts[i]) && TOPS.includes(parts[i - 2])) {
|
||||
return { namespace: parts[i - 1], dir: parts.slice(0, i + 1).join(SEPARATOR) };
|
||||
}
|
||||
}
|
||||
@@ -184,14 +201,34 @@ function read_dir(dir: string): Deno.DirEntry[] {
|
||||
|
||||
// the id of the mod a path is in, from the manifest.json of the nearest folder up that has one
|
||||
export function mod_namespace(path: string): string | undefined {
|
||||
return mod_of(path)?.id;
|
||||
}
|
||||
|
||||
function mod_of(path: string): { id: string; dir: string } | undefined {
|
||||
for (let dir = dirname(resolve(path)); dir !== dirname(dir); dir = dirname(dir)) {
|
||||
if (!is_file(`${dir}/manifest.json`)) continue;
|
||||
const id = JSON.parse(Deno.readTextFileSync(`${dir}/manifest.json`)).id;
|
||||
return typeof id === "string" ? id : undefined;
|
||||
return typeof id === "string" ? { id, dir } : undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// what the mods next to the one output is in have, by registry: their blocks, items, entities and biomes, and the
|
||||
// tags their files define. undefined when output isn't in a mod
|
||||
export interface Known {
|
||||
ids: Record<TagRegistry, Set<string>>;
|
||||
tags: Record<TagRegistry, Set<string>>;
|
||||
}
|
||||
|
||||
export function known_in(output: string): Known | undefined {
|
||||
const mod = mod_of(`${output}/x`);
|
||||
if (!mod) return undefined;
|
||||
const mods = load_and_check(dirname(mod.dir));
|
||||
const tags: Known["tags"] = { blocks: new Set(), items: new Set(), entities: new Set(), biomes: new Set() };
|
||||
for (const { json } of mods.flatMap((mod) => mod.tags)) tags[json.registry].add(json.id);
|
||||
return { ids: registered_ids(mods), tags };
|
||||
}
|
||||
|
||||
export function is_file(path: string): boolean {
|
||||
try {
|
||||
return Deno.statSync(path).isFile;
|
||||
@@ -237,11 +274,16 @@ export interface ImportReport {
|
||||
|
||||
// whether the remaps leave a location out, which is reported as skipped
|
||||
export function skips(location: string, remaps: Remaps, report: ImportReport): boolean {
|
||||
const pattern = remaps.skip?.find((pattern) => new RegExp(pattern).test(location));
|
||||
const pattern = skip_pattern(location, remaps);
|
||||
if (pattern !== undefined) report.skipped.push({ location, reason: `the remaps skip "${pattern}"` });
|
||||
return pattern !== undefined;
|
||||
}
|
||||
|
||||
// the skip pattern a location matches, if any
|
||||
export function skip_pattern(location: string, remaps: Remaps): string | undefined {
|
||||
return remaps.skip?.find((pattern) => new RegExp(pattern).test(location));
|
||||
}
|
||||
|
||||
export function empty_report(): ImportReport {
|
||||
return { written: [], skipped: [], errors: [], warnings: [] };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// java tags (data/<namespace>/tags/<registry>/<path>.json) to bworld's tags/<registry>/<namespace>/<path>.json. the
|
||||
// format is the same: values, replace and remove, with { id, required: false } for entries that can be missing. tag ids
|
||||
// keep their folders, since bworld's can have them too
|
||||
import { join } from "@std/path";
|
||||
import { FORMAT_VERSION, TAG_ID_PATTERN, type TagRegistry } from "$/common/mod_data.ts";
|
||||
import {
|
||||
DEFAULT_REMAPS,
|
||||
empty_report,
|
||||
format_json,
|
||||
id_claims,
|
||||
type ImportOptions,
|
||||
type ImportReport,
|
||||
input_files,
|
||||
type Known,
|
||||
known_in,
|
||||
location_of,
|
||||
location_string,
|
||||
parse_location,
|
||||
remap_location,
|
||||
type Remaps,
|
||||
skip_pattern,
|
||||
skips,
|
||||
to_id,
|
||||
write_report,
|
||||
} from "./resources.ts";
|
||||
|
||||
// java's registry folders, by the names they've had, and bworld's for them. other registries have no tags here
|
||||
const REGISTRIES: Record<string, TagRegistry> = {
|
||||
item: "items",
|
||||
items: "items",
|
||||
block: "blocks",
|
||||
blocks: "blocks",
|
||||
entity_type: "entities",
|
||||
entity_types: "entities",
|
||||
"worldgen/biome": "biomes",
|
||||
};
|
||||
|
||||
type TagEntry = string | { id: string; required?: boolean };
|
||||
|
||||
// a java tag's id in bworld, like #forge:ingots/brass's c:ingots/brass
|
||||
export function tag_id(location: string, remaps: Remaps): string {
|
||||
const { namespace, path } = remap_location(location, remaps.tags);
|
||||
return `${namespace}:${path}`;
|
||||
}
|
||||
|
||||
export function import_tags(input: string, options: ImportOptions = {}): ImportReport {
|
||||
if (options.output === undefined) throw new Error("--output is needed for tags");
|
||||
const remaps = options.remaps ?? DEFAULT_REMAPS;
|
||||
const report = empty_report();
|
||||
const claim = id_claims(report);
|
||||
|
||||
// each tag's registry, bworld id and json, found before any is converted so they can name each other
|
||||
const tags = input_files(input, "tags", ".json", options.namespace, options.output).flatMap(({ root, file }) => {
|
||||
const where = location_of(root, file, ".json");
|
||||
const location = location_string(where);
|
||||
const folder = Object.keys(REGISTRIES).find((name) => where.path.startsWith(`${name}/`));
|
||||
if (!folder) {
|
||||
report.skipped.push({ location, reason: `bworld has no tags for ${where.path.split("/")[0]}` });
|
||||
return [];
|
||||
}
|
||||
if (skips(location, remaps, report)) return [];
|
||||
const registry = REGISTRIES[folder];
|
||||
const id = tag_id(`${where.namespace}:${where.path.slice(folder.length + 1)}`, remaps);
|
||||
return [{ location, registry, id, json: JSON.parse(Deno.readTextFileSync(file)) }];
|
||||
});
|
||||
|
||||
const known = known_in(options.output);
|
||||
const own = new Set(tags.map(({ registry, id }) => `${registry} ${id}`));
|
||||
for (const { location, registry, id, json } of tags) {
|
||||
if (!TAG_ID_PATTERN.test(id)) {
|
||||
report.errors.push({ location, problems: [`its id ${id} isn't a valid tag id`] });
|
||||
continue;
|
||||
}
|
||||
if (!claim(`${registry} ${id}`, location)) continue;
|
||||
const missing: string[] = [];
|
||||
const exists = (entry: string) =>
|
||||
entry.startsWith("#")
|
||||
? own.has(`${registry} ${entry.slice(1)}`) || known_tag(known, registry, entry.slice(1))
|
||||
: known === undefined || known.ids[registry].has(entry);
|
||||
const convert = (entries: TagEntry[] | undefined, remove: boolean) =>
|
||||
entries?.flatMap((entry): TagEntry[] => {
|
||||
const raw = typeof entry === "string" ? entry : entry.id;
|
||||
// what's skipped is left out of tags too, like a wood bworld won't have
|
||||
if (skip_pattern(raw.replace(/^#/, ""), remaps) !== undefined) return [];
|
||||
const converted = raw.startsWith("#") ? `#${tag_id(raw.slice(1), remaps)}` : to_id(raw, remaps.ids);
|
||||
const required = !remove && (typeof entry === "string" || entry.required !== false);
|
||||
if (!required || exists(converted)) {
|
||||
return [typeof entry === "string" || remove ? converted : { ...entry, id: converted }];
|
||||
}
|
||||
// kept for when it's added, the way a tag names another mod's item that may not be installed
|
||||
missing.push(converted);
|
||||
return [{ id: converted, required: false }];
|
||||
});
|
||||
const values = convert(json.values, false) ?? [];
|
||||
const remove = convert(json.remove, true);
|
||||
if (missing.length > 0) {
|
||||
report.warnings.push({
|
||||
location,
|
||||
warning: `${missing.join(", ")} ${missing.length === 1 ? "doesn't" : "don't"} exist here, so ${
|
||||
missing.length === 1 ? "it's" : "they're"
|
||||
} optional`,
|
||||
});
|
||||
}
|
||||
const { namespace, path } = parse_location(id);
|
||||
report.written.push({
|
||||
location,
|
||||
id,
|
||||
file: join(options.output, registry, namespace, `${path}.json`),
|
||||
text: format_json({
|
||||
format_version: FORMAT_VERSION,
|
||||
tag: { ...(json.replace ? { replace: true } : {}), values, ...(remove?.length ? { remove } : {}) },
|
||||
}) + "\n",
|
||||
});
|
||||
}
|
||||
write_report(report);
|
||||
return report;
|
||||
}
|
||||
|
||||
// whether a tag exists in the mods output is next to. without them, every tag is taken to
|
||||
export function known_tag(known: Known | undefined, registry: TagRegistry, id: string): boolean {
|
||||
return known === undefined || known.tags[registry].has(id);
|
||||
}
|
||||
Reference in New Issue
Block a user