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