Block registry api
This commit is contained in:
@@ -81,9 +81,9 @@ function processing(json: Json, context: Context): Converted {
|
||||
};
|
||||
}
|
||||
|
||||
export function import_recipes(input: string, options: ImportOptions = {}): ImportReport {
|
||||
export async function import_recipes(input: string, options: ImportOptions = {}): Promise<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 context = { remaps: options.remaps ?? DEFAULT_REMAPS, known: await known_in(options.output) };
|
||||
const report = empty_report();
|
||||
if (context.known === undefined) {
|
||||
report.warnings.push({
|
||||
|
||||
@@ -221,10 +221,10 @@ export interface Known {
|
||||
tags: Record<TagRegistry, Set<string>>;
|
||||
}
|
||||
|
||||
export function known_in(output: string): Known | undefined {
|
||||
export async function known_in(output: string): Promise<Known | undefined> {
|
||||
const mod = mod_of(`${output}/x`);
|
||||
if (!mod) return undefined;
|
||||
const mods = load_and_check(dirname(mod.dir));
|
||||
const mods = await 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 };
|
||||
|
||||
@@ -47,7 +47,7 @@ export function tag_id(location: string, remaps: Remaps): string {
|
||||
return `${namespace}:${path}`;
|
||||
}
|
||||
|
||||
export function import_tags(input: string, options: ImportOptions = {}): ImportReport {
|
||||
export async function import_tags(input: string, options: ImportOptions = {}): Promise<ImportReport> {
|
||||
if (options.output === undefined) throw new Error("--output is needed for tags");
|
||||
const remaps = options.remaps ?? DEFAULT_REMAPS;
|
||||
const report = empty_report();
|
||||
@@ -68,7 +68,7 @@ export function import_tags(input: string, options: ImportOptions = {}): ImportR
|
||||
return [{ location, registry, id, json: JSON.parse(Deno.readTextFileSync(file)) }];
|
||||
});
|
||||
|
||||
const known = known_in(options.output);
|
||||
const known = await 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)) {
|
||||
|
||||
Reference in New Issue
Block a user