tiny-adventure / commits / 1d85f0d
Add generated textures, icons and asset script
Co-Authored-By: Claude Sonnet 5.5
@@ -0,0 +1,59 @@
1+#!/usr/bin/env bash
2+set -euo pipefail
3+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
4+OUT="$ROOT/web/assets"
5+MODEL="${ASSET_MODEL:-google/gemini-2.5-flash-image}"
6+set -a; . "$ROOT/.env"; set +a
7+: "${OPENROUTER_API_KEY:?missing}"
8+mkdir -p "$OUT"
9+
10+STYLE="hand-painted stylized fantasy tabletop game art, low-poly friendly, soft painterly shading, muted rich palette, no text, no watermark, no border"
11+TILE="Seamless tileable top-down texture, flat even lighting, no perspective, fills entire square frame, edge-to-edge pattern. $STYLE. Subject: "
12+ASSETS=(
13+"tex_grass|${TILE}lush meadow grass with tiny clover and flowers"
14+"tex_dirt|${TILE}packed brown dirt path with pebbles"
15+"tex_stone|${TILE}grey cobblestone rocky ground"
16+"tex_water|${TILE}deep blue fantasy water with gentle ripples and light caustics"
17+"tex_sand|${TILE}warm beige beach sand with subtle ripples"
18+"tex_snow|${TILE}white snow with pale blue shadows and sparkles"
19+"tex_dungeon|${TILE}dark dungeon flagstone floor with cracks and moss"
20+"tex_wood|${TILE}weathered wooden plank boards with nails"
21+"ui_parchment|Aged parchment paper panel texture with darker burnt edges and a subtle ornate dark-brown frame, flat front view, empty center for UI. $STYLE"
22+"icons_items|A 4x4 grid sheet of 16 distinct fantasy RPG item icons (sword, axe, bow, staff, shield, helmet, armor, boots, ring, amulet, potion, scroll, key, gold coins, gem, torch), each in its own equal square cell, plain dark slate background, consistent painterly style, no text. $STYLE"
23+"icons_abilities|A 4x4 grid sheet of 16 distinct fantasy RPG ability icons (fireball, heal cross, lightning bolt, ice shard, poison skull, shield bash, power strike, arrow volley, stealth dagger, holy light, summon, curse, whirlwind, battle cry, earth spike, wind gust), each in its own equal square cell, plain dark slate background, consistent painterly style, no text. $STYLE"
24+)
25+
26+gen() {
27+ local name="${1%%|*}" prompt="${1#*|}" f="$OUT/${1%%|*}.png" tmp
28+ if [ -z "${FORCE:-}" ] && file "$f" 2>/dev/null | grep -q 'PNG image'; then echo "skip $name (exists)"; return 0; fi
29+ tmp="$(mktemp)"
30+ for try in 1 2 3; do
31+ jq -n --arg m "$MODEL" --arg p "$prompt" '{model:$m,modalities:["image","text"],messages:[{role:"user",content:$p}]}' |
32+ curl -sS --max-time 180 https://openrouter.ai/api/v1/chat/completions \
33+ -H "Authorization: Bearer $OPENROUTER_API_KEY" -H 'Content-Type: application/json' -d @- 2>/dev/null |
34+ jq -r '.choices[0].message.images[0].image_url.url // empty' | sed 's/^data:[^,]*,//' | base64 -d > "$tmp" 2>/dev/null || true
35+ if file "$tmp" | grep -q 'PNG image'; then mv "$tmp" "$f"; chmod 644 "$f"; echo "ok $name"; return 0; fi
36+ echo "retry $name ($try)"
37+ done
38+ rm -f "$tmp"; echo "FAIL $name"
39+}
40+export -f gen; export OUT MODEL OPENROUTER_API_KEY FORCE
41+
42+printf '%s\n' "${ASSETS[@]}" | xargs -P 4 -I{} bash -c 'gen "$1"' _ {}
43+
44+{
45+ echo '{'
46+ first=1
47+ for a in "${ASSETS[@]}"; do
48+ n="${a%%|*}"
49+ if file "$OUT/$n.png" 2>/dev/null | grep -q 'PNG image'; then
50+ kind=texture; case "$n" in ui_*) kind=ui;; icons_*) kind=icons;; esac
51+ [ $first = 1 ] || echo ','
52+ first=0
53+ printf ' "%s": {"file": "%s.png", "type": "%s"%s}' "$n" "$n" "$kind" "$([ $kind = icons ] && echo ', "grid": 4' || ([ $kind = texture ] && echo ', "tileable": true'))"
54+ fi
55+ done
56+ echo; echo '}'
57+} > "$OUT/manifest.json"
58+jq . "$OUT/manifest.json" >/dev/null
59+echo "manifest: $(jq 'length' "$OUT/manifest.json") assets"
Binary file, not shown.
Binary file, not shown.
@@ -0,0 +1,13 @@
1+{
2+ "tex_grass": {"file": "tex_grass.png", "type": "texture", "tileable": true},
3+ "tex_dirt": {"file": "tex_dirt.png", "type": "texture", "tileable": true},
4+ "tex_stone": {"file": "tex_stone.png", "type": "texture", "tileable": true},
5+ "tex_water": {"file": "tex_water.png", "type": "texture", "tileable": true},
6+ "tex_sand": {"file": "tex_sand.png", "type": "texture", "tileable": true},
7+ "tex_snow": {"file": "tex_snow.png", "type": "texture", "tileable": true},
8+ "tex_dungeon": {"file": "tex_dungeon.png", "type": "texture", "tileable": true},
9+ "tex_wood": {"file": "tex_wood.png", "type": "texture", "tileable": true},
10+ "ui_parchment": {"file": "ui_parchment.png", "type": "ui"},
11+ "icons_items": {"file": "icons_items.png", "type": "icons", "grid": 4},
12+ "icons_abilities": {"file": "icons_abilities.png", "type": "icons", "grid": 4}
13+}
Binary file, not shown.
Binary file, not shown.
Binary file, not shown.
Binary file, not shown.
Binary file, not shown.
Binary file, not shown.
Binary file, not shown.
Binary file, not shown.
Binary file, not shown.