# Contributor/Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=wwrando
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.10.0
pkgrel=4
pkgdesc="Wind Waker Randomizer (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/LagoLunatic/wwrando"
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-pyside6"
  "${MINGW_PACKAGE_PREFIX}-python-yaml"
  "${MINGW_PACKAGE_PREFIX}-python-pillow"
  "${MINGW_PACKAGE_PREFIX}-python-appdirs"
  "${MINGW_PACKAGE_PREFIX}-python-certifi"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-pyside6-tools"
)
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-tinyaes"
  "${MINGW_PACKAGE_PREFIX}-python-pyfastbti"
  "${MINGW_PACKAGE_PREFIX}-python-pyfasttextureutils"
)
source=("https://github.com/LagoLunatic/wwrando/archive/$pkgver/${_realname}-${pkgver}.tar.gz")
sha256sums=('9d05501ff5468aa5d790cb10c7daaed50700f81b7254bc9cdbfe3c3f28c50d19')

prepare() {
  cd "${srcdir}"

  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m compileall .
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  local _pyver=$(${MINGW_PREFIX}/bin/python -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")
  find . -type f -exec install -Dm644 {} "${pkgdir}${MINGW_PREFIX}/lib/python${_pyver}/site-packages/wwrando/"{} \;

  mkdir -p "${pkgdir}${MINGW_PREFIX}/bin"
  printf "#!/bin/sh\npython ${MINGW_PREFIX}/lib/python${_pyver}/site-packages/wwrando/wwrando.py \$@\n" >> "${pkgdir}${MINGW_PREFIX}/bin/wwrando"
  chmod +x "${pkgdir}${MINGW_PREFIX}/bin/wwrando"
  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
