-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashtell
executable file
·128 lines (126 loc) · 2.51 KB
/
bashtell
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
if [[ "$1" == -h || "$1" == --help ]]; then
echo "usage: bashtell [-h] FILE [-l]
Options:
-l --load Load progress
-h --help Show this message
bashtell allows you to create simple text novels"
exit 0
fi
if ! [ -e "$1" ]; then
echo "File '$1' not found"
exit 1
fi
savegame() {
if [[ -z "$prepare" ]]; then
export savedata="$step-$var"
fi
}
echosave() {
echo ''
echo -n 'SAVE DATA: '
echo "$savedata" | base64 -w 0
echo ''
exit 0
}
gosleep() {
local __null __plus
__null=0
__plus="$1"
while ((__null < __plus)); do
echo -n -e '\r '; sleep 0.1
echo -n -e '\r \e[1m.\e[0m'; sleep 0.3
echo -n -e '\r \e[1m..\e[0m'; sleep 0.3
echo -n -e '\r \e[1m...\e[0m'; sleep 0.3
((__null++))
done
echo -n -e '\r'
}
prompt="$(echo -e "\e[0;34m>\e[0m")"
step=0
var=0
if [[ "$2" == -l || "$2" == --load ]]; then
read -r -p "Save data: " base64
base64="$(echo "$base64" | base64 -d)"
if [ "$?" != 0 ]; then
echo "invalid save data"
exit 1
fi
step="${base64%-*}"
var="${base64#*-}"
fi
trap echosave SIGINT
start="$(read -r __start < "$1"; echo "$__start")"
echo "${start#*-}"
echo ''
while :; do
if [ "$prepare" == 1 ]; then
var='[[:digit:]]*'
unset prepare
fi
steps="$(grep -o "[*/+?][[:digit:]]*-$step-$var .*" "$1")"
while read -r line; do
echo="${line#* }"
if [ -z "${echo%%@@*}" ]; then
time="${echo#@@*}"
time="${time%% *}"
fi
if [[ "$time" == [0-9]* ]]; then
sleep="gosleep $time"
echo="${echo#* }"
unset time
else
sleep=":"
fi
case "$line" in
'*'*) ques=0
$sleep
echo="${echo//##/\\n }"
echo -e "\e[0;32m< \e[0m$echo"
unlink=1
;;
'/'*) ques=0
$sleep
echo="${echo//##/\\n }"
echo -e "\e[0;31m<=== \e[m$echo"
exit 0
;;
'+'*) ques=0
$sleep
echo="${echo//##/\\n }"
echo -e "\e[0;33m<... \e[0m$echo"
prepare=1
;;
'?'*) prepare=1
ques=1
alu=${line#*-}
alu=${alu#*-}
alu=${alu%% *}
echo="${echo//##/\\n }"
choice+="$alu: $echo@@"
;;
esac
done <<<"$steps"
if [ "$ques" == 1 ]; then
bonk="${choice%@@*}"
bonk="${bonk//@@/\\n}"
echo -e "$bonk"
read -r -p "$prompt " ilu
while [ -z "$(echo -e "$bonk" | grep -x "$ilu: .*")" ]; do
echo "invalid choice"
read -r -p "$prompt " ilu
done
var="$ilu"
unset prepare
unset choice
echo ''
fi
if [ "$unlink" == 1 ]; then
var=0
unset unlink
echo ''
fi
line="$(echo "$steps" | tail -n 1)"
_step="${line%%-*}"; step="${_step//[?+*\/]/}"
savegame
done