2 #OpenGameBook engine implemented in BASH
5 title
="OpenGameBook - BASH engine";
9 export XDIALOG_HIGH_DIALOG_COMPAT
=true
;
10 dialog
="dialog"; #(dialog|whiptail|Xdialog|gdialog)
14 echo "Usage: gbook game.txt [room] [dialog_binary]";
19 else echo "File not exist!";
21 if [ -n "$2" ]; then room
="$2"; fi;
22 if [ -n "$3" ]; then dialog
="$3"; fi;
28 #sed "s/'/\\\\'/g" | sed 's/"/\\"/g' | sed 's/!/\!/g';
29 iconv -c |
sed "s/'/\\\\'/g";
33 head "$1" -n "$2" |
tail -n 1 | dial_escape
;
39 echo -n "$line" |
grep -o '\[[^]]*\]' |
while read item
; do
40 mroom
="$(echo "$item" | grep -o '[0-9][0-9]*' | head -n 1)";
41 echo "'$mroom'"; echo "'$item'";
44 echo 'c'; echo 'Cheat!';
52 tmpfile
="/tmp/ogb-$$.tmp";
53 dtmpfile
="/tmp/ogbd-$$.tmp";
54 head="$(fline "$game" 1)";
57 "$dialog" --msgbox "$head" 0 0 --backtitle "$title: $game" --title "$game intro";
59 line
="$(fline "$game" "$room")";
61 menuargs
="--backtitle '$title: $game' --title '$game/$room' --menu '#$room: $line' 0 0 10"
62 echo "$(echo "$menuargs" && enter_room "$line")" |
xargs "$dialog" 2>"$tmpfile";
63 set="$?"; seterr
=123; #123 in xargs == 1 in command
64 if [ "$set" == "$seterr" ]; then
65 "$dialog" --backtitle "$title: $game" --title "Exiting $game" --yesno "End? - Konec?" 0 0
66 if [ "$?" == 0 ]; then break; fi;
69 if [ "$(cat "$tmpfile" | xcompat)" == "c" ]; then
70 "$dialog" --backtitle "$title: $game" --title "Cheating in $game" --inputbox "Room? - Mistnost?" 0 0 2>"$tmpfile";
74 echo -n "$(cat "$tmpfile" | xcompat)" |
grep "[^0-9]" > /dev
/null
75 if [[ "$?" != 0 && "$set" != "$seterr" && -n "$(cat "$tmpfile" | xcompat)" ]]; then room
="$(cat "$tmpfile" | xcompat)"; fi;
82 echo Game
"$game" aborted by user
in room
"$room";