Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42dc4b4
commit 6e12db4
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |