SMB3-Foundry
SMB3-Foundry copied to clipboard
Refactor LevelObject Into Multiple Classes
Is your feature request related to a problem? Please describe.
At the current state LevelObject located in game/gfx/objects is very hard to understand, let alone change. The class itself takes over 900 lines of code and is required to edit for any future generators.
Describe the solution you'd like
I believe we need refactor LevelObject into multiple smaller classes. We will need an adapter to act like ObjectLike instead of forcing the entire class to act like it. This is for many reasons: it is hard to test, it makes LevelObject brittle, and it forces LevelObject to take on too much responsibility.
Once LevelObject is not bound to ObjectLike, we can begin to use many tactics to divide this class into different jobs. My proposal is we make LevelObject only responsible for the in game memory representation of the generator. We decorate LevelObject with a LevelObjectRenderer to implement the draw, render and as_image methods. Finally, LevelObjectRenderer will utilize the adapter in order to act like ObjectLike.
Methods I deem not critical for LevelObject that should be reimplemented elsewhere:
draw_draw_blockset_positionmove_byget_positionexpandsprimary_expansionresize_xresize_yresize_byincrement_typedecrement_typechange_typepoint_inget_status_infodisplay_sizeas_imagerender_render
Personally, I don't believe all these methods should be removed, but instead refactored into a property that can be set similarly. The main properties that come to mind are position and size and possibly primary_expansion.
Describe alternatives you've considered
There are alternatives to the solution provided, but ultimately any good solution will require an adapter for ObjectLike as it has so much responsibility. Where to put specific methods is can be debated.