Skip to content

Commit

Permalink
improvment for savefiles
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phyver committed Sep 1, 2022
1 parent 36e8aeb commit 880cc7d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ tests-zsh: clean
./"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'

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

Expand Down
6 changes: 3 additions & 3 deletions doc/gameshell.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ You can customize the archive with the following options
GameShell will ask for the player's name and email. This is useful in the
classroom as it makes it easier to link a game to the corresponding student.
(The player can run the archive in anonymous mode with the `-A` option.)
* `-p PASSWORD`: you can choose the admin password for the archive. This is
also useful in the classroom as we might not want the students to learn of
this password. :)
* `--password PASSWORD`: you can choose the admin password for the archive.
This is also useful in the classroom as we might not want the students to
learn of this password. :)
* `-a`: keep the automatic scripts. Some missions come with a script that
automagically completes the missions. By default, those scripts are **not**
included in the archive. Use `-a` if you want to keep them.
Expand Down
10 changes: 10 additions & 0 deletions i18n/start-help/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ options:

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

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

--simple-savefiles
the savefile is obtained by adding a "-save" suffix,
each savefile overwrites the previous one
--index-savefiles
savefiles are numbered so that all savefiles are kept
--overwrite-savefiles
the savefile overwrite the initial GameShell file
(you can use option -R to start a new game from the start)

-B use bash
-Z use zsh

Expand Down
12 changes: 12 additions & 0 deletions i18n/start-help/fr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@ options :

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

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

--simple-savefiles
le fichier de sauvegarde est obtenu en ajoutant un suffix "-save",
chaque fichier de sauvegarde remplace le précédent
--index-savefiles
les fichiers de sauvegarde sont numérotés pour que toutes les
sauvegardes soient conservées
--overwrite-savefiles
le fichier de sauvegarde remplace l'instance initial de GameShell
(on peut utiliser l'option -R pour lancer une partie à partir du début)

-q mode silencieux : n'affiche pas les messages d'information
-n mode noir et blanc : n'utilise pas les séquences ANSI
-c CMD donne cette commande à GameShell (pour faire des tests)
Expand Down
3 changes: 2 additions & 1 deletion lib/gsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,10 @@ __save() {
GSH_SAVEFILE="$GSH_SAVEFILE-save.$EXT"
;;

"same")
"overwrite")
GSH_SAVEFILE=$GSH_EXEC_DIR/$GSH_EXEC_FILE
;;

esac
fi
_gsh_save "$GSH_SAVEFILE"
Expand Down
5 changes: 4 additions & 1 deletion lib/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ do
elif [ "$arg" = "-K" ]
then
KEEP_DIR="true"
elif [ "$arg" = "-F" ]
then
GSH_FORCE="true"
elif [ "$arg" = "-h" ]
then
# used to avoid checking for more recent files
Expand All @@ -98,7 +101,7 @@ GSH_NAME=${GSH_NAME%-save*}
GSH_NAME=$(basename "$GSH_NAME")


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

Expand Down
34 changes: 30 additions & 4 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,37 @@ display_help() {
}


# possible values: index, simple, same
export GSH_SAVEFILE_MODE=simple
# possible values: index, simple (default), overwrite
export GSH_SAVEFILE_MODE="simple"
export GSH_AUTOSAVE=1
export GSH_COLOR="OK"
GSH_MODE="ANONYMOUS"
# if GSH_NO_GETTEXT is non-empty, gettext won't be used anywhere, the only language will thus be English
# export GSH_NO_GETTEXT=1 # DO NOT CHANGE OR REMOVE THIS LINE, it is used by utils/archive.sh
RESET=""
while getopts ":hnPdDACRXUVqGL:KBZc:" opt
# hack to parse long options --index-savefiles --overwrite-savefiles --simple-savefiles
# cf https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options
_long_option=0
while getopts ":hnPdDACRXUVqGL:KBZc:F-:" opt
do
if [ "$opt" = "-" ]
then
opt="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#$opt}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
_long_option=1
fi

case $opt in
index-savefiles)
GSH_SAVEFILE_MODE=index
;;
simple-savefiles)
GSH_SAVEFILE_MODE=simple
;;
overwrite-savefiles)
GSH_SAVEFILE_MODE=overwrite
;;
h)
display_help
exit 0
Expand Down Expand Up @@ -98,10 +120,14 @@ do
c)
GSH_COMMAND=$OPTARG
;;
K)
K|F)
: # used by the self-extracting archive
;;
*)
if [ "$_long_option" = "1" ]
then
OPTARG="-$opt"
fi
echo "$(eval_gettext "Error: invalid option: '-\$OPTARG'")" >&2
exit 1
;;
Expand Down
63 changes: 49 additions & 14 deletions utils/archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@ $(basename "$0") [OPTIONS] [MISSIONS]
create a GameShell standalone archive
options:
-h this message
-h this message
-p ... choose password for admin commands
-P use the "passport mode" by default when running GameShell
-A use the "anonymous mode" by default when running GameShell
-L LANGS only keep the given languages (ex: -L 'en*,fr')
-E only keep english as a language, not generating any ".mo" file
and not using gettext
--password ... choose password for admin commands
-P use the "passport mode" by default when running GameShell
-A use the "anonymous mode" by default when running GameShell
-L LANGS only keep the given languages (ex: -L 'en*,fr')
-E only keep english as a language, not generating any ".mo" file
and not using gettext
-N ... name of the archive / top directory (default: "gameshell")
-N ... name of the archive / top directory (default: "gameshell")
-a keep 'auto.sh' scripts for missions that have one
-t keep 'test.sh' scripts for missions that have one
-z keep tgz archive
--simple-savefiles
--index-savefiles
--overwrite-savefiles
choose default savefile mode
-v show the list of mission directories as they are being processed
-a keep 'auto.sh' scripts for missions that have one
-t keep 'test.sh' scripts for missions that have one
-z keep tgz archive
-v show the list of mission directories as they are being processed
EOH
}

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

while getopts ":hp:N:atPzL:Ev" opt
# hack to parse long option --password
# cf https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options
_long_option=0
while getopts ":hp:N:atPzL:Ev-:" opt
do
if [ "$opt" = "-" ]
then
opt="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#$opt}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
_long_option=1
fi

case $opt in
h)
display_help
exit 0;
;;
p)
password)
ADMIN_PASSWD=$OPTARG
;;
N)
NAME=$OPTARG
;;
index-savefiles)
GSH_SAVEFILE_MODE=index
;;
simple-savefiles)
GSH_SAVEFILE_MODE=simple
;;
overwrite-savefiles)
GSH_SAVEFILE_MODE=overwrite
;;
a)
KEEP_AUTO=1
;;
Expand All @@ -95,6 +120,10 @@ do
VERBOSE=1
;;
*)
if [ "$_long_option" = "1" ]
then
OPTARG="-$opt"
fi
echo "invalid option: '-$OPTARG'" >&2
exit 1
;;
Expand Down Expand Up @@ -295,6 +324,12 @@ case $DEFAULT_MODE in
;;
esac

# choose default savefile mode
if [ -n "$GSH_SAVEFILE_MODE" ]
then
sed-i "s/^export GSH_SAVEFILE_MODE=.*$/export GSH_SAVEFILE_MODE='$GSH_SAVEFILE_MODE'/" "$GSH_ROOT/start.sh"
fi

# record version
if git rev-parse --is-inside-work-tree >/dev/null 2>&1
then
Expand Down

0 comments on commit 880cc7d

Please sign in to comment.