# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           app 1.0
PortGroup           java 1.0
PortGroup           github 1.0

github.setup        yairm210 Unciv 4.12.10-patch1
name                unciv
github.tarball_from archive
revision            0

categories          games
platforms           any
supported_archs     noarch
license             {MPL-2 LGPL-2.1+}
maintainers         {@harens harens} openmaintainer

description         Open-source Android/Desktop remake of Civ V
long_description    An open source, mod-friendly Android and Desktop \
                    remake of Civ V, made with LibGDX.

checksums           rmd160  44d6164894321bbb888e37be97d98c3f11890865 \
                    sha256  076347d037aab18a0ad2cc37795c3252caf6d6d4c6098a1f2ff45a2202ff64a4 \
                    size    43309950

depends_build-append \
                    port:gradle

java.version        17+
java.fallback       openjdk17
use_configure       no

patchfiles          patch-remove-mobile-build.diff

post-extract {
    copy ${filespath}/gui.in ${workpath}/gui
    # Based off AUR: We cannot just get rid of the android/ folder becuase we need assets from it
    delete {*}[glob ${worksrcpath}/android/{res,src,build.gradle.kts,gradle.properties,project.properties}]
}

set javadir         ${prefix}/share/java/${name}

post-patch {
    reinplace -W ${workpath} "s|@JAVADIR@|${javadir}|g;s|@ICON@|${applications_dir}/Unciv.app/Contents/Resources/Unciv.icns|g" gui
}

build.env-append    GRADLE_USER_HOME=${worksrcpath}
build.cmd           ${prefix}/bin/gradle
build.target        desktop:dist
build.args          --stacktrace --parallel --max-workers=${build.jobs}

app.executable      ${workpath}/gui
app.icon            "${worksrcpath}/extraImages/Icons/Unciv icon v6.png"

# Create an empty saved files directory
destroot.keepdirs   ${destroot}${javadir}/saved_files

destroot {
    xinstall -d ${destroot}${javadir}
    xinstall -m 0770 -d ${destroot}${javadir}/saved_files
    xinstall -m 0644 ${worksrcpath}/desktop/build/libs/Unciv.jar ${destroot}${javadir}
}
