-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
42e83d0
commit 8c42c8f
Showing
1 changed file
with
35 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,35 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Rasterize svg objects | ||
SVGS="ports.svg duke.svg xmu.svg" | ||
PNGS="" | ||
for image in $SVGS; do | ||
for obj in $(inkscape --query-all $image | grep -oP "obj_\w+"); do | ||
outfile=${obj}.png | ||
inkscape --export-id-only --export-id=$obj --export-filename=$outfile $image | ||
PNGS="$PNGS $outfile" | ||
done | ||
done | ||
|
||
# Build texture atlas | ||
# pip install https://github.com/mborgerson/textureatlas/archive/refs/heads/master.zip | ||
python -m textureatlas -o ui_objs.png -m ui_objs.json -mf=json $PNGS | ||
|
||
# Build accessory structs | ||
python <<EOF >ui_objs.h | ||
import json | ||
with open("ui_objs.json", "r", encoding="utf-8") as file: | ||
atlas = json.load(file) | ||
print("const struct { int x, y, w, h; } ui_objs[] = {") | ||
names = [] | ||
for name, frames in atlas.items(): | ||
for x, y, w, h in frames: | ||
print(" {%4d, %4d, %4d, %4d}, // %s" % (x, y, w, h, name)) | ||
names.append(name) | ||
print("};") | ||
print("enum ui_objs_idx {") | ||
for idx, name in enumerate(names): | ||
print(f" ui_{name}_idx = {idx},") | ||
print("};") | ||
EOF |