summaryrefslogtreecommitdiff
path: root/play.sh
blob: 5667e81f29963eefe809faf2d38692cb5496c46d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/zsh -f

PLAY_DEBUG=${PLAY_DEBUG:-0}

[[ $PLAY_DEBUG == 2 ]] && setopt xtrace

PLAY_DIR="${PLAY_DIR:-${0:h}}"
PLAY_GAMES="${PLAY_GAMES:-$PLAY_DIR/games}"
PLAY_TEMPLATES="${PLAY_TEMPLATES:-$PLAY_DIR/templates}"

typeset -A ENV EENV
BIN=$0

source $PLAY_DIR/functions.sh

inherit default

if [[ $1 == "-x" ]]; then
    source $PLAY_GAMES/$2
    setenv
    prepare
    run
else
    GAME=$1
    DGAME="$PLAY_GAMES/$GAME"

    list () {
        out "Games are:"
        for k in $PLAY_GAMES/*(.:t); do
            echo "\t> $k"
        done
    }
    
    if [[ -z $GAME || ! -e $DGAME ]]; then
        [[ ! -e $DGAME ]] && out "Game '$GAME' not found"
        list
        exit 1
    else
        out "Launching '$GAME'"
        source $DGAME
        execute
    fi
fi