Skip to content

Commit 8b03fbb

Browse files
committed
Add Replay.game_type and Replay.real_type props.
Often the recorded type of the game does not reflect the number of players and/or teams in the game. Changes: * Replay.type => Replay.game_type * Replay.real_type now records the actual teams by players in team. NOTE: Deprecates Replay.type.
1 parent 0c7b9b4 commit 8b03fbb

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

sc2reader/resources.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,17 @@ class Replay(Resource):
5353
#: The game speed: Slower, Slow, Normal, Fast, Faster
5454
speed = str()
5555

56-
#: The game type: 1v1, 2v2, 3v3, 4v4, FFA
56+
#: Deprecated, use :member:`game_type` or :member:`real_type` instead
5757
type = str()
5858

59+
#: The game type choosen at game creation: 1v1, 2v2, 3v3, 4v4, FFA
60+
game_type = str()
61+
62+
#: The real type of the replay as observed by counting players on teams.
63+
#: For outmatched games, the smaller team numbers come first.
64+
#: Example Values: 1v1, 2v2, 3v3, FFA, 2v4, etc.
65+
real_type = str()
66+
5967
#: The category of the game, Ladder and Private
6068
category = str()
6169

@@ -172,6 +180,8 @@ def __init__(self, replay_file, filename=None, load_level=4, **options):
172180
self.other_people = set()
173181
self.speed = ""
174182
self.type = ""
183+
self.game_type = ""
184+
self.real_type = ""
175185
self.category = ""
176186
self.is_ladder = False
177187
self.is_private = False
@@ -250,7 +260,7 @@ def load_details(self):
250260
# Populate replay with attributes
251261
self.speed = self.attributes[16]['Game Speed']
252262
self.category = self.attributes[16]['Category']
253-
self.type = self.attributes[16]['Game Type']
263+
self.type = self.game_type = self.attributes[16]['Game Type']
254264
self.is_ladder = (self.category == "Ladder")
255265
self.is_private = (self.category == "Private")
256266

@@ -367,6 +377,13 @@ def load_players(self):
367377
for team in self.teams:
368378
team.lineup = sorted(player.play_race[0].upper() for player in team)
369379

380+
# Special case FFA games and sort outmatched games in ascending order
381+
team_sizes = [len(team.players) for team in self.teams]
382+
if len(team_sizes) > 2 and sum(team_sizes) == len(team_sizes):
383+
self.real_type = "FFA"
384+
else:
385+
self.real_type = "v".join(str(size) for size in sorted(team_sizes))
386+
370387
if 'replay.initData' in self.raw_data:
371388
# Assign the default region to computer players for consistency
372389
# We know there will be a default region because there must be

0 commit comments

Comments
 (0)