#!/usr/bin/env bash
# Rasterises the card SVGs into Android density buckets.
#
# The SVGs in assets/cards/ stay the source of truth; this regenerates the
# drawables at any size. Uses macOS `sips`, which renders SVG directly — no
# librsvg or ImageMagick needed.
#
# Note the `card_` prefix: Android resource names may not start with a digit, so
# `10_of_clubs.svg` must become `card_10_of_clubs.png`.
#
# Usage: tools/generate_card_assets.sh
set -euo pipefail

SRC="$(cd "$(dirname "$0")/.." && pwd)/assets/cards"
RES="$(cd "$(dirname "$0")/.." && pwd)/app/src/main/res"

# Card art is 2:3. Widths are chosen so xxhdpi lands at a crisp 240x360.
declare -a BUCKETS=(
  "mdpi:80:120"
  "hdpi:120:180"
  "xhdpi:160:240"
  "xxhdpi:240:360"
)

count=0
for bucket in "${BUCKETS[@]}"; do
  IFS=':' read -r density width height <<< "$bucket"
  out="$RES/drawable-$density"
  mkdir -p "$out"
  for svg in "$SRC"/*.svg; do
    base="$(basename "$svg" .svg)"
    # playing_cards_deck is the 52-card contact sheet, not a usable game asset.
    [ "$base" = "playing_cards_deck" ] && continue
    sips -s format png -z "$height" "$width" "$svg" --out "$out/card_$base.png" >/dev/null 2>&1
    count=$((count + 1))
  done
  echo "  $density (${width}x${height}): $(ls "$out" | wc -l | tr -d ' ') files"
done

echo "generated $count PNGs"
du -sh "$RES" | awk '{print "  total: " $1}'
