File indexing completed on 2024-10-13 03:43:38

0001 #!/bin/bash
0002 # This script converts game and level data from KGoldrunner 2 to KGoldrunner 3
0003 # format.  It must run in the directory where "games.dat" is located, with the
0004 # level-data files untarred into the "levels" sub-directory.  It is provided for
0005 # convenience only and must NOT be installed.  The "game_*.txt" files it creates
0006 # do get released and installed and the "games.dat" and "levels.tar" get
0007 # dropped from SVN and future releases.
0008 #
0009 # This script will be needed again whenever someone has created a new
0010 # KGoldrunner game using the game editor, because the editor continues
0011 # to use KGoldrunner 2 format.
0012 #
0013 # Pass 1: in games.dat, convert '\n' character sequences to actual newlines,
0014 # then copy the game-data and description to the new game-file's header.
0015 sed -e 's/\\n/\\\\n/g' games.dat | while read line
0016 do
0017     case "$line" in
0018         0*|1*|2*)
0019                 echo "Pass 1: $line"
0020                 set -- $line                            # Re-parse game-data.
0021                 prefix="$3"                             # Get fixed ID of game.
0022                 game="game_$prefix.txt"                 # Generate file name.
0023                 echo "// G$1 $2 $3 N" >"$game"          # Write game-data line.
0024                 shift; shift; shift
0025                 echo " i18n(\"$*\");" >>$game           # Append name of game.
0026                 ;;
0027         *)      echo " i18n(\"$line\");" >>"$game"      # Append game-desc line.
0028                 ;;
0029     esac
0030 done
0031 
0032 # Pass 2: append header and data for each level to the new game-files.
0033 while read n rules prefix name
0034 do
0035     case $n in
0036         0*|1*|2*)
0037                 echo "Pass 2: $n $rules $prefix $name"
0038                 game="game_$prefix.txt"
0039                 i=1
0040                 while [ "$i" -le "$n" ]                 # Loop thru all levels.
0041                 do
0042                     lev="$i"                            # Get the level-number.
0043                     if [ "$i" -lt 100 ]                 # Add leading zeroes.
0044                     then
0045                         lev="0""$lev"
0046                     fi
0047                     if [ "$i" -lt 10 ]
0048                     then
0049                         lev="0""$lev"
0050                     fi
0051 
0052                     echo "// L$lev" >>"$game"           # Append level-header.
0053                     grl="levels/$prefix$lev.grl"        # Get level's file path.
0054                     # Append level-data with a leading comment, level-name
0055                     # with 'i18n("");' and hint with 'i18n("");'.
0056                     sed -e '
0057                             1s:^://  :
0058                             2s/^/ i18n("/
0059                             2s/$/");/
0060                             3s/^/ i18n("/
0061                             3,$s/$/\\n"/
0062                             4,$s/^/ "/
0063                             $s/\\n"/");/
0064                     ' "$grl" >>"$game"
0065 
0066                     let "i = $i + 1"
0067                 done
0068                 ;;
0069         *)      ;;                                      # Skip game-desc lines.
0070     esac
0071 done <games.dat