Skip to content

Commit f3b0191

Browse files
committed
Updates to the plugin documentation.
1 parent f2a7286 commit f3b0191

File tree

2 files changed

+46
-27
lines changed

2 files changed

+46
-27
lines changed

docs/source/articles/creatingagameengineplugin.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ Given the following plugins::
3333
def handleTargetAbilityEvent(self, event, replay):
3434
pass
3535

36-
An engine handling a ``TargetAbilityEvent`` would call handlers in the following order::
36+
sc2reader.engine.register_plugin(Plugin1())
37+
sc2reader.engine.register_plugin(Plugin2())
38+
39+
When the engine handles a ``TargetAbilityEvent`` it will call handlers in the following order::
3740

3841
Plugin1.handleAbilityEvent(event, replay)
3942
Plugin2.handleEvent(event, replay)
@@ -84,3 +87,12 @@ If a plugin wishes to stop processing a replay it can yield a PluginExit event b
8487
The GameEngine will intercept this event and remove the plugin from the list of active plugins for this replay. The exit code and details will be available from the replay::
8588

8689
code, details = replay.plugins['MyPlugin']
90+
91+
Using Your Plugin
92+
-----------------
93+
94+
To use your plugin with sc2reader, just register it to the game engine:
95+
96+
sc2reader.engine.register_plugin(MyPlugin())
97+
98+
Plugins will be called in order of registration for each event. If plugin B depends on plugin A make sure to register plugin A first!

docs/source/plugins.rst

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
Plugins
22
=============
33

4-
A plugin is pretty much just a callable function or object that accepts a replay
5-
file as a single argument. sc2reader supports assignment of plugins to different
6-
resource types via the :meth:`SC2Factory.register_plugin` factory method.
4+
sc2reader has a built in game engine that you can plug into to efficiently process replay events. You can add plugins to the engine by calling :meth:`~sc2reader.engine.engine.GameEngine.register_plugin`::
75

8-
::
6+
import sc2reader
7+
from sc2reader.engine.plugins import APMTracker, SelectionTracker
8+
sc2reader.engine.register_plugin(APMTracker())
9+
sc2reader.engine.register_plugin(SelectionTracker())
910

10-
import sc2reader
11-
from sc2reader.plugins.replay import APMTracker, SelectionTracker
12-
sc2reader.register_plugin('Replay',APMTracker())
13-
sc2reader.register_plugin('Replay',SelectionTracker())
11+
Plugins will be called in order of registration for each event. If plugin B depends on plugin A make sure to register plugin A first!
1412

15-
The order you register plugins is the order they are executed in so be careful to
16-
put register in the right order if you have dependencies between plugins.
13+
See the :doc:`articles/creatingagameengineplugin` article for instructions on making your own plugins.
14+
15+
16+
ContextLoader
17+
-------------
18+
19+
.. note::
20+
21+
This plugin is registered by default.
22+
23+
This plugin creates and maintains all the :class:`~sc2reader.data.Unit` and :class:`~sc2reader.data.Ability` data objects from the raw replay data. This creates all the ``event.player``, ``event.unit``, ``event.ability`` object references and maintains other game data structures like :attr:`~sc2reader.resources.Replay.objects`.
24+
25+
26+
GameHeartNormalizer
27+
---------------------
28+
29+
.. note::
30+
31+
This plugin is registered by default.
32+
33+
This plugin fixes player lists, teams, game lengths, and frames for games that were played with the GameHeart mod.
1734

1835

1936
APMTracker
2037
----------------
2138

22-
The APMTracker adds three simple fields based on a straight tally of non-camera
23-
player action events such as selections, abilities, and hotkeys.
39+
The :class:`~sc2reader.engine.plugins.APMTracker` adds three simple fields based on a straight tally of non-camera player action events such as selections, abilities, and hotkeys.
2440

2541
* ``player.aps`` = a dictionary of second => total actions in that second
2642
* ``player.apm`` = a dictionary of minute => total actions in that minute
@@ -30,21 +46,12 @@ player action events such as selections, abilities, and hotkeys.
3046
SelectionTracker
3147
--------------------
3248

33-
The :class:`SelectionTracker` plugin simulates every person's selection at every
34-
frame in both the hotkey and active selection buffers. This selection information
35-
is stored in ``person.selection`` as a two dimensional array of lists.
36-
37-
::
38-
39-
unit_list = replay.player[1].selection[frame][buffer]
49+
.. note::
4050

41-
Where buffer is a control group 0-9 or 10 which represents the active selection.
51+
This plugin is intended to be used in conjunction with other user written plugins. If you attempt to use the ``player.selection`` attribute outside of a registered plugin the values will be the values as they were at the end of the game.
4252

43-
Keep in mind that the buffers are only updated for the following events:
53+
The :class:`SelectionTracker` maintains a ``person.selection`` structure maps selection buffers for that player to the player's current selection::
4454

45-
* The active selection changes
46-
* When unit types change (eggs hatch, tanks siege)
55+
active_selection = event.player.selection[10]
4756

48-
Buffers are not updated when units die unless the unit dies while selected (because
49-
the active selection must change). Units that die while deslected won't get deselected
50-
until the next time the control group they were saved in becomes active.
57+
Where buffer is a control group 0-9 or a 10 which represents the active selection.

0 commit comments

Comments
 (0)