Add all textures and models from create

This commit is contained in:
2026-10-12 18:47:41 -03:00
parent d4eff11f3e
commit 99bdcaeffc
3775 changed files with 66614 additions and 58 deletions
+24 -6
View File
@@ -31,6 +31,9 @@ export type Remap = Record<string, string>;
export interface Remaps {
textures: Remap;
models: 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[];
}
export const DEFAULT_REMAPS: Remaps = {
@@ -209,6 +212,13 @@ export interface ImportReport {
warnings: { location: string; warning: string }[];
}
// 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));
if (pattern !== undefined) report.skipped.push({ location, reason: `the remaps skip "${pattern}"` });
return pattern !== undefined;
}
export function empty_report(): ImportReport {
return { written: [], skipped: [], errors: [], warnings: [] };
}
@@ -240,20 +250,28 @@ export function write_report(report: ImportReport) {
}
}
// json in the style of the repo's data files: tabs, and short lists and objects of plain values on one line
export function format_json(value: unknown, indent = ""): string {
// how wide deno fmt lets a line be, with a tab as 4 columns, see deno.json
const LINE_WIDTH = 120;
const TAB_WIDTH = 4;
// json in the style of the repo's data files, the way deno fmt leaves it: tabs, and short lists and objects of plain
// values on one line when the whole line fits. indent is the line it starts on, after prefix (like a key) on that line
export function format_json(value: unknown, indent = "", prefix = 0): string {
if (value === null || typeof value !== "object") return JSON.stringify(value);
const entries = Array.isArray(value)
? value.map((v) => format_json(v, indent + "\t"))
: Object.entries(value).filter(([, v]) => v !== undefined).map(([k, v]) =>
`${JSON.stringify(k)}: ${format_json(v, indent + "\t")}`
);
: Object.entries(value).filter(([, v]) => v !== undefined).map(([k, v]) => {
const key = `${JSON.stringify(k)}: `;
return key + format_json(v, indent + "\t", key.length);
});
const [open, close] = Array.isArray(value) ? ["[", "]"] : ["{", "}"];
if (entries.length === 0) return open + close;
const flat = Object.values(value).every((v) =>
v === null || typeof v !== "object" || (Array.isArray(v) && v.every((x) => x === null || typeof x !== "object"))
);
const one_line = Array.isArray(value) ? `[${entries.join(", ")}]` : `{ ${entries.join(", ")} }`;
if (flat && !one_line.includes("\n") && indent.length * 4 + one_line.length <= 100) return one_line;
// and a comma after it
const width = indent.length * TAB_WIDTH + prefix + one_line.length + 1;
if (flat && !one_line.includes("\n") && width <= LINE_WIDTH) return one_line;
return `${open}\n${entries.map((e) => indent + "\t" + e).join(",\n")}\n${indent}${close}`;
}