2525from sc2reader .data import builds as datapacks
2626from sc2reader .exceptions import SC2ReaderLocalizationError
2727from sc2reader .objects import Participant , Observer , Computer , Team , PlayerSummary , Graph , BuildEntry
28- from sc2reader .constants import REGIONS , LOCALIZED_RACES , GAME_SPEED_FACTOR , LOBBY_PROPERTIES , GATEWAY_LOOKUP
28+ from sc2reader .constants import REGIONS , GAME_SPEED_FACTOR , LOBBY_PROPERTIES
2929
3030
3131def real_type (teams ):
@@ -687,11 +687,11 @@ class GameSummary(Resource):
687687 def __init__ (self , summary_file , filename = None , lang = 'enUS' , ** options ):
688688 super (GameSummary , self ).__init__ (summary_file , filename , lang = lang , ** options )
689689
690- #: A list of teams
690+ #: A dict of team# -> teams
691691 self .team = dict ()
692692
693- #: A dict of team# -> team
694- self .teams = dict ()
693+ #: A list of teams
694+ self .teams = list ()
695695
696696 #: Players, a dict of :class`PlayerSummary` from the game
697697 self .players = list ()
@@ -712,7 +712,6 @@ def __init__(self, summary_file, filename=None, lang='enUS', **options):
712712 self .localization_urls = dict ()
713713 self .lobby_properties = dict ()
714714 self .lobby_player_properties = dict ()
715- self .teams = dict ()
716715 self .game_type = str ()
717716 self .real_type = str ()
718717
@@ -745,8 +744,8 @@ def __init__(self, summary_file, filename=None, lang='enUS', **options):
745744 else :
746745 self .expansion = ''
747746
748- self .game_type = self .settings ['Teams' ].replace (" " ,"" )
749- self .real_type = real_type (self .teams . values () )
747+ self .game_type = self .settings ['Teams' ].replace (" " , "" )
748+ self .real_type = real_type (self .teams )
750749
751750 # The s2gs file also keeps reference to a series of s2mv files
752751 # Some of these appear to be encoded bytes and others appear to be
@@ -810,9 +809,10 @@ def load_translations(self):
810809 #
811810 # For now we'll only do this for english localizations.
812811 self .lang_sheets = dict ()
813- self .translations = dict ()
812+ self .translations = dict ()
814813 for lang , files in self .localization_urls .items ():
815- if lang != self .opt .lang : continue
814+ if lang != self .opt .lang :
815+ continue
816816
817817 sheets = list ()
818818 for depot_file in files :
@@ -824,7 +824,7 @@ def load_translations(self):
824824 translation [uid ] = sheets [sheet ][item ]
825825 elif self .opt .debug :
826826 msg = "No {0} translation for sheet {1}, item {2}"
827- raise SC2ReaderLocalizationError (msg .format (self .opt .lang ,sheet ,item ))
827+ raise SC2ReaderLocalizationError (msg .format (self .opt .lang , sheet , item ))
828828 else :
829829 translation [uid ] = "Unknown"
830830
@@ -853,10 +853,11 @@ def load_settings(self):
853853 settings [setting [0 ][1 ]] = [p [0 ] for p in setting [1 ]]
854854
855855 activated = dict ()
856+
856857 def use_property (prop , player = None ):
857858 # Check the cache before recomputing
858859 if (prop .id , player ) in activated :
859- return activated [(prop .id ,player )]
860+ return activated [(prop .id , player )]
860861
861862 # A property can only be used if it's requirements
862863 # are both active and have one if the required settings.
@@ -875,7 +876,7 @@ def use_property(prop, player=None):
875876 if requirement .is_lobby :
876877 values = [setting ]
877878 else :
878- values = [setting [player ]] if player != None else setting
879+ values = [setting [player ]] if player is not None else setting
879880
880881 # Because of the above complication we resort to a set intersection of
881882 # the applicable values and the set of required values.
@@ -887,7 +888,7 @@ def use_property(prop, player=None):
887888 use = True
888889
889890 # Record the result for future reference and return
890- activated [(prop .id ,player )] = use
891+ activated [(prop .id , player )] = use
891892 return use
892893
893894 translation = self .translations [self .opt .lang ]
@@ -896,7 +897,7 @@ def use_property(prop, player=None):
896897 if prop .is_lobby :
897898 if use_property (prop ):
898899 value = prop .values [settings [uid ]][0 ]
899- self .settings [name ] = translation [(uid ,value )]
900+ self .settings [name ] = translation [(uid , value )]
900901 else :
901902 for index , player_setting in enumerate (settings [uid ]):
902903 if use_property (prop , index ):
@@ -906,7 +907,7 @@ def use_property(prop, player=None):
906907 def load_player_stats (self ):
907908 translation = self .translations [self .opt .lang ]
908909
909- stat_items = sum ([p [0 ] for p in self .parts [3 :]],[])
910+ stat_items = sum ([p [0 ] for p in self .parts [3 :]], [])
910911
911912 for item in stat_items :
912913 # Each stat item is laid out as follows
@@ -922,9 +923,10 @@ def load_player_stats(self):
922923 # Build order ids are generally 16 million+
923924 if stat_id < 1000000 :
924925 for pid , value in enumerate (item [1 ]):
925- if not value : continue
926+ if not value :
927+ continue
926928
927- if stat_name in ('Army Value' ,'Resource Collection Rate' ,'Upgrade Spending' ,'Workers Active' ):
929+ if stat_name in ('Army Value' , 'Resource Collection Rate' , 'Upgrade Spending' , 'Workers Active' ):
928930 # Each point entry for the graph is laid out as follows
929931 #
930932 # {0:Value, 1:0, 2:Time}
@@ -960,7 +962,8 @@ def load_player_stats(self):
960962
961963 def load_players (self ):
962964 for index , struct in enumerate (self .parts [0 ][3 ]):
963- if not struct [0 ] or not struct [0 ][1 ]: continue # Slot is closed
965+ if not struct [0 ] or not struct [0 ][1 ]:
966+ continue # Slot is closed
964967
965968 player = PlayerSummary (struct [0 ][0 ])
966969 stats = self .player_stats .get (index , dict ())
@@ -975,21 +978,23 @@ def load_players(self):
975978 player .unknown2 = struct [0 ][1 ][1 ]
976979
977980 # Either a referee or a spectator, nothing else to do
978- if settings .get ('Participant Role' ,'' ) != 'Participant' :
981+ if settings .get ('Participant Role' , '' ) != 'Participant' :
979982 self .observers .append (player )
980983 continue
981984
982985 player .play_race = LOBBY_PROPERTIES [0xBB9 ][1 ].get (struct [2 ], None )
983986
984- player .is_winner = isinstance (struct [1 ],dict ) and struct [1 ][0 ] == 0
987+ player .is_winner = isinstance (struct [1 ], dict ) and struct [1 ][0 ] == 0
985988 if player .is_winner :
986989 self .winners .append (player .pid )
987990
988991 team_id = int (settings ['Team' ].split (' ' )[1 ])
989- if team_id not in self .teams :
990- self .teams [team_id ] = Team (team_id )
991- player .team = self .teams [team_id ]
992- self .teams [team_id ].players .append (player )
992+ if team_id not in self .team :
993+ self .team [team_id ] = Team (team_id )
994+ self .teams .append (self .team [team_id ])
995+
996+ player .team = self .team [team_id ]
997+ self .team [team_id ].players .append (player )
993998
994999 # We can just copy these settings right over
9951000 player .color = utils .Color (name = settings .get ('Color' , None ))
@@ -1017,7 +1022,7 @@ def load_players(self):
10171022 # HotS Stats
10181023 player .upgrade_spending_graph = stats .get ('Upgrade Spending' , None )
10191024 player .workers_active_graph = stats .get ('Workers Active' , None )
1020- player .enemies_destroyed = stats .get ('Enemies Destroyed:' ,None )
1025+ player .enemies_destroyed = stats .get ('Enemies Destroyed:' , None )
10211026 player .time_supply_capped = stats .get ('Time Supply Capped' , None )
10221027 player .idle_production_time = stats .get ('Idle Production Time' , None )
10231028 player .resources_spent = stats .get ('Resources Spent:' , None )
@@ -1045,7 +1050,7 @@ def load_players(self):
10451050
10461051 def __str__ (self ):
10471052 return "{0} - {1} {2}" .format (self .start_time ,self .game_length ,
1048- 'v' .join ('' .join (p .play_race [0 ] for p in team .players ) for team in self .teams . values () ))
1053+ 'v' .join ('' .join (p .play_race [0 ] for p in team .players ) for team in self .teams ))
10491054
10501055
10511056
0 commit comments