Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event.player is None #91

Open
rcortini opened this issue Jul 28, 2019 · 6 comments
Open

Event.player is None #91

rcortini opened this issue Jul 28, 2019 · 6 comments
Labels

Comments

@rcortini
Copy link

When using the APMTracker plugin, it became clear to me that the events that the plugin parses the attribute player is None.

Code to reproduce:

class TestPlugin(object):

    name = 'TestPlugin'
            
    def handleCommandEvent(self, event, replay):
        print(event.player)
                
replay_file = '/home/rcortini/soft/sc2reader/test_replays/4.7.0.70154/1.SC2Replay'
replay = sc2reader.load_replay(
    replay_file,
    engine=sc2reader.engine.GameEngine(plugins=[TestPlugin()]))

which outputs a bunch of Nones.

By the way, this also means that the APMTracker plugin does not work, and that it is very difficult to write functional plugins.

@cclauss
Copy link
Collaborator

cclauss commented Jul 28, 2019

Yes. This issue was closed without a proper fix in #62.

@StoicLoofah
Copy link
Collaborator

Is it all events in this replay that have the player set to none, or is it only specific events that are missing the player? If it's the latter, can we figure out what the reason is?

I think this is worth solving, but I don't have much context or any intuition for why it could be happening

@rcortini
Copy link
Author

Hi and thanks for the comment.

It is, as far as I can see, for all events and for all the players. Digging in the code I figured out that the constructor of the Event class assigns None to the attribute .player, but never actually assigns it to anything else. I reckon the constructor of Event would be the place to assign it, after checking whether the is_local flag is set to true.

@rcortini
Copy link
Author

Okay, I figured out that this only happens when using

replay = sc2reader.load_replay(
    replay_file,
    engine=sc2reader.engine.GameEngine(plugins=[TestPlugin()]))

but it does not happen if you use

sc2reader.engine.register_plugin(TestPlugin())
replay = sc2reader.load_replay(replay_file)

@StoicLoofah
Copy link
Collaborator

Oh, that is fascinating. I have to admit that despite being the current maintainer for this library, I am completely unfamiliar with this code =P

Since you have a reasonable workaround, I feel better on the urgency of this. Maybe I'll take a stab at this sometime, but others are welcome to investigate and share what you find. The relevant logic is presumably in https://github.com/ggtracker/sc2reader/blob/71d0903a60616798373565fcf658b722eba3475f/sc2reader/factories/sc2factory.py

@NumberPigeon
Copy link
Contributor

Okay, I figured out that this only happens when using

replay = sc2reader.load_replay(
    replay_file,
    engine=sc2reader.engine.GameEngine(plugins=[TestPlugin()]))

but it does not happen if you use

sc2reader.engine.register_plugin(TestPlugin())
replay = sc2reader.load_replay(replay_file)

The problem here is ContextLoader() plugin. When using default engine, the sc2reader.engine has 2 plugins registered: GameHeartNormalizer() and ContextLoader(), and the 'ContextLoader()' does many things including assign some Events' event.player according to event.pid. If you want to use your own engine, you should do something like this:

my_engine=sc2reader.engine.GameEngine(plugins=[ContextLoader(), TestPlugin()])
replay = sc2reader.load_replay(replay_file, engine=my_engine)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants