Skip to content

Commit 7221653

Browse files
authored
Merge pull request #44 from StoicLoofah/coop_support
Add co-op support
2 parents 1816755 + df31e53 commit 7221653

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

sc2reader/data/attributes.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@
298298
"T5": "Team 5",
299299
"T6": "Team 6",
300300
"T7": "Team 7",
301-
"T8": "Team 8"
301+
"T8": "Team 8",
302+
"T9": "Team 9",
303+
"T10": "Team 10",
304+
"T11": "Team 11"
302305
}
303306
],
304307
"3000": [
@@ -697,10 +700,17 @@
697700
"Commander",
698701
{
699702
"": "Pick Commander",
703+
"Abat": "Abathur",
704+
"Alar": "Alarak",
700705
"Arta": "Artanis",
706+
"Deha": "Dehaka",
707+
"Feni": "Fenix",
708+
"Horn": "Horner",
701709
"Kara": "Karax",
702710
"Kerr": "Kerrigan",
711+
"Nova": "Nova",
703712
"Rayn": "Raynor",
713+
"Stuk": "Stukov",
704714
"Swan": "Swann",
705715
"Vora": "Vorazun",
706716
"Zaga": "Zagara"

sc2reader/objects.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def __init__(self, sid, slot_data):
124124

125125
#:
126126
self.hero_mount = slot_data['mount']
127-
127+
128128
#: The unique Battle.net account identifier in the form of
129129
#: <region_id>-S2-<subregion>-<toon_id>
130130
self.toon_handle = slot_data['toon_handle']
@@ -164,10 +164,13 @@ class Player(object):
164164
:param dict detail_data: The detail data associated with this player
165165
:param dict attribute_data: The attribute data associated with this player
166166
"""
167-
def __init__(self, pid, detail_data, attribute_data):
167+
def __init__(self, pid, slot_data, detail_data, attribute_data):
168168
#: The player's unique in-game player id
169169
self.pid = int(pid)
170170

171+
#: The player's replay.initData slot data
172+
self.slot_data = slot_data
173+
171174
#: The replay.details data on this player
172175
self.detail_data = detail_data
173176

@@ -197,6 +200,24 @@ def __init__(self, pid, detail_data, attribute_data):
197200
#: One of Protoss, Terran, Zerg
198201
self.play_race = LOCALIZED_RACES.get(detail_data['race'], detail_data['race'])
199202

203+
#: The co-op commander the player picked
204+
#: Kerrigan, Raynor, etc.
205+
self.commander = slot_data['commander']
206+
if self.commander is not None:
207+
self.commander = self.commander.decode('utf8')
208+
209+
#: The level of the co-op commander
210+
#: 1-15 or None
211+
self.commander_level = slot_data['commander_level']
212+
213+
#: The mastery level of the co-op commander
214+
#: >0 or None
215+
self.commander_mastery_level = slot_data['commander_mastery_talents']
216+
217+
#: The mastery talents picked for the co-op commander
218+
#: list of longs of length 6, each between 0 and 30
219+
self.commander_mastery_talents = slot_data['commander_mastery_talents']
220+
200221
#: A reference to a :class:`~sc2reader.utils.Color` object representing the player's color
201222
self.color = utils.Color(**detail_data['color'])
202223

@@ -290,7 +311,7 @@ class Computer(Entity, Player):
290311
"""
291312
def __init__(self, sid, slot_data, pid, detail_data, attribute_data):
292313
Entity.__init__(self, sid, slot_data)
293-
Player.__init__(self, pid, detail_data, attribute_data)
314+
Player.__init__(self, pid, slot_data, detail_data, attribute_data)
294315

295316
#: The auto-generated in-game name for this computer player
296317
self.name = detail_data['name']
@@ -316,7 +337,7 @@ class Participant(Entity, User, Player):
316337
def __init__(self, sid, slot_data, uid, init_data, pid, detail_data, attribute_data):
317338
Entity.__init__(self, sid, slot_data)
318339
User.__init__(self, uid, init_data)
319-
Player.__init__(self, pid, detail_data, attribute_data)
340+
Player.__init__(self, pid, slot_data, detail_data, attribute_data)
320341

321342
def __str__(self):
322343
return "Player {0} - {1} ({2})".format(self.pid, self.name, self.play_race)
@@ -563,7 +584,7 @@ def __init__(self, contents):
563584
# Leave early so we dont barf. Turns out ggtracker doesnt need
564585
# any of the map data thats loaded below.
565586
return
566-
587+
567588
#: Load screen type: 0 = default, 1 = custom
568589
self.load_screen_type = data.read_uint32()
569590

sc2reader/resources.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ def load_players(self):
416416
self.entities.append(Observer(slot_id, slot_data, user_id, initData['user_initial_data'][user_id], player_id))
417417
player_id += 1
418418

419-
elif slot_data['control'] == 3:
419+
elif slot_data['control'] == 3 and detail_id < len(details['players']):
420+
# detail_id check needed for coop
420421
self.entities.append(Computer(slot_id, slot_data, player_id, details['players'][detail_id], self.attributes.get(player_id, dict())))
421422
detail_id += 1
422423
player_id += 1

test_replays/coop/CoA.SC2Replay

130 KB
Binary file not shown.

test_replays/test_all.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,13 @@ def test_64469(self):
568568
factory = sc2reader.factories.SC2Factory()
569569
replay = factory.load_replay(replayfilename)
570570

571+
def test_coop(self):
572+
for replayfilename in [
573+
"test_replays/coop/CoA.SC2Replay",
574+
]:
575+
factory = sc2reader.factories.SC2Factory()
576+
replay = factory.load_replay(replayfilename)
577+
571578

572579
class TestGameEngine(unittest.TestCase):
573580
class TestEvent(object):

0 commit comments

Comments
 (0)