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

Structs with a retriever which depend on a parent value are difficult to define #6

Open
KSneijders opened this issue Jun 28, 2023 · 1 comment
Labels
Enhancement New feature or request

Comments

@KSneijders
Copy link
Contributor

KSneijders commented Jun 28, 2023

(We discussed this in DM too, so this continues on top of that) (URL to DM)

The only work-around that has been working is the following:

This code is inside the __init__(...): of the child struct:

def __init__(self, struct_ver: Version = Version((0,)), parent: BaseStruct = None, idx: int = -1, initialise_defaults: bool = True, **retriever_inits):
    if parent is not None:
        Retriever.set_repeat(TerrainTables.terrain_restrictions, self, parent.terrain_count)
        Retriever.set_repeat(TerrainTables.terrain_pass_graphics, self, parent.terrain_count)
    super().__init__(struct_ver, parent, idx, initialise_defaults, **retriever_inits)

This doesn't feel like a proper solution in my opinion.

Could a feature (callback) be added for initializing that executes between __init__(...) and reading the retrievers?
It'd still need access to instance and parent variables etc.

Thanks!

@Divy1211 Divy1211 added the Enhancement New feature or request label Nov 14, 2023
@Divy1211
Copy link
Owner

Making a void Retriever at the very beginning to set repeat using struct.parent.value is currently the cleanest way to do this, although I admit it might not be the best, will look into potential solutions.

example of a void Retriever: #5

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

No branches or pull requests

2 participants