Skip to content

Commit

Permalink
ci: Added resize script
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonjgardner committed Feb 20, 2024
1 parent 42dc4b4 commit 6e12db4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/scripts/resize.ts
@@ -0,0 +1,44 @@
import sharp from "sharp";
import { mkdir, readdir } from "node:fs/promises";
import { basename, dirname, join, resolve } from "node:path";

const ROOT_DIR = resolve(import.meta.dirname, "../../../");
const TEXTURES_DIR = join(ROOT_DIR, "bedrock/pack/RP/textures/blocks");
const DIST_DIR = join(ROOT_DIR, "build");
const SIZES: number[] = [64, 128, 256];

const files = await readdir(TEXTURES_DIR, { recursive: true });

for (const size of SIZES) {
const dir = join(DIST_DIR, `${size}x`, "textures/blocks");
await mkdir(dir, { recursive: true });

for (const file of files) {
if (file.endsWith(".tga")) {
console.log(`Skipping ${file}`);
continue;
}

const subdir = dirname(file.replace(TEXTURES_DIR, ""));

if (subdir !== "") {
await mkdir(join(dir, subdir), { recursive: true });
}

const dest = Bun.file(join(dir, subdir, basename(file)));
const src = Bun.file(join(TEXTURES_DIR, file));

if (file.endsWith(".json")) {
await Bun.write(dest, src);
continue;
}

if (file.endsWith(".png")) {
const buffer = await sharp(await src.arrayBuffer()).resize(size, null)
.toBuffer();

await Bun.write(dest, buffer);
continue;
}
}
}

0 comments on commit 6e12db4

Please sign in to comment.