-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderchest
executable file
·57 lines (47 loc) · 2.44 KB
/
renderchest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/php
<?php
require_once 'vendor/autoload.php';
use Aternos\Renderchest\Output\AsyncItemLibraryGenerator;
use Aternos\Renderchest\Output\ItemLibraryGenerator;
use Garden\Cli\Cli;
$cli = new Cli();
$cli->description("Generate icons and css for Minecraft items.")
->opt("assets:a", "Assets folder to use. Multiple assets folders are possible, " .
"but a base assets folder extracted from the Minecraft jar should always be included.", true, "string[]")
->opt("namespace:n", "Asset namespace that the items should be rendered from. Default: minecraft", false, "string[]")
->opt("size:s", "Size of the generated item icons. Default: 64", false, "integer")
->opt("quality:q", "When generating very small icons, small issues (like z-fighting of faces close to each other) can occur. " .
"This option allows rendering images in a higher resolution and scaling them down for the final icon. Default: 2", false, "integer")
->opt("item-list:i", "Create a JSON file containing the names of all rendered items.", false, "boolean")
->opt("output:o", "Output directory", true)
->opt("prefix:p", "Prefix to use for CSS classes. Default: rc-")
->opt("format:f", "Output image format. Default: webp")
->opt("fallback", "Create a set of fallback textures as PNGs. Default: false", false, "boolean");
function resolvePath($path)
{
if (!str_starts_with($path, "/")) {
$path = getcwd() . "/" . $path;
}
return $path;
}
function onProgress($i, $total, $name, $success, $errorMessage): void
{
if ($success) {
echo "Rendered item " . ($i + 1) . "/" . $total . ": " . $name . PHP_EOL;
} else {
echo "Failed to render item " . ($i + 1) . "/" . $total . ": " . $name . ($errorMessage ? " (" . $errorMessage . ")" : "") . PHP_EOL;
}
}
$args = $cli->parse($argv);
$output = resolvePath($args->getOpt("output"));
$assets = array_map(resolvePath(...), $args->getOpt("assets"));
$libraryGenerator = new ItemLibraryGenerator($assets, $output);
$libraryGenerator->setNamespaces($args->getOpt("namespace", ["minecraft"]))
->setSize($args->getOpt("size", 64))
->setQuality($args->getOpt("quality", 2))
->setCreateItemList($args->getOpt("item-list", false))
->setPrefix($args->getOpt("prefix", "rc-"))
->setFormat($args->getOpt("format", "webp"))
->setCreatePngFallback($args->getOpt("fallback", false))
->render(onProgress(...));
echo "Saved stylesheet and textures to " . $output . "\n";