Skip to content

Commit b6ef88a

Browse files
committed
Catch and correct the computer edge case (computers don't have subregions).
1 parent a9799eb commit b6ef88a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

sc2reader/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@
145145
'232323': 'Dark grey',
146146
'E55BB0': 'Pink'
147147
}
148+
149+
# TODO: We need a better mapping of subregions
148150
REGIONS = {
149151
'us': {
150152
1: 'us',

sc2reader/processors.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def Full(replay):
3737
return replay
3838

3939
# Create and add the players based on attribute and details information
40-
player_index, observer_index = 0, 0
40+
player_index, observer_index, default_region = 0, 0, ''
4141
player_data = replay.raw.details.players
4242
for pid, attributes in sorted(attribute_data.iteritems()):
4343

@@ -93,12 +93,14 @@ def Full(replay):
9393
player.type = attributes['Player Type']
9494
player.uid = pdata.bnet.uid
9595
player.subregion = pdata.bnet.subregion
96-
player.region = REGIONS[replay.gateway][player.subregion]
9796
player.handicap = pdata.handicap
9897

9998
# We need initData for the gateway which is required to build the url!
10099
if 'initData' in replay.raw and replay.gateway:
101100
player.gateway = replay.gateway
101+
if player.type == 'Human':
102+
player.region = REGIONS[replay.gateway][player.subregion]
103+
default_region = player.region
102104

103105
# Conversion instructions to the new color object:
104106
# color_rgba is the color object itself
@@ -118,6 +120,13 @@ def Full(replay):
118120
team.lineup = sorted(player.play_race[0].upper() for player in team)
119121

120122
if 'initData' in replay.raw:
123+
# Assign the default region to computer players for consistency
124+
# We know there will be a default region because there must be
125+
# atleast 1 human player or we wouldn't have a replay.
126+
for player in replay.players:
127+
if player.type == 'Computer':
128+
player.region = default_region
129+
121130
# Create observers out of the leftover names gathered from initData
122131
all_players = replay.raw.initData.player_names
123132
for i in range(observer_index,len(all_players)):

0 commit comments

Comments
 (0)