forked from devilesk/dota-map-coordinates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_spawner.py
135 lines (122 loc) · 4.24 KB
/
process_spawner.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
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
import json
import matplotlib.path as mplPath
import numpy as np
#targetname goes to target
lane_data = {}
with open('data/dota_pvp_prefab.vmap.txt', 'r') as f:
dump_on_next_brace = False
ent_type_found = False
for line in f.readlines():
if '"CMapEntity"' in line:
origin = [0,0]
ent_type_found = False
if '"origin"' in line:
origin = [x.replace('"', '') for x in line.strip('\n').split(" ")[-3:]]
if '"classname"' in line:
classname = line.strip('\n').split(" ")[-1].replace('"', '')
if '"targetname"' in line:
targetname = line.strip('\n').split(" ")[-1].replace('"', '')
if '"target"' in line:
target = line.strip('\n').split(" ")[-1].replace('"', '')
if '"path_corner"' in line:
ent_type_found = True
if ent_type_found and origin[0] and origin[1]:
dump_on_next_brace = True
if '}' in line and dump_on_next_brace:
dump_on_next_brace = False
## print classname, target, origin, targetname
lane_data[targetname] = {
'target': target,
'origin': origin,
'targetname': targetname
}
origin = [0,0]
ent_type_found = False
##print lane_data
spawner_data = {}
with open('data/dota_pvp_prefab.vmap.txt', 'r') as f:
dump_on_next_brace = False
ent_type_found = False
for line in f.readlines():
if '"CMapEntity"' in line:
origin = [0,0]
ent_type_found = False
if '"origin"' in line:
origin = [x.replace('"', '') for x in line.strip('\n').split(" ")[-3:]]
if '"classname"' in line:
classname = line.strip('\n').split(" ")[-1].replace('"', '')
if '"targetname"' in line:
targetname = line.strip('\n').split(" ")[-1].replace('"', '')
if 'NPCFirstWaypoint' in line:
NPCFirstWaypoint = line.strip('\n').split(" ")[-1].replace('"', '')
if 'npc_dota_spawner_' in line and '_staging' not in line:
ent_type_found = True
if ent_type_found and origin[0] and origin[1]:
dump_on_next_brace = True
if '}' in line and dump_on_next_brace:
dump_on_next_brace = False
## print classname, NPCFirstWaypoint, origin, targetname
spawner_data[classname] = {
'NPCFirstWaypoint': NPCFirstWaypoint,
'origin': origin,
'targetname': targetname
}
origin = [0,0]
ent_type_found = False
##print spawner_data
for key in spawner_data:
obj = spawner_data[key]
obj['path'] = []
waypoint = lane_data[obj['NPCFirstWaypoint']]
## print waypoint
## coord = {
## 'x': float(waypoint['origin'][0]),
## 'y': float(waypoint['origin'][1]),
#### 'targetname': waypoint['targetname']
## }
coord = [float(x) for x in waypoint['origin'][:2]]
obj['path'].append(coord)
while waypoint['target'] != "" and waypoint['target'] != waypoint['targetname']:
waypoint = lane_data[waypoint['target']]
## print waypoint
## coord = {
## 'x': float(waypoint['origin'][0]),
## 'y': float(waypoint['origin'][1]),
#### 'targetname': waypoint['targetname']
## }
coord = [float(x) for x in waypoint['origin'][:2]]
obj['path'].append(coord)
## print '----'
geojsondata = {
"type": "FeatureCollection",
"features": []
}
spawnerdata = {
"type": "FeatureCollection",
"features": []
}
for key in spawner_data:
obj = spawner_data[key]
feature = {
"type": "Feature",
"id": key,
"geometry": {
"type": "LineString",
"coordinates": obj['path']
}
}
geojsondata['features'].append(feature)
coord = [float(x) for x in obj['origin'][:2]]
feature = {
"type": "Feature",
"id": key,
"geometry": {
"type": "Point",
"coordinates": coord
}
}
spawnerdata['features'].append(feature)
with open('data/path_corner.json', 'w') as f:
f.write(json.dumps(geojsondata))
with open('data/npc_dota_spawner.json', 'w') as f:
f.write(json.dumps(spawnerdata))