Skip to content

Commit 2b35c07

Browse files
committed
Fixes #160 with non back compatible changes.
Renames all ability events as following: * AbilityEvent -> CommandEvent * AbilityEvent -> BasicCommandEvent * TargetAbilityEvent -> TargetUnitCommandEvent * LocationAbilityEvent -> TargetPointCommandEvent As such, all references to these classes, statements that check the event name, and engine plugin event handlers need to be renamed. Its not ideal but it is much better than being wrong.
1 parent caeb6ca commit 2b35c07

File tree

9 files changed

+61
-46
lines changed

9 files changed

+61
-46
lines changed

sc2reader/data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self, unit_id):
6262
self.killed_by = None
6363

6464
#: The unique in-game id for this unit. The id can sometimes be zero because
65-
#: TargetAbilityEvents will create a new unit with id zero when a unit
65+
#: TargetUnitCommandEvents will create a new unit with id zero when a unit
6666
#: behind the fog of war is targetted.
6767
self.id = unit_id
6868

sc2reader/engine/engine.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ class GameEngine(object):
1818
Example Usage::
1919
2020
class Plugin1():
21-
def handleAbilityEvent(self, event, replay):
21+
def handleCommandEvent(self, event, replay):
2222
pass
2323
2424
class Plugin2():
2525
def handleEvent(self, event, replay):
2626
pass
2727
28-
def handleTargetAbilityEvent(self, event, replay):
28+
def handleTargetUnitCommandEvent(self, event, replay):
2929
pass
3030
3131
...
@@ -35,11 +35,11 @@ def handleTargetAbilityEvent(self, event, replay):
3535
engine.reigster_plugin(Plugin(5))
3636
engine.run(replay)
3737
38-
Calls functions in the following order for a ``TargetAbilityEvent``::
38+
Calls functions in the following order for a ``TargetUnitCommandEvent``::
3939
40-
Plugin1.handleAbilityEvent(event, replay)
40+
Plugin1.handleCommandEvent(event, replay)
4141
Plugin2.handleEvent(event, replay)
42-
Plugin2.handleTargetAbilityEvent(event, replay)
42+
Plugin2.handleTargetUnitCommandEvent(event, replay)
4343
4444
4545
Plugin Specification
@@ -57,7 +57,7 @@ def handleEventName(self, event, replay)
5757
* handleMessageEvent - called for events in replay.message.events
5858
* handleGameEvent - called for events in replay.game.events
5959
* handleTrackerEvent - called for events in replay.tracker.events
60-
* handleAbilityEvent - called for all types of ability events
60+
* handleCommandEvent - called for all types of command events
6161
* handleControlGroupEvent - called for all player control group events
6262
6363
Plugins may also handle optional ``InitGame`` and ``EndGame`` events generated
@@ -90,7 +90,7 @@ def handleEvent(self, event, replay):
9090
return
9191
...
9292
93-
def handleAbilityEvent(self, event, replay):
93+
def handleCommandEvent(self, event, replay):
9494
try:
9595
possibly_throwing_error()
9696
catch Error as e:
@@ -204,8 +204,8 @@ def _get_plugin_event_handlers(self, plugin, event):
204204
handlers.append(getattr(plugin, 'handleGameEvent', None))
205205
if isinstance(event, TrackerEvent) and hasattr(plugin, 'handleTrackerEvent'):
206206
handlers.append(getattr(plugin, 'handleTrackerEvent', None))
207-
if isinstance(event, AbilityEvent) and hasattr(plugin, 'handleAbilityEvent'):
208-
handlers.append(getattr(plugin, 'handleAbilityEvent', None))
207+
if isinstance(event, CommandEvent) and hasattr(plugin, 'handleCommandEvent'):
208+
handlers.append(getattr(plugin, 'handleCommandEvent', None))
209209
if isinstance(event, ControlGroupEvent) and hasattr(plugin, 'handleControlGroupEvent'):
210210
handlers.append(getattr(plugin, 'handleControlGroupEvent', None))
211211
if hasattr(plugin, 'handle'+event.name):

sc2reader/engine/plugins/apm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class APMTracker(object):
88
"""
99
Builds ``player.aps`` and ``player.apm`` dictionaries where an action is
10-
any Selection, ControlGroup, or Ability event.
10+
any Selection, ControlGroup, or Command event.
1111
1212
Also provides ``player.avg_apm`` which is defined as the sum of all the
1313
above actions divided by the number of seconds played by the player (not
@@ -31,7 +31,7 @@ def handleSelectionEvent(self, event, replay):
3131
event.player.aps[event.second] += 1
3232
event.player.apm[int(event.second/60)] += 1
3333

34-
def handleAbilityEvent(self, event, replay):
34+
def handleCommandEvent(self, event, replay):
3535
event.player.aps[event.second] += 1
3636
event.player.apm[int(event.second/60)] += 1
3737

sc2reader/engine/plugins/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def handleGameEvent(self, event, replay):
2020
def handleMessageEvent(self, event, replay):
2121
self.load_message_game_player(event, replay)
2222

23-
def handleAbilityEvent(self, event, replay):
23+
def handleCommandEvent(self, event, replay):
2424
if not replay.datapack:
2525
return
2626

@@ -43,7 +43,7 @@ def handleAbilityEvent(self, event, replay):
4343
elif event.other_unit_id is not None:
4444
self.logger.error("Other unit {0} not found".format(event.other_unit_id))
4545

46-
def handleTargetAbilityEvent(self, event, replay):
46+
def handleTargetUnitCommandEvent(self, event, replay):
4747
if not replay.datapack:
4848
return
4949

sc2reader/events/game.py

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,31 @@ def __init__(self, frame, pid, data):
105105
def create_command_event(frame, pid, data):
106106
ability_type = data['data'][0]
107107
if ability_type == 'None':
108-
return AbilityEvent(frame, pid, data)
108+
return BasicCommandEvent(frame, pid, data)
109109

110110
elif ability_type == 'TargetUnit':
111-
return TargetAbilityEvent(frame, pid, data)
111+
return TargetUnitCommandEvent(frame, pid, data)
112112

113113
elif ability_type == 'TargetPoint':
114-
return LocationAbilityEvent(frame, pid, data)
114+
return TargetPointCommandEvent(frame, pid, data)
115115

116116
elif ability_type == 'Data':
117-
return SelfAbilityEvent(frame, pid, data)
117+
return DataCommandEvent(frame, pid, data)
118118

119119

120120
@loggable
121-
class AbilityEvent(GameEvent):
121+
class CommandEvent(GameEvent):
122122
"""
123123
Ability events are generated when ever a player in the game issues a command
124124
to a unit or group of units. They are split into three subclasses of ability,
125125
each with their own set of associated data. The attributes listed below are
126126
shared across all ability event types.
127127
128-
See :class:`LocationAbilityEvent`, :class:`TargetAbilityEvent`, and :class:`SelfAbilityEvent`
129-
for individual details.
128+
See :class:`TargetPointCommandEvent`, :class:`TargetUnitCommandEvent`, and
129+
:class:`DataCommandEvent` for individual details.
130130
"""
131131
def __init__(self, frame, pid, data):
132-
super(AbilityEvent, self).__init__(frame, pid)
132+
super(CommandEvent, self).__init__(frame, pid)
133133

134134
#: Flags on the command???
135135
self.flags = data['flags']
@@ -235,25 +235,38 @@ def __str__(self):
235235
return string
236236

237237

238-
class LocationAbilityEvent(AbilityEvent):
238+
class BasicCommandEvent(CommandEvent):
239239
"""
240-
Extends :class:`AbilityEvent`
240+
Extends :class:`CommandEvent`
241+
242+
This event is recorded for events that have no extra information recorded.
243+
244+
Note that like all CommandEvents, the event will be recorded regardless
245+
of whether or not the command was successful.
246+
"""
247+
def __init__(self, frame, pid, data):
248+
super(TargetPointCommandEvent, self).__init__(frame, pid, data)
249+
250+
251+
class TargetPointCommandEvent(CommandEvent):
252+
"""
253+
Extends :class:`CommandEvent`
241254
242255
This event is recorded when ever a player issues a command that targets a location
243256
and NOT a unit. Commands like Psistorm, Attack Move, Fungal Growth, and EMP fall
244257
under this category.
245258
246-
Note that like all AbilityEvents, the event will be recorded regardless
259+
Note that like all CommandEvents, the event will be recorded regardless
247260
of whether or not the command was successful.
248261
"""
249262
def __init__(self, frame, pid, data):
250-
super(LocationAbilityEvent, self).__init__(frame, pid, data)
263+
super(TargetPointCommandEvent, self).__init__(frame, pid, data)
251264

252265
#: The x coordinate of the target. Available for TargetPoint and TargetUnit type events.
253-
self.x = self.ability_type_data['point'].get('x', 0)/4096.0
266+
self.x = self.ability_type_data['point'].get('x', 0) / 4096.0
254267

255268
#: The y coordinate of the target. Available for TargetPoint and TargetUnit type events.
256-
self.y = self.ability_type_data['point'].get('y', 0)/4096.0
269+
self.y = self.ability_type_data['point'].get('y', 0) / 4096.0
257270

258271
#: The z coordinate of the target. Available for TargetPoint and TargetUnit type events.
259272
self.z = self.ability_type_data['point'].get('z', 0)
@@ -262,18 +275,19 @@ def __init__(self, frame, pid, data):
262275
self.location = (self.x, self.y, self.z)
263276

264277

265-
class TargetAbilityEvent(AbilityEvent):
278+
class TargetUnitCommandEvent(CommandEvent):
266279
"""
267-
Extends :class:`AbilityEvent`
280+
Extends :class:`CommandEvent`
268281
269-
TargetAbilityEvents are recorded when ever a player issues a command that targets a unit.
282+
This event is recorded when ever a player issues a command that targets a unit.
270283
The location of the target unit at the time of the command is also recorded. Commands like
271284
Chronoboost, Transfuse, and Snipe fall under this category.
272285
273-
Note that all AbilityEvents are recorded regardless of whether or not the command was successful.
286+
Note that like all CommandEvents, the event will be recorded regardless
287+
of whether or not the command was successful.
274288
"""
275289
def __init__(self, frame, pid, data):
276-
super(TargetAbilityEvent, self).__init__(frame, pid, data)
290+
super(TargetUnitCommandEvent, self).__init__(frame, pid, data)
277291

278292
#: Flags set on the target unit. Available for TargetUnit type events
279293
self.target_flags = self.ability_type_data.get('flags', None)
@@ -301,10 +315,10 @@ def __init__(self, frame, pid, data):
301315
self.upkeep_player_id = self.ability_type_data.get('upkeep_player_id', None)
302316

303317
#: The x coordinate of the target. Available for TargetPoint and TargetUnit type events.
304-
self.x = self.ability_type_data['point'].get('x', 0)/4096.0
318+
self.x = self.ability_type_data['point'].get('x', 0) / 4096.0
305319

306320
#: The y coordinate of the target. Available for TargetPoint and TargetUnit type events.
307-
self.y = self.ability_type_data['point'].get('y', 0)/4096.0
321+
self.y = self.ability_type_data['point'].get('y', 0) / 4096.0
308322

309323
#: The z coordinate of the target. Available for TargetPoint and TargetUnit type events.
310324
self.z = self.ability_type_data['point'].get('z', 0)
@@ -313,17 +327,18 @@ def __init__(self, frame, pid, data):
313327
self.location = (self.x, self.y, self.z)
314328

315329

316-
class SelfAbilityEvent(AbilityEvent):
330+
class DataCommandEvent(CommandEvent):
317331
"""
318-
Extends :class:`AbilityEvent`
332+
Extends :class:`CommandEvent`
319333
320-
SelfAbilityEvents are recorded when ever a player issues a command that has no target. Commands
334+
DataCommandEvent are recorded when ever a player issues a command that has no target. Commands
321335
like Burrow, SeigeMode, Train XYZ, and Stop fall under this category.
322336
323-
Note that all AbilityEvents are recorded regardless of whether or not the command was successful.
337+
Note that like all CommandEvents, the event will be recorded regardless
338+
of whether or not the command was successful.
324339
"""
325340
def __init__(self, frame, pid, data):
326-
super(SelfAbilityEvent, self).__init__(frame, pid, data)
341+
super(DataCommandEvent, self).__init__(frame, pid, data)
327342

328343
#: Other target data. Available for Data type events.
329344
self.target_data = self.ability_type_data.get('data', None)

sc2reader/events/tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class UnitBornEvent(TrackerEvent):
222222
223223
Unfortunately, units that are born do not have events marking their beginnings like
224224
:class:`UnitInitEvent` and :class:`UnitDoneEvent` do. The closest thing to it are the
225-
:class:`~sc2reader.event.game.AbilityEvent` game events where the ability is a train unit
225+
:class:`~sc2reader.event.game.CommandEvent` game events where the command is a train unit
226226
command.
227227
"""
228228
def __init__(self, frames, data, build):

sc2reader/factories/plugins/replay.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def toDict(replay):
9494
def APMTracker(replay):
9595
"""
9696
Builds ``player.aps`` and ``player.apm`` dictionaries where an action is
97-
any Selection, Hotkey, or Ability event.
97+
any Selection, Hotkey, or Command event.
9898
9999
Also provides ``player.avg_apm`` which is defined as the sum of all the
100100
above actions divided by the number of seconds played by the player (not
@@ -106,7 +106,7 @@ def APMTracker(replay):
106106
player.seconds_played = replay.length.seconds
107107

108108
for event in player.events:
109-
if event.name == 'SelectionEvent' or 'AbilityEvent' in event.name or 'ControlGroup' in event.name:
109+
if event.name == 'SelectionEvent' or 'CommandEvent' in event.name or 'ControlGroup' in event.name:
110110
player.aps[event.second] += 1
111111
player.apm[int(event.second/60)] += 1
112112

sc2reader/scripts/sc2parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main():
4848
human.pids = set([human.pid for human in replay.humans])
4949
event_pids = set([event.player.pid for event in replay.events if getattr(event, 'player', None)])
5050
player_pids = set([player.pid for player in replay.players if player.is_human])
51-
ability_pids = set([event.player.pid for event in replay.events if 'AbilityEvent' in event.name])
51+
ability_pids = set([event.player.pid for event in replay.events if 'CommandEvent' in event.name])
5252
if human.pids != event_pids:
5353
print('Event Pid problem! pids={pids} but event pids={event_pids}'.format(pids=human.pids, event_pids=event_pids))
5454
print(' with {path}: {build} - {real_type} on {map_name} - Played {start_time}'.format(path=path, **replay.__dict__))

sc2reader/scripts/sc2replayer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def getch():
4545
def main():
4646
parser = argparse.ArgumentParser(
4747
description="""Step by step replay of game events; shows only the
48-
Initialization, Ability, and Selection events by default. Press any
48+
Initialization, Command, and Selection events by default. Press any
4949
key to advance through the events in sequential order."""
5050
)
5151

@@ -77,7 +77,7 @@ def main():
7777
# Loop through the events
7878
for event in events:
7979

80-
if isinstance(event, AbilityEvent) or \
80+
if isinstance(event, CommandEvent) or \
8181
isinstance(event, SelectionEvent) or \
8282
isinstance(event, PlayerLeaveEvent) or \
8383
isinstance(event, GameStartEvent) or \

0 commit comments

Comments
 (0)