tools/hwmap2lua.sh
branchios-develop
changeset 13413 ba39a1d396c0
parent 13064 6766b900ab13
equal deleted inserted replaced
13411:6e8b807bda4b 13413:ba39a1d396c0
       
     1 #!/bin/sh -
       
     2 # === HWMAP-to-Lua converter ===
       
     3 # This script allows you to put arbitrary HWMAPs into your missions!
       
     4 #
       
     5 # Usage:
       
     6 # It expects a .hwmap file of name "map.hwmap" to be in
       
     7 # its directory and creates a Lua file (map.lua) containing code to
       
     8 # draw the map.
       
     9 # In Lua, call drawMap() in onGameInit. And don't forget
       
    10 # to set MapGen to mgDrawn. Then your map should be ready to go! :-)
       
    11 
       
    12 # FILE NAMES 
       
    13 IN="./map.hwmap";
       
    14 OUT="./map.lua";
       
    15 
       
    16 # TEMPORARY FILES
       
    17 TEMP_UNBASE=$(mktemp);
       
    18 TEMP_GZIP=$(mktemp);
       
    19 TEMP_OCTETS=$(mktemp);
       
    20 base64 -d $IN | tail -c +7 | head -c -4 > $TEMP_UNBASE;
       
    21 echo -ne "\x1f\x8b\x08\0\0\0\0\0\x02\xff" > $TEMP_GZIP;
       
    22 # Suppress gunzip warning: "gzip: stdin: unexpected end of file"
       
    23 cat $TEMP_GZIP $TEMP_UNBASE | gunzip 2> /dev/null > $TEMP_OCTETS;
       
    24 C=0;
       
    25 echo -n '-- Map definition automatically converted from HWMAP file by hwmap2lua.sh
       
    26 local map = {' > $OUT;
       
    27 od -w240 -t u1 $TEMP_OCTETS | grep -Ev "^[0-9]*[[:space:]]*$" | while read f;
       
    28 do C=$((C+1));
       
    29 	if ((C!=1));
       
    30 	then
       
    31 		echo "," >> $OUT;
       
    32 	fi;
       
    33 	echo -n $f | sed "s/^......./'/;s/  */\\\\/g;s/$/'/" >> $OUT;
       
    34 done;
       
    35 echo '}
       
    36 
       
    37 local function drawMap()
       
    38 	for m=1, #map do
       
    39 		ParseCommand("draw "..map[m])
       
    40 	end
       
    41 end' >> $OUT;
       
    42 rm $TEMP_UNBASE $TEMP_GZIP $TEMP_OCTETS;