Skip to content

Commit 6c3168e

Browse files
committed
Fix Ability.__str__ to report the ability name when available.
1 parent 0749ce9 commit 6c3168e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

sc2reader/events.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,28 @@ def load_context(self, replay):
126126
class AbilityEvent(PlayerActionEvent):
127127
def __init__(self, framestamp, player, type, code, ability):
128128
super(AbilityEvent, self).__init__(framestamp, player, type, code)
129-
self.ability = ability
129+
self.ability_code = ability
130130

131131
def load_context(self, replay):
132132
super(AbilityEvent, self).load_context(replay)
133133

134-
if self.ability not in replay.datapack.abilities:
134+
if self.ability_code not in replay.datapack.abilities:
135135
if not getattr(replay, 'marked_error', None):
136136
replay.marked_error=True
137137
self.logger.error(replay.filename)
138138
self.logger.error("Release String: "+replay.release_string)
139139
for player in replay.players:
140140
self.logger.error("\t"+str(player))
141-
self.logger.error("{0}\t{1}\tMissing ability {2} from {3}".format(self.frame, self.player.name, hex(self.ability), replay.datapack.__class__.__name__))
141+
self.logger.error("{0}\t{1}\tMissing ability {2} from {3}".format(self.frame, self.player.name, hex(self.ability_code), replay.datapack.__class__.__name__))
142+
self.ability = "UNKNOWN"
143+
else:
144+
self.ability = replay.datapack.abilities[self.ability_code]
142145

143146
def __str__(self):
144-
if not self.ability:
147+
if not self.ability_code:
145148
return self._str_prefix() + "Move"
146149
else:
147-
ability_name = self.data.ability(self.ability) if self.ability in self.data.abilities else "UNKNOWN"
148-
return self._str_prefix() + "Ability (%s) - %s" % (hex(self.ability), ability_name)
150+
return self._str_prefix() + "Ability (%s) - %s" % (hex(self.ability_code), self.ability)
149151

150152
@loggable
151153
class TargetAbilityEvent(AbilityEvent):

0 commit comments

Comments
 (0)