|
11 | 11 |
|
12 | 12 | from sc2reader import utils |
13 | 13 | from sc2reader import log_utils |
14 | | -from sc2reader.objects import Player, Observer, Team |
| 14 | +from sc2reader.objects import Player, Observer, Team, PlayerSummary |
15 | 15 | from sc2reader.constants import REGIONS, LOCALIZED_RACES, GAME_SPEED_FACTOR |
16 | 16 |
|
17 | 17 |
|
@@ -407,20 +407,42 @@ def read_game_strings(self): |
407 | 407 |
|
408 | 408 | class GameSummary(Resource): |
409 | 409 | url_template = 'http://{0}.depot.battle.net:1119/{1}.s2gs' |
| 410 | + |
| 411 | + race_map = { |
| 412 | + 'Zerg' : 'Zerg', |
| 413 | + 'Terr' : 'Terran', |
| 414 | + 'Prot' : 'Protoss', |
| 415 | + 'RAND' : 'Random' |
| 416 | + } |
| 417 | + |
| 418 | + |
| 419 | + #: Players, a list of :class`PlayerSummary` from the game |
| 420 | + players = list() |
| 421 | + |
410 | 422 | def __init__(self, summary_file, filename=None, **options): |
411 | 423 | super(GameSummary, self).__init__(summary_file, filename,**options) |
412 | 424 | self.data = zlib.decompress(summary_file.read()[16:]) |
413 | 425 | self.parts = list() |
414 | 426 | buffer = utils.ReplayBuffer(self.data) |
415 | 427 | while buffer.left: |
416 | 428 | part = buffer.read_data_struct() |
417 | | -# print str(part)+"\n\n\n" |
418 | 429 | self.parts.append(part) |
419 | | -# print len(self.parts) |
420 | | -# pprint.PrettyPrinter(indent=2).pprint(self.parts) |
421 | | - for index, name in s2gsmap: |
422 | | - for player in [0, 1]: |
423 | | - print "Player", player, name, self.parts[3][0][index][1][player][0][0] |
| 430 | + |
| 431 | + #Parse players, 16 is the maximum amount of players |
| 432 | + for i in range(16): |
| 433 | + player = None |
| 434 | + # Check if player, break if not |
| 435 | + if self.parts[0][3][i][2] == '\x00\x00\x00\x00': |
| 436 | + break |
| 437 | + player_struct = self.parts[0][3][i] |
| 438 | + |
| 439 | + player = PlayerSummary(i) |
| 440 | + player.race = self.race_map[player_struct[2]] |
| 441 | + player.bnetid = player_struct[0][1][0][3] |
| 442 | + player.subregion = player_struct[0][1][0][2] |
| 443 | + |
| 444 | + self.players.append(player) |
| 445 | + |
424 | 446 |
|
425 | 447 | class MapInfo(Resource): |
426 | 448 | url_template = 'http://{0}.depot.battle.net:1119/{1}.s2mi' |
|
0 commit comments