forked from MrCheeze/skywardsword-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathallobjects.py
186 lines (162 loc) · 6.51 KB
/
allobjects.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
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
import json
import glob
import os.path
try:
from .util import *
except ImportError:
from util import *
try:
from .eventnumbers import foundevents
except ImportError:
from eventnumbers import foundevents
basepath = os.path.abspath(os.path.dirname(__file__))
with open(basepath + '/allsceneflags.json') as f:
all_scene_flags=json.load(f)
with open(basepath + '/allstoryflags.json') as f:
all_story_flags=json.load(f)
with open(basepath + '/allitems.json') as f:
all_items=json.load(f)
all_stages={}
totally_all_objects=[]
raw_stages={}
all_ENVTS=[]
all_AREAS=[]
all_PLY=[]
sizeobjs = ('SOBS','SOBJ','STAS','STAG','SNDT')
objs = ('OBJS','OBJ ','DOOR')
allobjtypes = sizeobjs + objs + ('AREA',)
# iterate through all object to attach some extra info/get bounds
for stagefile in glob.glob(basepath + '/output/stage/*.json'):
output={}
output['stageid']=os.path.split(stagefile)[-1][:-5]
output['stagename']=stagenames[output['stageid']]
maxx=0
minx=0
maxz=0
minz=0
all_objects=[]
with open(stagefile) as f:
raw_stage=json.load(f)
raw_stages[output['stageid']]=raw_stage
stage={'rooms': raw_stage['rooms']}
for (objt, objects) in raw_stage.items():
if not objt in allobjtypes:
continue
for obj in objects:
# find min max bounds
maxx=max(maxx,obj['posx'])
maxz=max(maxz,obj['posz'])
minx=min(minx,obj['posx'])
minz=min(minz,obj['posz'])
obj['type'] = objt
obj['roomid'] = -1
obj['layerid'] = 0
obj['stageid'] = output['stageid']
all_objects.append(obj)
totally_all_objects.append(obj)
for (lid, layer) in raw_stage['LAY '].items():
for (objt, objects) in layer.items():
if not objt in allobjtypes:
continue
for obj in objects:
# find min max bounds
maxx=max(maxx,obj['posx'])
maxz=max(maxz,obj['posz'])
minx=min(minx,obj['posx'])
minz=min(minz,obj['posz'])
obj['type'] = objt
obj['roomid'] = -1
obj['layerid'] = int(lid[1:])
obj['stageid'] = output['stageid']
all_objects.append(obj)
totally_all_objects.append(obj)
for (rid, room) in stage['rooms'].items():
if 'EVNT' in room:
all_ENVTS.extend(room['EVNT'])
all_PLY.extend(room.get('PLY ',[]))
for obj in room.get('AREA',[]):
# find min max bounds
maxx=max(maxx,obj['posx'])
maxz=max(maxz,obj['posz'])
minx=min(minx,obj['posx'])
minz=min(minz,obj['posz'])
obj['type'] = 'AREA'
obj['name'] = 'AREA'
obj['roomid'] = int(rid[1:])
obj['layerid'] = 0 # no layer would be more accurate
obj['stageid'] = output['stageid']
all_objects.append(obj)
totally_all_objects.append(obj)
for (objt, objects) in room.items():
if not objt in allobjtypes:
continue
for obj in objects:
# find min max bounds
maxx=max(maxx,obj['posx'])
maxz=max(maxz,obj['posz'])
minx=min(minx,obj['posx'])
minz=min(minz,obj['posz'])
obj['type'] = objt
obj['roomid'] = int(rid[1:])
obj['layerid'] = 0
obj['stageid'] = output['stageid']
all_objects.append(obj)
totally_all_objects.append(obj)
for (lid, layer) in room['LAY '].items():
for (objt, objects) in layer.items():
if not objt in allobjtypes:
continue
for obj in objects:
# find min max bounds
maxx=max(maxx,obj['posx'])
maxz=max(maxz,obj['posz'])
minx=min(minx,obj['posx'])
minz=min(minz,obj['posz'])
obj['type'] = objt
obj['roomid'] = int(rid[1:])
obj['layerid'] = int(lid[1:])
obj['stageid'] = output['stageid']
all_objects.append(obj)
totally_all_objects.append(obj)
# repeat for every stage
used_layers=sorted(set(obj['layerid'] for obj in all_objects))
used_rooms=sorted(set(obj['roomid'] for obj in all_objects))
output['maxx']=maxx
output['minx']=minx
output['maxz']=maxz
output['minz']=minz
output['usedLayers']=used_layers
output['usedRooms']=used_rooms
output['allObjects']=all_objects
all_stages[output['stageid']]=output
for obj in totally_all_objects:
if obj.get('talk_behaviour',None) in foundevents:
if not 'extra_info' in obj:
obj['extra_info'] = {}
obj['extra_info']['eventSrc'] = foundevents[obj['talk_behaviour']]
if obj.get('extra_info',{}).get('talk_behaviour',None) in foundevents:
obj['extra_info']['eventSrc'] = foundevents[obj['extra_info']['talk_behaviour']]
# typnamemap = collections.OrderedDict()
# for typ in allobjtypes:
# typnamemap[typ] = collections.Counter((a['name'] for a in totally_all_objects if a['type']==typ))
# for typ, counter in typnamemap.items():
# print('\n'+typ+':')
# for item, count in counter.most_common():
# print('%s: %d'%(item,count))
# all_unknown=[]
# for i, stages in enumerate(flagindex_to_stages):
# for stage in stages:
# for obj in all_stages[stage]['allObjects']:
# if 'extraInfo' in obj and 'flagid' in obj['extraInfo']:
# flagid=obj['extraInfo']['flagid']
# if flagid>=0:
# flagdesc=all_scene_flags[i]['sceneflags'][flagid]
# if flagdesc.strip()=='' or '[' in flagdesc:
# all_unknown.append(obj)
# blacklist=set(('posx','posy','posz','sizex','sizey','sizez','extraInfo'))
# info=collections.defaultdict(set)
# for obj in totally_all_objects:
# if obj['name'] == 'NpcTke':
# for k,v in obj.items():
# if not k in blacklist:
# info[k].add(v)