Skip to content

Commit 4e7f5fb

Browse files
committed
Add co-op support
1 parent 155ae25 commit 4e7f5fb

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

sc2reader/data/attributes.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@
298298
"T5": "Team 5",
299299
"T6": "Team 6",
300300
"T7": "Team 7",
301-
"T8": "Team 8"
301+
"T8": "Team 8",
302+
"T9": "Team 9"
302303
}
303304
],
304305
"3000": [
@@ -697,10 +698,17 @@
697698
"Commander",
698699
{
699700
"": "Pick Commander",
701+
"Abat": "Abathur",
702+
"Alar": "Alarak",
700703
"Arta": "Artanis",
704+
"Deha": "Dehaka",
705+
"Feni": "Fenix",
706+
"Horn": "Horner",
701707
"Kara": "Karax",
702708
"Kerr": "Kerrigan",
709+
"Nova": "Nova",
703710
"Rayn": "Raynor",
711+
"Stuk": "Stukov",
704712
"Swan": "Swann",
705713
"Vora": "Vorazun",
706714
"Zaga": "Zagara"

sc2reader/objects.py

Lines changed: 11 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,9 @@ 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+
self.commander = slot_data['commander']
205+
200206
#: A reference to a :class:`~sc2reader.utils.Color` object representing the player's color
201207
self.color = utils.Color(**detail_data['color'])
202208

@@ -290,7 +296,7 @@ class Computer(Entity, Player):
290296
"""
291297
def __init__(self, sid, slot_data, pid, detail_data, attribute_data):
292298
Entity.__init__(self, sid, slot_data)
293-
Player.__init__(self, pid, detail_data, attribute_data)
299+
Player.__init__(self, pid, slot_data, detail_data, attribute_data)
294300

295301
#: The auto-generated in-game name for this computer player
296302
self.name = detail_data['name']
@@ -316,7 +322,7 @@ class Participant(Entity, User, Player):
316322
def __init__(self, sid, slot_data, uid, init_data, pid, detail_data, attribute_data):
317323
Entity.__init__(self, sid, slot_data)
318324
User.__init__(self, uid, init_data)
319-
Player.__init__(self, pid, detail_data, attribute_data)
325+
Player.__init__(self, pid, slot_data, detail_data, attribute_data)
320326

321327
def __str__(self):
322328
return "Player {0} - {1} ({2})".format(self.pid, self.name, self.play_race)
@@ -563,7 +569,7 @@ def __init__(self, contents):
563569
# Leave early so we dont barf. Turns out ggtracker doesnt need
564570
# any of the map data thats loaded below.
565571
return
566-
572+
567573
#: Load screen type: 0 = default, 1 = custom
568574
self.load_screen_type = data.read_uint32()
569575

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
@@ -561,6 +561,13 @@ def test_59587(self):
561561
factory = sc2reader.factories.SC2Factory()
562562
replay = factory.load_replay(replayfilename)
563563

564+
def test_coop(self):
565+
for replayfilename in [
566+
"test_replays/coop/CoA.SC2Replay",
567+
]:
568+
factory = sc2reader.factories.SC2Factory()
569+
replay = factory.load_replay(replayfilename)
570+
564571

565572
class TestGameEngine(unittest.TestCase):
566573
class TestEvent(object):

0 commit comments

Comments
 (0)