@@ -335,27 +335,22 @@ def load_players(self):
335
335
if 'replay.initData' not in self .raw_data :
336
336
return
337
337
338
- # 1. pids are in lobby join order, use initData.player_names
339
- # 2. use the name to get the player_data index
340
- # 2a. if observer, save pid+name for later
341
- # 3. use the player_data index as the attrib_data index...?
342
- # 4. use the player_data and attribute_data to load the player
343
- # 5. after loop, load the computer players and (optionally) their attributes
344
- # 6. then load the observer pid,name using attributes if available
338
+ self .clients = list ()
339
+ self .client = dict ()
340
+
341
+ def createObserver (pid , name , attributes ):
342
+ # TODO: Make use of that attributes, new in HotS
343
+ observer = Observer (pid , name )
344
+ return observer
345
+
345
346
def createPlayer (pid , pdata , attributes ):
346
- # General information re: each player comes from the following files
347
- # * replay.initData
348
- # * replay.details
349
- # * replay.attribute.events
350
- #
351
- # TODO: recognize current locale and use that instead of western
352
- # TODO: fill in the LOCALIZED_RACES table
353
- player = Player (pid ,pdata .name )
354
-
355
- # Cross reference the player and team lookups
356
- # TODO: Players without attribute events, where do we get the team info?
357
- # print pdata.name, attributes, pdata
358
- team_number = attributes .get ('Teams' + self .type ,0 )
347
+ # make sure to strip the clan tag out of the name
348
+ name = pdata .name .split ("]" )[- 1 ]
349
+ player = Player (pid , name )
350
+
351
+ # In some beta patches attribute information is missing
352
+ # Just assign them to team 2 to keep the issue from being fatal
353
+ team_number = attributes .get ('Teams' + self .type ,2 )
359
354
if not team_number in self .team :
360
355
self .team [team_number ] = Team (team_number )
361
356
self .teams .append (self .team [team_number ])
@@ -368,70 +363,50 @@ def createPlayer(pid, pdata, attributes):
368
363
self .winner = player .team
369
364
elif pdata .result == 2 :
370
365
player .team .result = "Loss"
366
+ else :
367
+ pass # We don't need to do anything here?
371
368
372
369
player .pick_race = attributes .get ('Race' ,'Unknown' )
373
370
player .play_race = LOCALIZED_RACES .get (pdata .race , pdata .race )
374
371
player .difficulty = attributes .get ('Difficulty' ,'Unknown' )
375
372
player .is_human = (attributes .get ('Player Type' ,'Computer' ) == 'Human' )
376
373
player .uid = pdata .bnet .uid
377
374
player .subregion = pdata .bnet .subregion
375
+ player .gateway = {0 :'' , 1 :'us' ,2 :'eu' ,3 :'kr' ,6 :'sea' , 98 :'xx' }[pdata .bnet .unknown1 ] # actually is gateway!!!
378
376
player .handicap = pdata .handicap
379
-
380
- # We need initData for the gateway portion of the url!
381
- if self .gateway :
382
- player .gateway = self .gateway
383
- if player .is_human and player .subregion :
384
- player .region = REGIONS [self .gateway ].get (player .subregion , 'Unknown' )
385
-
386
- # Conversion instructions to the new color object:
387
- # color_rgba is the color object itself
388
- # color_hex is color.hex
389
- # color is str(color)
390
377
player .color = utils .Color (** pdata .color ._asdict ())
378
+ return player
391
379
392
- # Each player can be referenced in a number of different ways,
393
- # primarily for convenience of access in any given situation.
394
- self .people .append (player )
380
+
381
+ pid = 0
382
+ clients = self .raw_data ['replay.initData' ].player_names
383
+ for index , pdata in enumerate (self .raw_data ['replay.details' ].players ):
384
+ pid += 1
385
+ attributes = self .attributes .get (pid , dict ())
386
+ player = createPlayer (pid , pdata , attributes )
387
+ self .player [pid ] = player
395
388
self .players .append (player )
396
389
self .player [pid ] = player
390
+ self .people .append (player )
397
391
self .person [pid ] = player
398
392
399
- def createObserver (pid , name , attributes ):
400
- observer = Observer (pid ,name )
401
- self .observers .append (observer )
402
- self .people .append (observer )
403
- self .person [pid ] = observer
404
-
405
- observer_data = list ()
406
- unassigned_player_data = collections .OrderedDict ((p .name , (idx ,p )) for idx , p in enumerate (self .raw_data ['replay.details' ].players ))
407
- try :
408
- for pid , name in enumerate (self .raw_data ['replay.initData' ].player_names ):
409
- if name in unassigned_player_data :
410
- idx , pdata = unassigned_player_data [name ]
411
- attributes = self .attributes .get (idx ,dict ())
412
- createPlayer (pid , pdata , attributes )
413
- del unassigned_player_data [name ]
414
- else :
415
- observer_data .append ((pid ,name ))
416
-
417
- comp_start_id = len (self .raw_data ['replay.initData' ].player_names )
418
- for name , (idx ,pdata ) in unassigned_player_data .items ():
419
- attributes = self .attributes .get (idx ,dict ())
420
- createPlayer (comp_start_id , pdata , attributes )
421
- comp_start_id += 1
422
-
423
- obs_start_idx = len (self .raw_data ['replay.details' ].players )
424
- for pid , name in observer_data :
425
- attributes = self .attributes .get (obs_start_idx ,dict ())
426
- createObserver (pid , name , attributes )
427
- obs_start_idx += 1
428
- except :
429
- print unassigned_player_data
430
- print self .raw_data ['replay.initData' ].player_names
431
- raise
393
+ for cid , name in enumerate (clients ):
394
+ if name not in self .player ._key_map :
395
+ pid += 1
396
+ attributes = self .attributes .get (pid , dict ())
397
+ client = createObserver (pid , name , attributes )
398
+ self .observers .append (client )
399
+ self .people .append (client )
400
+ self .person [pid ] = client
401
+ else :
402
+ client = self .player .name (name )
432
403
404
+ client .cid = cid
405
+ self .clients .append (client )
406
+ self .client [cid ] = client
433
407
434
- self .humans = filter (lambda p : p .is_human , self .people )
408
+ # replay.clients replaces replay.humans
409
+ self .humans = self .clients
435
410
436
411
#Create an store an ordered lineup string
437
412
for team in self .teams :
@@ -573,8 +548,7 @@ def register_default_readers(self):
573
548
self .register_reader ('replay.game.events' , readers .GameEventsReader_19595 (), lambda r : 19595 <= r .build < 22612 )
574
549
self .register_reader ('replay.game.events' , readers .GameEventsReader_22612 (), lambda r : 22612 <= r .build and r .expansion == 'WoL' )
575
550
self .register_reader ('replay.game.events' , readers .GameEventsReader_Beta (), lambda r : r .expansion == 'HotS' and r .build < 23925 )
576
- self .register_reader ('replay.game.events' , readers .GameEventsReader_Beta_23925 (), lambda r : r .expansion == 'HotS' and 23925 <= r .build < 24247 )
577
- self .register_reader ('replay.game.events' , readers .GameEventsReader_Beta_24247 (), lambda r : r .expansion == 'HotS' and 24247 <= r .build )
551
+ self .register_reader ('replay.game.events' , readers .GameEventsReader_Beta_23925 (), lambda r : r .expansion == 'HotS' and 23925 <= r .build )
578
552
579
553
580
554
def register_default_datapacks (self ):
0 commit comments