equal
deleted
inserted
replaced
|
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 # Many thanks to szczur! |
|
13 |
|
14 # FILE NAMES |
|
15 IN="./map.hwmap"; |
|
16 OUT="./map.lua"; |
|
17 |
|
18 # TEMPORARY FILES |
|
19 TEMP_UNBASE=$(mktemp); |
|
20 TEMP_GZIP=$(mktemp); |
|
21 TEMP_OCTETS=$(mktemp); |
|
22 base64 -d $IN | tail -c +7 | head -c -4 > $TEMP_UNBASE; |
|
23 echo -ne "\x1f\x8b\x08\0\0\0\0\0\x02\xff" > $TEMP_GZIP; |
|
24 # Suppress gunzip warning: "gzip: stdin: unexpected end of file" |
|
25 cat $TEMP_GZIP $TEMP_UNBASE | gunzip 2> /dev/null > $TEMP_OCTETS; |
|
26 C=0; |
|
27 echo -n '-- Map definition automatically converted from HWMAP file by hwmap2lua.sh |
|
28 local map = {' > $OUT; |
|
29 od -w240 -t u1 $TEMP_OCTETS | grep -Ev "^[0-9]*[[:space:]]*$" | while read f; |
|
30 do C=$((C+1)); |
|
31 if ((C!=1)); |
|
32 then |
|
33 echo "," >> $OUT; |
|
34 fi; |
|
35 echo -n $f | sed "s/^......./'/;s/ */\\\\/g;s/$/'/" >> $OUT; |
|
36 done; |
|
37 echo '} |
|
38 |
|
39 local function drawMap() |
|
40 for m=1, #map do |
|
41 ParseCommand("draw "..map[m]) |
|
42 end |
|
43 end' >> $OUT; |
|
44 rm $TEMP_UNBASE $TEMP_GZIP $TEMP_OCTETS; |