Incorporate the supplied item card artwork and lore

This commit is contained in:
unimatrixgit 2026-11-28 17:00:13 +01:00
commit 68cf12ab4d
2 changed files with 742 additions and 22 deletions

View file

@ -0,0 +1,105 @@
"""Build atlas pages and the Jarvis glyph index from the approved item-card artwork."""
import json
from pathlib import Path
from PIL import Image, ImageDraw, ImageFilter
ROOT = Path(__file__).resolve().parents[1]
ART = ROOT / "docs/design/item-card/banner-art-source.png"
RESOURCE = ROOT / "JarvisConnector/src/main/resources"
SHARED = ROOT / "network/resource-pack/shared/assets/dunerealms"
ICONS = ROOT / "website/web/assets/minecraft-items"
NATIVE_ICONS = ROOT / "DuneResourcePack/assets/dunerealms/textures/item"
QUALITIES = {
"common": "#ffffff", "uncommon": "#55ff55", "rare": "#5555ff",
"very_rare": "#aa00aa", "legendary": "#ffaa00", "mythic": "#ff55ff",
"relic": "#fff2b0",
}
GOLD = "#e5b95e"
WIDTH, HEIGHT = 480, 72
COLUMNS, ROWS = 4, 16
def bitmap(file, chars):
return {"type": "bitmap", "file": "dunerealms:gui/card-art/" + file,
"height": 24, "ascent": 20, "chars": chars}
def tile(scene, source=None, quality="common"):
banner = scene.copy()
if source is None:
return banner
socket = (415, 8, 469, 62)
mask = Image.new("L", banner.size)
ImageDraw.Draw(mask).rounded_rectangle(socket, radius=13, fill=160)
glow = Image.new("RGBA", banner.size, QUALITIES[quality])
glow.putalpha(mask.filter(ImageFilter.GaussianBlur(11)))
banner.alpha_composite(glow)
draw = ImageDraw.Draw(banner)
draw.rounded_rectangle(socket, radius=13, fill="#102a23", outline=GOLD, width=2)
draw.rounded_rectangle((418, 11, 466, 59), radius=11, outline=QUALITIES[quality], width=1)
with Image.open(source) as pic:
icon = pic.convert("RGBA")
icon = icon.crop(icon.getbbox()) if icon.getbbox() else icon
scale = 38 / max(icon.size)
icon = icon.resize((max(1, round(icon.width*scale)), max(1, round(icon.height*scale))),
Image.Resampling.NEAREST)
banner.alpha_composite(icon, (442-icon.width//2, 35-icon.height//2))
return banner
def main():
(ROOT / "website/web/assets/item-card-banner.png").write_bytes(ART.read_bytes())
raw = json.loads((RESOURCE / "item-templates.json").read_text(encoding="utf8"))
sources = {}
for path in sorted(NATIVE_ICONS.rglob("*.png")) + sorted((SHARED / "textures/item").rglob("*.png")):
root = SHARED / "textures/item" if path.is_relative_to(SHARED) else NATIVE_ICONS
key = path.relative_to(root).with_suffix("").as_posix()
sources["dunerealms:" + key] = (path, "common")
for template_id, template in sorted(raw["templates"].items()):
material = template.get("material", "").lower()
quality = template.get("quality")
if quality not in QUALITIES or not (ICONS / (material + ".png")).is_file():
continue
path = sources.get("dunerealms:" + template_id.removeprefix("dr_"), (ICONS / (material + ".png"), quality))[0]
sources[template_id] = (path, quality)
sources.setdefault("minecraft:" + material + "/" + quality, (path, quality))
sources["minecraft:diamond_shovel/mythic"] = (ICONS / "diamond_shovel.png", "mythic")
scene = Image.open(ART).convert("RGBA").resize((WIDTH, HEIGHT), Image.Resampling.LANCZOS)
alpha = Image.new("L", scene.size)
ImageDraw.Draw(alpha).rounded_rectangle((0, 0, WIDTH-1, HEIGHT+8), radius=10, fill=255)
scene.putalpha(alpha)
output = SHARED / "textures/gui/card-art"
output.mkdir(parents=True, exist_ok=True)
generic = output / "generic.png"
scene.save(generic, optimize=True)
providers = [bitmap(generic.name, ["\ue000"])]
images, index = {}, {"generic": 0xE000}
for key, (path, quality) in sorted(sources.items()):
image_key = path, quality
if image_key not in images:
images[image_key] = 0xE100 + len(images)
index[key] = images[image_key]
if images and max(images.values()) > 0xF8FF:
raise ValueError("Item card font exceeds the private-use block")
ordered = list(images)
for start in range(0, len(images), COLUMNS*ROWS):
group = ordered[start:start+COLUMNS*ROWS]
page = Image.new("RGBA", (WIDTH*COLUMNS, HEIGHT*((len(group)+COLUMNS-1)//COLUMNS)))
chars = []
for row in range(0, len(group), COLUMNS):
line = ""
for col, (path, quality) in enumerate(group[row:row+COLUMNS]):
page.paste(tile(scene, path, quality), (col*WIDTH, row//COLUMNS*HEIGHT))
line += chr(images[(path, quality)])
chars.append(line.ljust(COLUMNS, "\0"))
file = f"atlas-{start//(COLUMNS*ROWS):02}.png"
page.save(output / file, optimize=True)
providers.append(bitmap(file, chars))
font = SHARED / "font/card_art.json"
font.write_text(json.dumps({"providers": providers}, separators=(",", ":"))+"\n", encoding="utf8", newline="\n")
(RESOURCE / "item-card-glyphs.json").write_text(json.dumps(index, indent=2)+"\n", encoding="utf8", newline="\n")
print(f"{len(images)} art glyphs, {len(index)-1} item keys")
if __name__ == "__main__":
main()

View file

@ -226,3 +226,27 @@ test('every official Dunemark piece has a complete central-pack model and textur
assert.equal(png.readUInt32BE(20),64);
}
});
test('item-card atlas cells and the runtime glyph index agree',()=>{
const assets=new URL('../network/resource-pack/shared/assets/dunerealms/',import.meta.url);
const providers=JSON.parse(fs.readFileSync(new URL('font/card_art.json',assets))).providers;
const index=JSON.parse(fs.readFileSync(new URL('../JarvisConnector/src/main/resources/item-card-glyphs.json',import.meta.url)));
assert.equal(index.generic,0xe000);
const codepoints=new Set();
for(const {file,chars,height} of providers){
assert.equal(height,24);
const png=fs.readFileSync(new URL('textures/'+file.split(':')[1],assets));
assert.equal(png.readUInt32BE(16),480*chars[0].length);
assert.equal(png.readUInt32BE(20),72*chars.length);
for(const glyph of chars.join(''))if(glyph!=='\0'){
const point=glyph.codePointAt(0);
assert(!codepoints.has(point));
codepoints.add(point);
}
}
assert.deepEqual(new Set(Object.values(index)),codepoints);
assert(index['dunerealms:spy_module']>=0xe100);
assert(index['minecraft:diamond_shovel/mythic']>=0xe100);
const approved=fs.readFileSync(new URL('../docs/design/item-card/banner-art-source.png',import.meta.url));
assert.deepEqual(fs.readFileSync(new URL('../website/web/assets/item-card-banner.png',import.meta.url)),approved);
});