1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2025-01-09 13:42:38 +01:00
bygfoot/test/test-load-save.sh
Tom Stellard 013df8dd93 Add json interface
This adds an initial version of a json interface to bygfoot.  This
is still in development so the interface may change in the future.  This
interface can be used for writing tests or for communication between a
client and server.

To use the interface, you can pass a json file with commands to bygfoot
using the --json option.
2021-03-05 23:38:28 -05:00

37 lines
938 B
Bash

set -e
bygfoot_bin=$1
bygfoot_bindir=`dirname $bygfoot_bin`
json_file=`mktemp`
save_dir=`mktemp -d`
cat <<EOF > $json_file
{ 'commands' : [
{ 'add_country' : { 'name' : 'faroe_islands' }},
{ 'start_bygfoot' : {}},
{ 'simulate_games' : {'weeks' : 5}},
{ 'save_bygfoot' : {'filename' : '$save_dir/save0.zip'}},
{ 'load_bygfoot' : {'filename' : '$save_dir/save0.zip'}},
{ 'save_bygfoot' : {'filename' : '$save_dir/save1.zip'}},
{ 'simulate_games' : {'years' : 1}},
]}
EOF
echo $save_dir
tmphome=`mktemp -d`
pushd $bygfoot_bindir
HOME=$tmphome ./bygfoot --random-seed=1 --json=$json_file
for f in save0 save1; do
mkdir -p $save_dir/$f
unzip -q $save_dir/$f.zip -d $save_dir/$f
sed -i "s/${f}___//g" $save_dir/$f/*
for file in `ls $save_dir/$f`; do
new_name=`echo $file | sed "s/${f}___//g"`
mv $save_dir/$f/$file $save_dir/$f/$new_name
done
done
diff -r $save_dir/save0 $save_dir/save1