Skip to content

Commit b4cc31d

Browse files
committed
Modifies the observer creation algorithm.
In particular it accounts for a rare situation where the player names listed in the initData file are not in pid order as I had previously assumed to be true.
1 parent 236c2af commit b4cc31d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

sc2reader/replay.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def load_players(self):
198198
return
199199

200200
# Create and add the players based on attribute and details information
201-
player_index, observer_index, default_region = 0, 0, ''
201+
player_index, obs_index, default_region = 0, 1, ''
202202
player_data = self.raw_data['replay.details'].players
203203
for pid, attributes in sorted(self.attributes.iteritems()):
204204

@@ -217,7 +217,7 @@ def load_players(self):
217217
# If this is a human player, push back the initial observer index in
218218
# the list of all human players we gathered from the initdata file.
219219
if attributes['Player Type'] == 'Human':
220-
observer_index += 1
220+
obs_index += 1
221221

222222
# Create the player using the current pid and the player name from
223223
# The details file. This works because players are stored in order
@@ -293,12 +293,17 @@ def load_players(self):
293293
player.region = default_region
294294

295295
# Create observers out of the leftover names gathered from initData
296-
all_players = self.raw_data['replay.initData'].player_names
297-
for i in range(observer_index,len(all_players)):
298-
observer = Observer(i+1,all_players[i])
296+
all_players = [p.name for p in self.players]
297+
all_people = self.raw_data['replay.initData'].player_names
298+
for obs_name in all_people:
299+
if obs_name in all_players: continue
300+
301+
observer = Observer(obs_index,obs_name)
302+
observer.gateway = self.gateway
299303
self.observers.append(observer)
300304
self.people.append(observer)
301-
self.person[i+1] = observer
305+
self.person[obs_index] = observer
306+
obs_index += 1
302307

303308
# Miscellaneous people processing
304309
self.humans = filter(lambda p: p.is_human, self.people)

0 commit comments

Comments
 (0)