forked from gamingrobot/WotMiniMapMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakemaps.py
More file actions
191 lines (168 loc) · 7.88 KB
/
Copy pathmakemaps.py
File metadata and controls
191 lines (168 loc) · 7.88 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
from xml.dom.minidom import parseString
from bs4 import BeautifulSoup
import os
import re
import string
import math
import Image
# both x and y dimensions are equal
targetMapSize = 500.0
iconSize = 64.0
r = re.compile("(.*)_([0-9]{2,3}).xml")
def main():
for filename in os.listdir("arena_defs_decoded"):
readxml(filename)
def readxml(filename):
file = open('arena_defs_decoded/' + filename, 'r')
#convert to string:
data = file.read()
#close file because we dont need it anymore:
file.close()
m = r.search(filename)
filename = m.group(2) + '_' + m.group(1)
print filename
soup = BeautifulSoup(data, 'xml')
bottomLeft = soup.find("bottomLeft").contents
upperRight = soup.find("upperRight").contents
x2, y2 = string.split(bottomLeft[0].replace(',', '.'))
x1, y1 = string.split(upperRight[0].replace(',', '.'))
x2, y2 = float(x2), float(y2)
x1, y1 = float(x1), float(y1)
oldBoundingBox = [x1, x2, y1, y2]
if (math.fabs(x1) + math.fabs(x2)) != (math.fabs(y1) + math.fabs(y2)):
print "Could not process " + str(filename) + ": map dimensions do not match!"
return
ctf = soup.find("ctf")
ass = soup.find("assault")
dom = soup.find("domination")
if ctf != None:
#print "CTF"
background = Image.open("mapsRaw/" + filename + "/mmap.png")
teamBasePositions = ctf.find("teamBasePositions")
team1 = teamBasePositions.find("team1")
team2 = teamBasePositions.find("team2")
team1Position = team1.find(re.compile("^position"))
team2Position = team2.find(re.compile("^position"))
#print team1Position, team2Position
#scale and place on map
foreground = Image.open("icon/" + 'base_green' + ".png")
inx, iny = convertScaleToXY(team1Position.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
#put second team in
foreground = Image.open("icon/" + 'base_red' + ".png")
inx, iny = convertScaleToXY(team2Position.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
#do spawn points
teamSpawnPoints = ctf.find("teamSpawnPoints")
if teamSpawnPoints != None:
team1 = teamSpawnPoints.find("team1")
team2 = teamSpawnPoints.find("team2")
team1SpawnPoint = team1.find_all("position")
team2SpawnPoint = team2.find_all("position")
#print team1SpawnPoint, team2SpawnPoint
#team1 first
counter = 1
for spawn in team1SpawnPoint:
foreground = Image.open("icon/" + 'spawn_green_' + str(counter) + ".png")
inx, iny = convertScaleToXY(spawn.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
counter += 1
#team2 second
counter = 1
for spawn in team2SpawnPoint:
foreground = Image.open("icon/" + 'spawn_red_' + str(counter) + ".png")
inx, iny = convertScaleToXY(spawn.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
counter += 1
background.save("gridding/in/" + filename + "_" + "ctf" + ".png")
if ass != None:
#print "ASS"
background = Image.open("mapsRaw/" + filename + "/mmap.png")
teamBasePositions = ass.find("teamBasePositions")
if teamBasePositions != None:
team1 = teamBasePositions.find("team1")
team2 = teamBasePositions.find("team2")
team1Position = team1.find(re.compile("^position"))
team2Position = team2.find(re.compile("^position"))
#print team1Position, team2Position
#first team: scale and place on map
if team1Position != None:
foreground = Image.open("icon/" + 'base_green' + ".png")
inx, iny = convertScaleToXY(team1Position.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
#put second team in
if team2Position != None:
foreground = Image.open("icon/" + 'base_red' + ".png")
inx, iny = convertScaleToXY(team2Position.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
#find spawn points
teamSpawnPoints = ass.find("teamSpawnPoints")
if teamSpawnPoints != None:
team1 = teamSpawnPoints.find("team1")
team2 = teamSpawnPoints.find("team2")
team1SpawnPoint = team1.find_all("position")
team2SpawnPoint = team2.find_all("position")
#print team1SpawnPoint, team2SpawnPoint
#team1 first
counter = 1
for spawn in team1SpawnPoint:
foreground = Image.open("icon/" + 'spawn_green_' + str(counter) + ".png")
inx, iny = convertScaleToXY(spawn.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
counter += 1
#team2 second
counter = 1
for spawn in team2SpawnPoint:
foreground = Image.open("icon/" + 'spawn_red_' + str(counter) + ".png")
inx, iny = convertScaleToXY(spawn.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
counter += 1
background.save("gridding/in/" + filename + "_" + "ass" + ".png")
if dom != None:
#print "DOM"
background = Image.open("mapsRaw/" + filename + "/mmap.png")
controlPoint = dom.find("controlPoint")
#print controlPoint
#scale and place on map
foreground = Image.open("icon/" + 'base_neutral' + ".png")
inx, iny = convertScaleToXY(controlPoint.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
#find spawn points
teamSpawnPoints = dom.find("teamSpawnPoints")
team1 = teamSpawnPoints.find("team1")
team2 = teamSpawnPoints.find("team2")
team1SpawnPoint = team1.find_all("position")
team2SpawnPoint = team2.find_all("position")
#print team1SpawnPoint, team2SpawnPoint
#team1 first
counter = 1
for spawn in team1SpawnPoint:
foreground = Image.open("icon/" + 'spawn_green_' + str(counter) + ".png")
inx, iny = convertScaleToXY(spawn.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
counter += 1
#team2 second
counter = 1
for spawn in team2SpawnPoint:
foreground = Image.open("icon/" + 'spawn_red_' + str(counter) + ".png")
inx, iny = convertScaleToXY(spawn.contents[0], oldBoundingBox)
background.paste(foreground, (int(inx), int(targetMapSize - iny)), foreground)
counter += 1
background.save("gridding/in/" + filename + "_" + "dom" + ".png")
def convertScaleToXY(input, oldScale):
# oldScale is an array with values x1, x2, y1, y2
inx, iny = string.split(input)
inx, iny = round(float(inx.replace(',', '.'))), round(float(iny.replace(',', '.')))
# move coordinates to start from (0,0)
inx = inx - min(oldScale[0],oldScale[1])
iny = iny - min(oldScale[2],oldScale[3])
oldMaxX = math.fabs(oldScale[0]) + math.fabs(oldScale[1])
oldMaxY = math.fabs(oldScale[2]) + math.fabs(oldScale[3])
x = inx / oldMaxX * targetMapSize
y = iny / oldMaxY * targetMapSize
# set icon center at coordinates
x -= iconSize / 2
y += iconSize / 2
return float(x), float(y)
if __name__ == '__main__':
main()