Animated textures !
This commit is contained in:
+22
-4
@@ -19,6 +19,7 @@ import {
|
||||
} 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";
|
||||
import { type TextureJson, validate_texture_json } from "$/common/texture_animation.ts";
|
||||
import { dirname } from "@std/path";
|
||||
|
||||
export { load_order, type LoadedMod, type ModReport };
|
||||
@@ -81,6 +82,7 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
tags: [],
|
||||
textures: [],
|
||||
texture_files: new Map(),
|
||||
texture_json: new Map(),
|
||||
};
|
||||
const error = (message: string) => mod.report.errors.push(message);
|
||||
|
||||
@@ -214,11 +216,27 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
mod.textures.push(texture_id);
|
||||
mod.texture_files.set(texture_id, `${dir}/textures/${file}`);
|
||||
const size = png_size(Deno.readFileSync(`${dir}/textures/${file}`));
|
||||
if (!size) {
|
||||
error(`textures/${file}: isn't a png`);
|
||||
} else if (texture_size_problem(size)) {
|
||||
error(`textures/${file}: ${texture_size_problem(size)}`);
|
||||
if (!size) error(`textures/${file}: isn't a png`);
|
||||
}
|
||||
for (const file of walk(`${dir}/textures`, ".json")) {
|
||||
const texture_id = `${id}:${file.replace(/\.json$/, "").replaceAll("/", "_")}`;
|
||||
const png = mod.texture_files.get(texture_id);
|
||||
if (!png) {
|
||||
error(`textures/${file}: there's no ${file.replace(/\.json$/, ".png")} for it to go with`);
|
||||
continue;
|
||||
}
|
||||
const json = read_json(`${dir}/textures/${file}`, (message) => error(`textures/${file}: ${message}`));
|
||||
const size = png_size(Deno.readFileSync(png));
|
||||
if (json === undefined || !size) continue;
|
||||
const problems = validate_texture_json(json, size);
|
||||
for (const problem of problems) error(`textures/${file}: ${problem}`);
|
||||
if (problems.length === 0) mod.texture_json.set(texture_id, json as TextureJson);
|
||||
}
|
||||
// once it's known which are animated, their frames are what has to fit
|
||||
for (const [texture_id, path] of mod.texture_files) {
|
||||
const size = png_size(Deno.readFileSync(path));
|
||||
const problem = size && texture_size_problem(size, mod.texture_json.get(texture_id));
|
||||
if (problem) error(`${path.slice(dir.length + 1)}: ${problem}`);
|
||||
}
|
||||
|
||||
return mod;
|
||||
|
||||
@@ -27,6 +27,7 @@ export async function pack_mod(mod: LoadedMod): Promise<Uint8Array<ArrayBuffer>>
|
||||
for (const [id, path] of [...mod.texture_files].sort(([a], [b]) => a.localeCompare(b))) {
|
||||
textures.set(id, Deno.readFileSync(path));
|
||||
}
|
||||
const texture_json = new Map([...mod.texture_json].sort(([a], [b]) => a.localeCompare(b)));
|
||||
|
||||
return write_bmod({
|
||||
manifest,
|
||||
@@ -44,6 +45,7 @@ export async function pack_mod(mod: LoadedMod): Promise<Uint8Array<ArrayBuffer>>
|
||||
},
|
||||
scripts,
|
||||
textures,
|
||||
texture_json,
|
||||
credits: manifest.credits ? Deno.readTextFileSync(`${mod.dir}/${manifest.credits}`) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user