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

Make it easier to access node settings within node definition #60

Closed
4 tasks done
S-S-X opened this issue Nov 19, 2020 · 2 comments · Fixed by #61
Closed
4 tasks done

Make it easier to access node settings within node definition #60

S-S-X opened this issue Nov 19, 2020 · 2 comments · Fixed by #61
Assignees
Labels
API Metatool API issues enhancement New feature or request

Comments

@S-S-X
Copy link
Owner

S-S-X commented Nov 19, 2020

Problem with getting configuration values easily

There is metatool.settings(toolname, key) function which is probably good enough for tool itself but there's nothing for node definition, instead one has to do something like metatool.tool("mytool").nodes.mynode.settings.setting_name to read node settings.
Currently another way could be using metatool.ns function but that is not so clean and not really meant for this kind of hacky access to self and introduces many other problems.

Possible solution, maybe

Better way would probably be something like self.settings.setting_name when accessed from node functions (copy, paste, info, before_write, before read, etc.).
This requires converting node definitions to allow easy and clean definitions with easy and clean access to node definition object.

Things to consider, list of tasks

  • Utilize and express OOP model better with node definitions, allow easy access to compiled node definition object.
    Edit: Seems that this is already done, just not utilized and not visible in any way. Just try to convert node definitions to format that more visibly express this possibility.
  • Drop intermediate tooldef key from node definition table. Just bring everything below it to top level.
    There's no need for another level and it just makes things complicated, also tooldef as name is very bad and misleading.
  • Allow dropping tool on_read_node/on_write_node out and call copy/paste from node definition directly.
    There might be some use for tool on_read_node and/or on_write_node callbacks so it might be good to allow these but most tools just copy/paste exact same stuff there.

Breaking changes for API, bump major version when releasing this

  • Create issue as reminder before closing this one
@S-S-X S-S-X added enhancement New feature or request API Metatool API issues labels Nov 19, 2020
@S-S-X
Copy link
Owner Author

S-S-X commented Nov 19, 2020

This would cover large part of cleanup mentioned in #42, not all of it but still a lot.

@S-S-X S-S-X self-assigned this Nov 19, 2020
S-S-X pushed a commit that referenced this issue Nov 19, 2020
@S-S-X
Copy link
Owner Author

S-S-X commented Nov 19, 2020

Should probably leave this here as note to myself if I have to do something like this again...

find . -type f -name '*.lua' -path '*/nodes/*' | xargs -L1 -i'{}' bash -c 'ed "{}" <<END
/^return {$/+1;/^}$/-1m/^local definition = {/
/^return {$/-;/^}$/d
wq
END
'

@S-S-X S-S-X mentioned this issue Nov 19, 2020
S-S-X pushed a commit that referenced this issue Nov 19, 2020
S-S-X pushed a commit that referenced this issue Nov 20, 2020
@S-S-X S-S-X closed this as completed in #61 Nov 21, 2020
S-S-X added a commit that referenced this issue Nov 21, 2020
* (#60) OOP model for node definitions

* formatting

* (#60) Drop tooldef key/subtable from definition table

* (#60) Covert before_* API methods to OOP model, cleaner formatting for other API methods

* (#60) Unified on_use flow, similar overrides for callbacks

* (#60) Fix before_write/read/info callbacks, allow short name for /metatool:give

* (#60) Update API documentation, style/formatting for tool:on_write_node call

* (#60) Extend regression tests

* checkout@v2, "mineunit" detached to mt-mods repo

* Update mineunit

* Remove metatool copy/paste/info wrapper methods

Co-authored-by: SX <sx@minetest>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Metatool API issues enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant