]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/mapping-helper.sh
c28ddee2a891f6a3c999fc22eb8e7a0d7d6d80ac
[xonotic/xonotic.git] / misc / tools / mapping-helper.sh
1 #!/usr/bin/env bash
2
3 # Tiny script to set up and package standalone maps
4
5 list () {
6     for PK3DIR in $(find ${BASEDIR} -type d -name "map-*.pk3dir"); do
7         PK3DIR=${PK3DIR%.pk3dir}
8         PK3DIR=${PK3DIR##${BASEDIR}/map-}
9         echo $PK3DIR
10     done
11 }
12
13 create_stub () {
14     MAPNAME=$1
15     [[ -z "${MAPNAME}" ]] && { echo "Please specify mapname"; exit -1; }
16     [[ -d "${BASEDIR}/map-${MAPNAME}.pk3dir" ]] && { echo "Map ${MAPNAME} already exists"; exit -1; }
17     TEMP=$(find ${BASEDIR} -maxdepth 1 -type d -name "map-"${MAPNAME}"_[[:digit:]].[[:digit:]][[:digit:]].pk3dir")
18     [[ -n "${TEMP}" ]] && { echo "Map ${MAPNAME} already exists"; exit -1; }
19     mkdir -p "${BASEDIR}/map-${MAPNAME}_0.01.pk3dir/"{cubemaps,env,map,models,scripts,sounds,textures}
20     touch "${BASEDIR}/map-${MAPNAME}_0.01.pk3dir/map/${MAPNAME}_0.01.map"
21 }
22
23 package () {
24     MAPNAME=$1
25     [[ -z "${MAPNAME}" ]] && { echo "Please specify mapname"; exit -1; }
26     [[ ! -d "${BASEDIR}/map-${MAPNAME}.pk3dir" ]] && { echo "Map ${MAPNAME} not found"; exit -1; }
27     # TODO: check for License, mapinfo and mapshot
28     pushd ${BASEDIR}/map-${MAPNAME}.pk3dir
29     zip -r -D ${BASEDIR}/map-${MAPNAME}.pk3 * -x "*.srf" "*.prt" "*.bak"
30     popd
31 }
32
33 while getopts "b:" FLAG; do
34     case "${FLAG}" in
35         b)
36             BASEDIR=$OPTARG
37             ;;
38     esac
39 done
40
41 shift $( expr ${OPTIND} - 1 )
42
43 case $(uname -s) in
44     Linux*)
45         DEFAULT_BASEDIR="${HOME}/.xonotic/data"
46         ;;
47     Darwin*)
48         DEFAULT_BASEDIR="~/Library/Application Support/xonotic/data"
49         ;;
50     CYGWIN*|MINGW*)
51         echo "WINDOWS NOT SUPPORTED (YET?)" && exit -1
52         ;;
53     *)
54         echo "Unknown platform, assuming posix"
55         DEFAULT_BASEDIR="${HOME}/.xonotic/data"
56         ;;
57 esac
58
59 BASEDIR=${BASEDIR:-$DEFAULT_BASEDIR}
60
61 TASK=$1
62
63 shift
64
65 case "${TASK}" in
66     ls|list)
67         list
68         ;;
69     stub)
70         create_stub $@
71         ;;
72     package)
73         package $@
74         ;;
75     # TODO: increment version command
76     *)
77         echo "Unsupported option" && exit -1
78         ;;
79 esac
80