# -*- 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           github 1.0
PortGroup           love 1.0

github.setup        Stabyourself nottetris2 2.0 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            2
checksums           rmd160  933a9ff2ca6a56869b660704f1850a113bc35abf \
                    sha256  e2b8737e1e761174bbb0cdea403a2b7558732b682f5a1e32ea3ee956192ea88c \
                    size    2774048

categories          games
maintainers         {ryandesign @ryandesign} openmaintainer
license             WTFPL-2

description         all the upsides of Tetris and all the downsides of physics

long_description    Not Tetris 2 is the spiritual successor of the classic \
                    Tetris mixed with physics. The result is a fun spinoff \
                    in which blocks are no longer bound to the usual grid. \
                    Blocks can be rotated and placed at any angle, resulting \
                    in a complete mess if not careful. And with the newest \
                    cutting-edge technology, Not Tetris 2 allows line clears \
                    when the lines are sufficiently filled.

homepage            https://stabyourself.net/nottetris2/
# A fully-working version is not on GitHub, only in the downloads on the web
# site. The code on GitHub appears to be a work in progress for migrating to
# love 0.8. https://github.com/Stabyourself/nottetris2/issues/8
master_sites        https://stabyourself.net/dl.php?file=${name}/${name}-linux.zip&dummy=
distname            ${name}-linux-${version}
use_zip             yes

depends_build       port:ImageMagick7

# https://github.com/Stabyourself/nottetris2/issues/2
love.branch         0.7

extract.mkdir       yes
love.extract        Not Tetris 2.love

love.exclude        LICENSE.txt \
                    README.md

app.name            Not Tetris 2
app.icon            ${workpath}/icon.png
app.identifier      net.stabyourself.not-tetris2

post-extract {
    # DOS to UNIX line endings.
    reinplace "s|\r||g" {*}[glob ${love.dir}/*.lua]
}

post-patch {
    # Allow keypad enter key to be used in place of return key.
    # https://github.com/Stabyourself/nottetris2/commit/62c05953341b74f601d7f0003529fab9764a166b
    reinplace -E {s/(key == "return")/\1 or key == "kpenter"/g} ${love.dir}/main.lua
}

post-build {
    # -9° slant matches application icons introduced in OS X Yosemite.
    system -W ${workpath} \
        "${prefix}/lib/ImageMagick7/bin/magick [shellescape ${love.dir}/graphics/pieces/4.png] -filter box -resize 894x894 -background none -rotate -9 icon.png"
}

variant no_music description {Exclude the music} {
    love.exclude-append \
                    sounds/gameover2.ogg \
                    sounds/highscoreintro.ogg \
                    sounds/highscoremusic.ogg \
                    sounds/musicoptions.ogg \
                    sounds/resultsmusic.ogg \
                    sounds/rocket1to3.ogg \
                    sounds/rocket4.ogg \
                    sounds/themeA.ogg \
                    sounds/themeB.ogg \
                    sounds/themeC.ogg \
                    sounds/titlemusic.ogg

    post-patch {
        reinplace -W ${love.dir} -E \
                    {/(gameover2|highscoreintro|music(\[[^]]+\]|highscore|options|results|rocket(1to3|4)|title))/d} \
                    failed.lua \
                    gameA.lua \
                    gameB.lua \
                    gameBmulti.lua \
                    main.lua \
                    menu.lua \
                    rocket.lua
    }
}
