19
19
from sc2reader .constants import REGIONS , LOCALIZED_RACES , GAME_SPEED_FACTOR , GAME_SPEED_CODES , RACE_CODES , PLAYER_TYPE_CODES , TEAM_COLOR_CODES , GAME_FORMAT_CODES , GAME_TYPE_CODES , DIFFICULTY_CODES
20
20
21
21
22
+ def real_type (teams ):
23
+ # Special case FFA games and sort outmatched games in ascending order
24
+ team_sizes = [len (team .players ) for team in teams ]
25
+ if len (team_sizes ) > 2 and sum (team_sizes ) == len (team_sizes ):
26
+ return "FFA"
27
+ else :
28
+ return "v" .join (str (size ) for size in sorted (team_sizes ))
29
+
30
+
22
31
class Resource (object ):
23
32
def __init__ (self , file_object , filename = None , ** options ):
24
33
self .opt = utils .AttributeDict (options )
@@ -399,12 +408,7 @@ def load_players(self):
399
408
for team in self .teams :
400
409
team .lineup = '' .join (sorted (player .play_race [0 ].upper () for player in team ))
401
410
402
- # Special case FFA games and sort outmatched games in ascending order
403
- team_sizes = [len (team .players ) for team in self .teams ]
404
- if len (team_sizes ) > 2 and sum (team_sizes ) == len (team_sizes ):
405
- self .real_type = "FFA"
406
- else :
407
- self .real_type = "v" .join (str (size ) for size in sorted (team_sizes ))
411
+ self .real_type = real_type (self .teams )
408
412
409
413
if 'replay.initData' in self .raw_data :
410
414
# Assign the default region to computer players for consistency
@@ -660,8 +664,9 @@ def __init__(self, summary_file, filename=None, **options):
660
664
661
665
self .observers = list ()
662
666
663
- #: Game completion time
664
- self .time = None
667
+ #: Game start and end times
668
+ self .start_time = None
669
+ self .end_time = None
665
670
666
671
self .winners = list ()
667
672
self .player = dict ()
@@ -674,6 +679,8 @@ def __init__(self, summary_file, filename=None, **options):
674
679
self .lobby_properties = dict ()
675
680
self .lobby_player_properties = dict ()
676
681
self .teams = dict ()
682
+ self .game_type = str ()
683
+ self .real_type = str ()
677
684
678
685
# The first 16 bytes appear to be some sort of compression header
679
686
buffer = utils .ReplayBuffer (zlib .decompress (summary_file .read ()[16 :]))
@@ -684,18 +691,21 @@ def __init__(self, summary_file, filename=None, **options):
684
691
while not buffer .is_empty :
685
692
self .parts .append (buffer .read_data_struct ())
686
693
687
- self .time = self .parts [0 ][8 ]
688
- self .date = datetime .utcfromtimestamp (self .parts [0 ][8 ])
694
+ self .end_time = datetime .utcfromtimestamp (self .parts [0 ][8 ])
689
695
self .game_speed = GAME_SPEED_CODES [self .parts [0 ][0 ][1 ]]
690
696
self .game_length = utils .Length (seconds = self .parts [0 ][7 ])
691
697
self .real_length = utils .Length (seconds = self .parts [0 ][7 ]/ GAME_SPEED_FACTOR [self .game_speed ])
698
+ self .start_time = datetime .utcfromtimestamp (self .parts [0 ][8 ] - self .real_length .seconds )
692
699
693
700
self .load_translations ()
694
701
self .load_settings ()
695
702
self .load_player_stats ()
696
703
self .load_player_builds ()
697
704
self .load_players ()
698
705
706
+ self .game_type = self .settings ['Teams' ].replace (" " ,"" )
707
+ self .real_type = real_type (self .teams .values ())
708
+
699
709
# The s2gs file also keeps reference to a series of s2mv files
700
710
# Some of these appear to be encoded bytes and others appear to be
701
711
# the preview images that authors may bundle with their maps.
@@ -966,7 +976,7 @@ def load_players(self):
966
976
self .player [player .pid ] = player
967
977
968
978
def __str__ (self ):
969
- return "{} - {} {}" .format (time .ctime (self .time ),self .game_length ,
979
+ return "{} - {} {}" .format (time .ctime (self .start_time ),self .game_length ,
970
980
'v' .join ('' .join (self .players [p ].race [0 ] for p in self .teams [tid ]) for tid in self .teams ))
971
981
972
982
0 commit comments