Skip to content

Commit

Permalink
fix(debrief): correct inability to parse debrief
Browse files Browse the repository at this point in the history
fixes #83
  • Loading branch information
Wrycu committed Jan 3, 2020
1 parent ad3068b commit 6731461
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions userdata/debriefing.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def append_dead_object(object_mission_id_str):
def parse_dead_object(event):
try:
append_dead_object(event["initiatorMissionID"])
except KeyError:
try:
append_dead_object([x['initiatorMissionID'] for x in event.values() if 'initiatorMissionID' in x][0])
except Exception as e:
logging.error(e)
except Exception as e:
logging.error(e)

Expand All @@ -98,9 +103,20 @@ def parse_dead_object(event):
except Exception as e:
table = parse_mutliplayer_debriefing(table_string)

events = table.get("debriefing", {}).get("events", {})
try:
events = table["debriefing"].get("events", {})
except KeyError:
events = table.get('events', {})
for event in events.values():
event_type = event.get("type", None)
try:
event_type = event["type"]
except KeyError:
# this means we've encountered a different version of the parsed debrief. This means we must search
# for the key we want :|
try:
event_type = [x['type'] for x in event.values() if 'type' in x][0]
except Exception as e:
print("Failed to parse event - {} ({})".format(event, e))
if event_type in ["crash", "dead"]:
parse_dead_object(event)

Expand All @@ -125,7 +141,7 @@ def count_groups(groups: typing.List[UnitType]) -> typing.Dict[UnitType, int]:

player = mission.country(player_name)
enemy = mission.country(enemy_name)

player_units = count_groups(player.plane_group + player.vehicle_group + player.ship_group)
enemy_units = count_groups(enemy.plane_group + enemy.vehicle_group + enemy.ship_group)

Expand Down

0 comments on commit 6731461

Please sign in to comment.