-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_map_web.py
95 lines (77 loc) · 2.54 KB
/
generate_map_web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import sys
import reader_map
import format_cty
from format_pic import Pic
import utils
oPath = sys.argv[1]
dlPath = sys.argv[2] if len(sys.argv) > 2 else 'DL'
m = reader_map.readData(dlPath)
width, height = len(m[0]), len(m) # in tiles
tw, th = 16, 12 # tile dimensions
dh = 4 # tile y-dist
palFnames = ('MAPICONS.PIC','MAPICON2.PIC') # tile "palletes"
for fn in palFnames:
Pic(dlPath+'/PICS/'+fn).save_image(oPath+'/'+fn+'.png')
palFnames = [fn+'.png' for fn in palFnames]
out = open(oPath + '/map.html', 'w')
out.write('''<html>
<head>
<meta charset="utf-8">
<title>Map of Darklands</title>
<style type="text/css">
body {margin:0; padding:0; font-size:xx-small;}
.c {color:yellow; text-shadow: 2px 2px #000000; position:absolute; overflow:hidden; cursor: default; width:10em;height:1.4EM}
.c:hover { color:black; text-shadow: none; background-color:white; cursor: auto; border:1px solid black; padding:0.5em; width:auto; height:auto; z-index:1}
''')
for p, fn in enumerate(palFnames):
for r in range(0,16):
for c in range(0,16):
out.write(".t%d{width:%dpx;height:%dpx;background:url('%s') %dpx %dpx;position:absolute}"\
%(p*256+r*16+c, tw, th, fn, -c*tw, -r*th))
out.write('''
</style>
</head>
<body>''')
# sprites test
'''
for pal in (0,1):
print('<div style="position:relative;width:%dpx;height:%dpx;border:1px solid green">'%(16*tw, 16*th))
for row in range(0,16):
for col in range(0,16):
print('<div class="t%d_%d_%d" style="left:%dpx;top:%dpx"></div>'%(pal, row, col, col*tw, row*th))
print('</div>')
'''
out.write('''
<div style="position:relative;width:%dpx;height:%dpx;background-color:#00a000">'''%((width+1)*tw, (height+2)*dh))
for y, ln in enumerate(m):
#if y < 550: continue
#if y > 200: continue
xc = tw/2 if y%2 else 0
#xc = 0 if y%2 else tw/2
rs = ''
for x, tile in enumerate(ln):
#if x < 200: continue
#if x > 150: continue
pal, row, col = tile
if not ((pal == 0 and row in(1, 3)) or (pal == 1 and row in (8,9,10,11,13))):
continue
rs += '<div class="t%d" style="left:%dpx;top:%dpx"></div>'%(pal*256+row*16+col, x*tw+xc, y*dh)
out.write(rs)
cities = format_cty.readData(dlPath)
for c in cities:
name = utils.tchars(c.name)
x, y = c.entry_coords
x1 = x*tw + (tw/2 if y%2 else 0)
y1 = y*dh
x2, y2 = c.exit_coords
x2 = x2 * tw + (tw/2 if y%2 else 0)
y2 = y2*dh
out.write('<div class="c" style="left:%dpx;top:%dpx">'\
%((x1+x2)//2-tw//2, (y1+y2)//2-th//2))
out.write("<b>%s</b><br><br>"%(name))
out.write(utils.itemStr(c).replace('\n','<br>'))
out.write('</div>')
out.write('''</div>
</body>
</html>''')
out.close()