Skip to content

Commit 880cc7d

Browse files
committed
improvment for savefiles
it is possible to choose the savefile mode with options --overwrite-savefiles --simple-savefiles (default) --index-savefiles Those options are also available for archive.sh to choose the default mode. The option -F forces using the given file and doesn't check for more recent savefiles.
1 parent 36e8aeb commit 880cc7d

File tree

8 files changed

+111
-24
lines changed

8 files changed

+111
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ tests-zsh: clean
5555
./"game shell (1).sh" -Zdq -c 'gsh systemconfig; for _ in $$(seq 42); do gsh goal|cat; gsh test --abort; gsh auto --abort; done; gsh stat'
5656

5757
clean:
58-
rm -rf i18n/*~ locale gameshell.tgz gameshell.sh gameshell-save.sh scripts/boxes-data.awk
58+
rm -rf i18n/*~ locale gameshell.tgz gameshell.sh gameshell-save*.sh scripts/boxes-data.awk
5959
rm -rf .bin .config .sbin .var World
6060
rm -rf "game shell"*
6161

doc/gameshell.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ You can customize the archive with the following options
139139
GameShell will ask for the player's name and email. This is useful in the
140140
classroom as it makes it easier to link a game to the corresponding student.
141141
(The player can run the archive in anonymous mode with the `-A` option.)
142-
* `-p PASSWORD`: you can choose the admin password for the archive. This is
143-
also useful in the classroom as we might not want the students to learn of
144-
this password. :)
142+
* `--password PASSWORD`: you can choose the admin password for the archive.
143+
This is also useful in the classroom as we might not want the students to
144+
learn of this password. :)
145145
* `-a`: keep the automatic scripts. Some missions come with a script that
146146
automagically completes the missions. By default, those scripts are **not**
147147
included in the archive. Use `-a` if you want to keep them.

i18n/start-help/en.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@ options:
99

1010
-C continue current game (if relevant)
1111
-R reset game
12+
-F do not check for more recent savefiles, force using the given archive
1213

1314
-G do not use gettext for translation (everything will be in English)
1415
-L ... set LANGUAGE variable (ex: -L fr:it:en)
1516
On non GNU systems, set the variable LC_MESSAGES
1617
to a valid locale.
1718

19+
--simple-savefiles
20+
the savefile is obtained by adding a "-save" suffix,
21+
each savefile overwrites the previous one
22+
--index-savefiles
23+
savefiles are numbered so that all savefiles are kept
24+
--overwrite-savefiles
25+
the savefile overwrite the initial GameShell file
26+
(you can use option -R to start a new game from the start)
27+
1828
-B use bash
1929
-Z use zsh
2030

i18n/start-help/fr.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,24 @@ options :
99

1010
-C continue la partie en cours (si pertinent)
1111
-R recommence une partie du début
12+
-F ne vérifie pas l'existence de fichiers de sauvegarde plus récents,
13+
force l'utilisation de l'archive donnée
1214

1315
-G désactive gettext pour les traductions (tout sera en Anglais)
1416
-L initialise la variable LANGUAGE (ex : -L fr:it:en)
1517
Pour les systèmes non GNU, initialisez la variable LC_MESSAGES
1618
avec une locale valide.
1719

20+
--simple-savefiles
21+
le fichier de sauvegarde est obtenu en ajoutant un suffix "-save",
22+
chaque fichier de sauvegarde remplace le précédent
23+
--index-savefiles
24+
les fichiers de sauvegarde sont numérotés pour que toutes les
25+
sauvegardes soient conservées
26+
--overwrite-savefiles
27+
le fichier de sauvegarde remplace l'instance initial de GameShell
28+
(on peut utiliser l'option -R pour lancer une partie à partir du début)
29+
1830
-q mode silencieux : n'affiche pas les messages d'information
1931
-n mode noir et blanc : n'utilise pas les séquences ANSI
2032
-c CMD donne cette commande à GameShell (pour faire des tests)

lib/gsh.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,10 @@ __save() {
517517
GSH_SAVEFILE="$GSH_SAVEFILE-save.$EXT"
518518
;;
519519

520-
"same")
520+
"overwrite")
521521
GSH_SAVEFILE=$GSH_EXEC_DIR/$GSH_EXEC_FILE
522522
;;
523+
523524
esac
524525
fi
525526
_gsh_save "$GSH_SAVEFILE"

lib/header.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ do
8181
elif [ "$arg" = "-K" ]
8282
then
8383
KEEP_DIR="true"
84+
elif [ "$arg" = "-F" ]
85+
then
86+
GSH_FORCE="true"
8487
elif [ "$arg" = "-h" ]
8588
then
8689
# used to avoid checking for more recent files
@@ -98,7 +101,7 @@ GSH_NAME=${GSH_NAME%-save*}
98101
GSH_NAME=$(basename "$GSH_NAME")
99102

100103

101-
if [ "$GSH_HELP" != "true" ]
104+
if [ "$GSH_HELP" != "true" ] && [ "$GSH_FORCE" != "true" ]
102105
then
103106
LAST_SAVEFILE=$(ls "$GSH_EXEC_DIR/$GSH_NAME-save"*".$EXT" 2>/dev/null | sort | tail -n 1)
104107

start.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,37 @@ display_help() {
2929
}
3030

3131

32-
# possible values: index, simple, same
33-
export GSH_SAVEFILE_MODE=simple
32+
# possible values: index, simple (default), overwrite
33+
export GSH_SAVEFILE_MODE="simple"
3434
export GSH_AUTOSAVE=1
3535
export GSH_COLOR="OK"
3636
GSH_MODE="ANONYMOUS"
37+
# if GSH_NO_GETTEXT is non-empty, gettext won't be used anywhere, the only language will thus be English
38+
# export GSH_NO_GETTEXT=1 # DO NOT CHANGE OR REMOVE THIS LINE, it is used by utils/archive.sh
3739
RESET=""
38-
while getopts ":hnPdDACRXUVqGL:KBZc:" opt
40+
# hack to parse long options --index-savefiles --overwrite-savefiles --simple-savefiles
41+
# cf https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options
42+
_long_option=0
43+
while getopts ":hnPdDACRXUVqGL:KBZc:F-:" opt
3944
do
45+
if [ "$opt" = "-" ]
46+
then
47+
opt="${OPTARG%%=*}" # extract long option name
48+
OPTARG="${OPTARG#$opt}" # extract long option argument (may be empty)
49+
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
50+
_long_option=1
51+
fi
52+
4053
case $opt in
54+
index-savefiles)
55+
GSH_SAVEFILE_MODE=index
56+
;;
57+
simple-savefiles)
58+
GSH_SAVEFILE_MODE=simple
59+
;;
60+
overwrite-savefiles)
61+
GSH_SAVEFILE_MODE=overwrite
62+
;;
4163
h)
4264
display_help
4365
exit 0
@@ -98,10 +120,14 @@ do
98120
c)
99121
GSH_COMMAND=$OPTARG
100122
;;
101-
K)
123+
K|F)
102124
: # used by the self-extracting archive
103125
;;
104126
*)
127+
if [ "$_long_option" = "1" ]
128+
then
129+
OPTARG="-$opt"
130+
fi
105131
echo "$(eval_gettext "Error: invalid option: '-\$OPTARG'")" >&2
106132
exit 1
107133
;;

utils/archive.sh

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@ $(basename "$0") [OPTIONS] [MISSIONS]
99
create a GameShell standalone archive
1010
1111
options:
12-
-h this message
12+
-h this message
1313
14-
-p ... choose password for admin commands
15-
-P use the "passport mode" by default when running GameShell
16-
-A use the "anonymous mode" by default when running GameShell
17-
-L LANGS only keep the given languages (ex: -L 'en*,fr')
18-
-E only keep english as a language, not generating any ".mo" file
19-
and not using gettext
14+
--password ... choose password for admin commands
15+
-P use the "passport mode" by default when running GameShell
16+
-A use the "anonymous mode" by default when running GameShell
17+
-L LANGS only keep the given languages (ex: -L 'en*,fr')
18+
-E only keep english as a language, not generating any ".mo" file
19+
and not using gettext
2020
21-
-N ... name of the archive / top directory (default: "gameshell")
21+
-N ... name of the archive / top directory (default: "gameshell")
2222
23-
-a keep 'auto.sh' scripts for missions that have one
24-
-t keep 'test.sh' scripts for missions that have one
25-
-z keep tgz archive
23+
--simple-savefiles
24+
--index-savefiles
25+
--overwrite-savefiles
26+
choose default savefile mode
2627
27-
-v show the list of mission directories as they are being processed
28+
-a keep 'auto.sh' scripts for missions that have one
29+
-t keep 'test.sh' scripts for missions that have one
30+
-z keep tgz archive
31+
32+
-v show the list of mission directories as they are being processed
2833
EOH
2934
}
3035

@@ -57,19 +62,39 @@ KEEP_PO=0 # this is set to 1 if we generate .mo files. Setting it to 1 here
5762
LANGUAGES=""
5863
VERBOSE=
5964

60-
while getopts ":hp:N:atPzL:Ev" opt
65+
# hack to parse long option --password
66+
# cf https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options
67+
_long_option=0
68+
while getopts ":hp:N:atPzL:Ev-:" opt
6169
do
70+
if [ "$opt" = "-" ]
71+
then
72+
opt="${OPTARG%%=*}" # extract long option name
73+
OPTARG="${OPTARG#$opt}" # extract long option argument (may be empty)
74+
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
75+
_long_option=1
76+
fi
77+
6278
case $opt in
6379
h)
6480
display_help
6581
exit 0;
6682
;;
67-
p)
83+
password)
6884
ADMIN_PASSWD=$OPTARG
6985
;;
7086
N)
7187
NAME=$OPTARG
7288
;;
89+
index-savefiles)
90+
GSH_SAVEFILE_MODE=index
91+
;;
92+
simple-savefiles)
93+
GSH_SAVEFILE_MODE=simple
94+
;;
95+
overwrite-savefiles)
96+
GSH_SAVEFILE_MODE=overwrite
97+
;;
7398
a)
7499
KEEP_AUTO=1
75100
;;
@@ -95,6 +120,10 @@ do
95120
VERBOSE=1
96121
;;
97122
*)
123+
if [ "$_long_option" = "1" ]
124+
then
125+
OPTARG="-$opt"
126+
fi
98127
echo "invalid option: '-$OPTARG'" >&2
99128
exit 1
100129
;;
@@ -295,6 +324,12 @@ case $DEFAULT_MODE in
295324
;;
296325
esac
297326

327+
# choose default savefile mode
328+
if [ -n "$GSH_SAVEFILE_MODE" ]
329+
then
330+
sed-i "s/^export GSH_SAVEFILE_MODE=.*$/export GSH_SAVEFILE_MODE='$GSH_SAVEFILE_MODE'/" "$GSH_ROOT/start.sh"
331+
fi
332+
298333
# record version
299334
if git rev-parse --is-inside-work-tree >/dev/null 2>&1
300335
then

0 commit comments

Comments
 (0)