election-game/art/icon/render-icons.sh

37 lines
1.9 KiB
Bash
Raw Permalink Normal View History

選戰卡牌第五版:趕場、政見支票、資源瘦身、新主畫面圖示、修 Bug 資源與載入(docs/27 第 1 節):首頁下載 8.7 → 1.6 MB、載入畫面 4.4 → 1.5 秒,進一局 5.0 → 1.3 MB - 中文字型切成 unicode-range 小片,照畫面出現的頻率排(art/fonts/split-webfonts.py),拿掉 Google Fonts; canvas 上的字(3D 看板、名牌、分享圖)字型片載好再畫一次(ui/canvasFont.ts) - 3D 模型 meshopt 壓縮、只留用到的動作(art/optimize-3d.mjs、game/gltf.ts),5.5 → 1.0 MB - 卡圖 320 px 小圖+srcset(art/cards-small.sh);木紋貼圖縮小;背景音樂改 Opus 96 kbps(art/music-opus.sh) - 新增 GET /api/scenarios/list 只回大廳用到的欄位(1.52 → 0.44 MB);伺服器沒有這條路由時前端改抓舊的清單 玩法(docs/27 第 2–4 節,研究桌遊機制後挑兩個做): - 趕場(推運氣):每週可以翻牌庫頂的牌免費打,越翻越容易翻車(POST /api/rogue/runs/:id/overtime) - 政見支票(藏起來的長期目標):第 1 週開跑記者會三選一或不開,開票時兌現全市加票、跳票掉票 新主畫面圖示:重畫投票箱(art/icon/icon.svg、render-icons.sh),apple-touch 滿版不透明,加 Android maskable 修 Bug: - 舊版伺服器沒有新路由時,首頁、政治生涯的紅色「Not Found」改成照樣能用;版本對不上時寫中文說明 - 捏人物「存起來,去政治生涯」直接選好剛捏的角色、跳到選家鄉 - 政見支票:開票畫面的兌現與否和開票結果一致(照投票日的票數判定);跳過=不開;模擬玩家都不開 - 趕場翻到的免費牌只免費一次 - 劇本清單算錯一次後不會一直回錯誤 - 分享圖的標語、減少動態效果時的 3D 看板,字型晚到後重畫 - Safari 解不開 OGG 時改放 MP3 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 09:04:19 +00:00
#!/usr/bin/env bash
# 網站圖示:從 art/icon/icon.svg(1024 滿版原稿)出 web/public 的各種尺寸
# - apple-touch-icon.png 180:iPhone 加到主畫面用,滿版不透明(iOS 自己切圓角,自己畫圓角會變成角落多一圈底色)
# - icon-192.png、icon-512.png:manifest 的一般圖示,自己帶圓角(透明角)
# - icon-maskable-512.png:Android 自適應圖示,滿版、圖案縮進中間的安全圓(半徑 40%)
# - favicon.svg:瀏覽器分頁,圓角向量版
# 用法:art/icon/render-icons.sh(要 rsvg-convert、ImageMagick)
set -eu
here="$(cd "$(dirname "$0")" && pwd)"
pub="$here/../../web/public"
src="$here/icon.svg"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
# 圓角:rx 230/1024 ≈ 22.5%,和 iPhone 主畫面的圓角差不多
sed 's/id="tile-shape" width="1024" height="1024" rx="0"/id="tile-shape" width="1024" height="1024" rx="230"/' "$src" > "$tmp/rounded.svg"
# 安全圓:投票箱的角離中心最遠,縮到 0.86 才都在半徑 40% 裡面
sed 's/scale(1.08)/scale(0.86)/' "$src" > "$tmp/maskable.svg"
grep -q 'rx="230"' "$tmp/rounded.svg" && grep -q 'scale(0.86)' "$tmp/maskable.svg"
png() { # 原稿 寬 輸出 [不透明]
rsvg-convert -w "$2" -h "$2" "$1" -o "$tmp/out.png"
if [[ ${4-} == opaque ]]; then
magick "$tmp/out.png" -background "#ffd84f" -alpha remove -alpha off -strip -depth 8 -define png:compression-level=9 "PNG24:$3"
else
magick "$tmp/out.png" -strip -depth 8 -define png:compression-level=9 "PNG32:$3"
fi
echo "ok $(basename "$3") $(stat -c %s "$3") B"
}
png "$src" 180 "$pub/apple-touch-icon.png" opaque
png "$tmp/rounded.svg" 192 "$pub/icon-192.png"
png "$tmp/rounded.svg" 512 "$pub/icon-512.png"
png "$tmp/maskable.svg" 512 "$pub/icon-maskable-512.png" opaque
# favicon:拿掉原稿的說明註解,其他照抄
grep -v '<!-- 選舉小鎮的圖示原稿' "$tmp/rounded.svg" > "$pub/favicon.svg"
echo "ok favicon.svg $(stat -c %s "$pub/favicon.svg") B"