Loading schematics
This commit is contained in:
@@ -28,6 +28,7 @@ import { check_references, load_order, type LoadedMod, type ModReport } from "@/
|
||||
import { data_url, png_size, texture_size_problem } from "@/common/mod.ts";
|
||||
import { type TextureJson, validate_texture_json } from "@/common/texture_animation.ts";
|
||||
import { type LootTableJson, validate_loot_table } from "@/common/loot.ts";
|
||||
import { decode_schematic, type Schematic, SCHEMATIC_EXTENSION, validate_schematic } from "@/common/schematic.ts";
|
||||
import { validate_biome } from "@/common/worldgen/biomes.ts";
|
||||
import {
|
||||
validate_biome_source,
|
||||
@@ -141,6 +142,7 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
biome_sources: [],
|
||||
dimensions: [],
|
||||
features: [],
|
||||
schematics: [],
|
||||
textures: [],
|
||||
texture_files: new Map(),
|
||||
texture_json: new Map(),
|
||||
@@ -272,6 +274,22 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
});
|
||||
}
|
||||
|
||||
// schematics/<name>.cbsm is the schematic <mod id>:<name>
|
||||
for (const file of walk(`${dir}/schematics`, SCHEMATIC_EXTENSION)) {
|
||||
const path = `schematics/${file}`;
|
||||
let schematic: Schematic;
|
||||
try {
|
||||
schematic = decode_schematic(Deno.readFileSync(`${dir}/${path}`));
|
||||
} catch (e) {
|
||||
error(`${path}: ${(e as Error).message}`);
|
||||
continue;
|
||||
}
|
||||
const json = { ...schematic, id: `${id}:${file.slice(0, -SCHEMATIC_EXTENSION.length)}` };
|
||||
const problems = validate_schematic(json);
|
||||
for (const problem of problems) error(`${path}: ${problem}`);
|
||||
if (problems.length === 0) mod.schematics.push({ file: path, json });
|
||||
}
|
||||
|
||||
if (exists(`${dir}/config.json`)) {
|
||||
mod.config = read_data("config.json", "config", json_object, "{ ... }");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user