71 lines
1.7 KiB
Text
71 lines
1.7 KiB
Text
|
#!/bin/sh
|
|||
|
|
|||
|
VERSION="0.2"
|
|||
|
|
|||
|
PROGNAME="gamelib.gui"
|
|||
|
|
|||
|
GAMELIB="$(dirname -- "$(readlink -f -- "${0}")")/gamelib"
|
|||
|
|
|||
|
hlpr:die() {
|
|||
|
echo "${@}" >&2
|
|||
|
exit 1
|
|||
|
}
|
|||
|
|
|||
|
[ $(${GAMELIB} list | wc -l) -ne 0 ] || hlpr:die "you have no games"
|
|||
|
|
|||
|
orig_IFS="${IFS}"
|
|||
|
IFS=$'\n'
|
|||
|
for game in $(${GAMELIB} list); do
|
|||
|
img="${GAMELIB_GAMES_DIR}/${game%% *}/gamelib_gui.png"
|
|||
|
if [ -r "${img}" ]; then
|
|||
|
image="${img}"
|
|||
|
else
|
|||
|
image="applications-games"
|
|||
|
fi
|
|||
|
conf="${GAMELIB_GAMES_DIR}/${game%% *}/gamelib_gui.conf"
|
|||
|
if [ -f "${conf}" ]; then
|
|||
|
. "${conf}"
|
|||
|
[ -n "${name}" ] || name="$(echo "${game%% *}" | sed 's/-/ /g')"
|
|||
|
[ -n "${description}" ] || description="${game##* }"
|
|||
|
else
|
|||
|
name="$(echo "${game%% *}" | sed 's/-/ /g')"
|
|||
|
description="${game##* }"
|
|||
|
fi
|
|||
|
games="${games}
|
|||
|
${game%% *} ${game##* } '${image}' '${name}' ' ${description} '"
|
|||
|
done
|
|||
|
games="$(echo "${games}" | sed '/^$/d')"
|
|||
|
gnum="$(echo "${games}" | wc -l | sed 's/^[[:space:]]*//')"
|
|||
|
|
|||
|
# game: 96×32
|
|||
|
|
|||
|
game="$(eval yad \
|
|||
|
--width 600 --height 600 --center \
|
|||
|
--class "'${PROGNAME%.*}'" \
|
|||
|
--title "'${PROGNAME}'" \
|
|||
|
--text "'$(${GAMELIB} version) (gui: ${VERSION})\n${gnum} games found:'" \
|
|||
|
--image "'applications-games'" --image-on-top \
|
|||
|
--buttons-layout "'center'" \
|
|||
|
--button "'_cancel:1'" \
|
|||
|
--button "'_run:0'" \
|
|||
|
--list --no-headers \
|
|||
|
--print-column 1 \
|
|||
|
--search-column 0 \
|
|||
|
--expand-column 4 \
|
|||
|
--tooltip-column 5 \
|
|||
|
--ellipsize-cols 4,5 \
|
|||
|
--separator "''" \
|
|||
|
--column game:HD --column type:HD --column icon:IMG --column name:TEXT --column description:HD \
|
|||
|
${games})"
|
|||
|
exitcode=${?}
|
|||
|
|
|||
|
|
|||
|
case ${exitcode} in
|
|||
|
(0) ${GAMELIB} run "${game}" ;;
|
|||
|
(1) echo "${PROGNAME}: canceled" >&2 ;;
|
|||
|
(252) echo "${PROGNAME}: escaped" >&2 ;;
|
|||
|
(*) echo "${PROGNAME}: exited with ${exitcode}" >&2 ;;
|
|||
|
esac
|
|||
|
|
|||
|
exit ${exitcode}
|