Add easy way to add plugins (game wrappers) to Plugin Manager
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 539
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 5
Description
Hello! I've been attempted to add the WIP Pokemon Red Plugin to my local project, but I'm finding it's quite difficult due to the way the `PyBoy` and `PluginManager` classes are structured. Would you be willing to accept a PR that makes the design more modular, and allows the user to something like the following?
```python
game = pyboy.PyBoy(PATH, game_wrapper=True)
game.plugin_manager.add_plugin(PLUGIN)
```
Additionally, inside the plugin manager, there is a lot of `.enabled()` calls from plugins, but it appears as though that function will return the same result everytime. This can be seen by the fact that the `PluginManager` class has extra attributes to cache the result for all of them.
```py
# example:
self.window_sdl2 = WindowSDL2(pyboy, mb, pyboy_argv)
self.window_sdl2_enabled = self.window_sdl2.enabled()
self.window_open_gl = WindowOpenGL(pyboy, mb, pyboy_argv)
self.window_open_gl_enabled = self.window_open_gl.enabled()
```
I personally think this would be structured better if the `enabled` function in each plugin was changed into a `_enabled` helper function that is called in the initializer and set to an `enabled` attribute, so the attribute `.enabled` would be available and these extra `(plugin name)_enabled` attributes wouldn't be needed.
If there's conflicts with evaluating `enabled` state before hand, that's okay as that doesn't impact the user at the end of the day. What does though, is the ability to add custom plugins, so let me know what you think about these suggestions! :)
Contributor guide
Research direction
Start by reading the PyBoy and PluginManager classes and tracing how built-in plugins are initialized and how their enabled state is cached. Identify the existing plugin entry points and tests before deciding how custom add_plugin support should fit. Done means a user can add a game wrapper plugin through the proposed API and the plugin enabled state no longer needs duplicated manager attributes, with existing plugins still working.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- game-dev, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100