#!/usr/bin/env bash
# The pictures of the web site (site/images) and assets/thumbnail.png, from the game itself. From the repository's root:
#   bash games/webrtc-demo/tools/site/shots.sh
# then python3 games/webrtc-demo/tools/site/build.py (the pages in the 14 languages).
set -euo pipefail
cd "$(dirname "$0")/../../../.."
G=webrtc-demo
shot() { JUMPHP_SCENE="$1" JUMPHP_SCENE_PARAMS="$2" bin/jumphp shot $G "$3" "var/screenshots/site-$4.png" >/dev/null; }
shot 'App\Scene\TitleScene' '{"lang":"en"}' 30 title
shot 'App\Scene\LinkScene' '{"demo":true,"lang":"en"}' 200 link
shot 'App\Scene\DuelScene' '{"mode":"bot","demo":true,"seed":4,"lang":"en"}' 330 duel
shot 'App\Scene\TitleScene' '{"lang":"ja"}' 30 title-ja
python3 -I - "games/$G" <<'PY'
import sys
from PIL import Image
g = sys.argv[1]
s = lambda n: Image.open(f'{g}/var/screenshots/site-{n}.png').convert('RGB')
for i, n in enumerate(['title', 'link', 'duel', 'title-ja'], 1):
    s(n).save(f'{g}/site/images/shot-{i}.png', optimize=True)
duel = s('duel')
duel.save(f'{g}/assets/thumbnail.png', optimize=True)
og = Image.new('RGB', (1200, 630), (10, 12, 24))
og.paste(duel.resize((1120, 630), Image.NEAREST), (40, 0))
og.save(f'{g}/site/images/og.png', optimize=True)
fav = Image.new('RGBA', (32, 32), (10, 12, 24, 255))
for x0, c in ((2, (64, 214, 128, 255)), (18, (255, 150, 64, 255))):
    for x in range(x0, x0 + 12):
        for y in range(10, 22):
            fav.putpixel((x, y), c)
fav.save(f'{g}/site/images/favicon.png')
icon = fav.resize((128, 128), Image.NEAREST)
icon.save(f'{g}/assets/icon.png')
print('site images, thumbnail and icon written')
PY
