#!/bin/sh
PACKNAME=${1%.*}
OUTDIR="../OUT"
mkdir -p "$OUTDIR/assets"
printf "{\"$PACKNAME\":{" > "$OUTDIR/$PACKNAME.json"
OUTNAME="$(sha256sum "$1" | awk '{ print $1 }').${1##*.}"
printf "\"frame\":\"$OUTNAME\"," >> "$OUTDIR/$PACKNAME.json"
cp $1 "$OUTDIR/assets/$OUTNAME"
if [ ! -z $5 ]; then
	printf "\"size\":[$2,$3,$4,$5]" >> "$OUTDIR/$PACKNAME.json"
elif [ ! -z $3 ]; then
	printf "\"size\":[$2,$3]" >> "$OUTDIR/$PACKNAME.json"
else
	printf "\"size\":[$2]" >> "$OUTDIR/$PACKNAME.json"
fi
printf "}}" >> "$OUTDIR/$PACKNAME.json"
if [ $RECORD ]; then
	printf "../pack-frame.sh $*\n" >> "$OUTDIR/frames.sh"
fi