-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprocess_spawner.py
More file actions
117 lines (106 loc) · 3.71 KB
/
process_spawner.py
File metadata and controls
117 lines (106 loc) · 3.71 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
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
for line in f.readlines():
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:
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
}
##print lane_data
spawner_data = {}
with open('data/dota_pvp_prefab.vmap.txt', 'r') as f:
dump_on_next_brace = False
for line in f.readlines():
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:
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
}
##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))