Skip to content

Combine MiscTablesModule and ExpandedTablesModule - #326

Open
Supremekirb wants to merge 4 commits into
pk-hack:masterfrom
Supremekirb:misc-expanded-tables-merge-but-fixed
Open

Supremekirb wants to merge 4 commits into
pk-hack:masterfrom
Supremekirb:misc-expanded-tables-merge-but-fixed

Conversation

@Supremekirb

Copy link
Copy Markdown

This PR combines MiscTablesModule and ExpandedTablesModule by implementing the expansion features of the latter into the former. ExpandedTablesModule no longer exists; the new combination retains the MiscTablesModule name.

Under the hood, things are similar to ExpandedTablesModule, but if no list of pointers to patch is provided, then the table will be considered unexpandable, and regular MiscTablesModule behavior will apply.

Additionally, the FREE_RANGES attribute becomes a property that is calculated at runtime. This means that it is no longer necessary to manually calculate and hardcode the space freed up by expanding a table.

This PR doesn't add expansion capabilities to any new tables. That can come later.

@PhoenixBound PhoenixBound left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to discuss ideas about the best way to handle "moving" files from one module to another, in the project upgrade process, and pruning out data for redundant modules from the Project.snake. In the meantime, here's what I'd suggest so far.

Thanks again for your work on this.

Comment thread coilsnake/modules/eb/MiscTablesModule.py Outdated
Comment on lines +13 to +20
# this decorator is used to calculate the free ranges instead of hardcoding them.
# in 3.9 - 3.11, it's possible to combine @property and @classmethod, so we COULD just do that...
# however, for the sake for maintainability, a >3.11-style solution is here.
class classproperty:
def __init__(self, func):
self.fget = func
def __get__(self, instance, owner):
return self.fget(owner)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm misunderstanding something, you should be able to combine @staticmethod and @property, instead of using @classmethod.

This is the only spot in CoilSnake where FREE_RANGES is read from:

for free_range in module_class.FREE_RANGES:
and it's not called on an instance of the class

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been almost a year so I don't recall the details, but I remember this was giving me a headache. That means I probably landed on this for a reason, so a change would need to be tested

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I didn't take into account going into this review was that TABLE_OFFSETS here is a member of the MiscTablesModule class, meaning it might not be as easy to refer to without a self or type(self) or whatever. (You could make TABLE_OFFSETS be a global variable to compensate, but then that would require changing every instance of self.TABLE_OFFSETS in the rest of the code, and probably make Mother 2 support harder down the line.)

A lot of bikeshedding is possible here since the code will probably need to change again once Mother 2 support is added. For now, I went with a simpler solution that doesn't involve any property methods, suggested by Coop. (I just double checked, and the function that initializes FREE_RANGES is only called once, so that's not a concern at least.)

Comment thread coilsnake/modules/eb/MiscTablesModule.py Outdated
I initially suggested replacing @classmethod with @staticmethod, which
would have required additional changes, but Coop pointed out that a
simple solution like this was also possible.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants