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

Allow Nodes, Resources, and TypedArrays to be exported #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

chocola-mint
Copy link
Contributor

This PR completes REG_PROPERTY's missing functionalities by allowing Nodes, Resources, and TypedArrays to be exported. #16 and #17 are addressed as well.


To accomodate for REG_PROPERTY's new features, its meta properties have been refactored.

  • REG_P_HintType and REG_P_HintString replace REG_P_Info, improving readability.
  • REG_P_UsageFlags lets developers specify PropertyUsageFlags, a constexpr made up of bitflags OR'd together. This is passed into PropertyInfo verbatim.
  • REG_P_ExportAsNode and REG_P_ExportAsResource tell RegAutomation to treat the property as a Node or a Resource type. It is theoretically possible to parse godot-cpp headers to figure out which types inherit from Node and which inherit from Resource, but this will lead to a huge amount of overhead and add a lot of code complexity, which is why this solution is picked.

A new class called PropertyBinder is extracted from Pattern_Property to handle binding logic. No tests are written for it yet, but example.h has been updated to feature demonstrations of the new features.

Test_PropertyParser on the other hand has been updated to make sure it can properly extract information from the REG_PROPERTY macro.

A notable difference between PropertyBinder and the previous Pattern_Property is that the mapping from C++ classes to Godot Variant enums is now a handwritten Dictionary. This is more maintainable than relying on naming patterns, and allows us to add in additional aliases as needed.

Lastly, the current implementation has just one limitation: It can't handle multidimensional arrays yet. The reasons are as follows:

  • Multidimensional TypedArray<T> is just not supported by Godot at the moment. It won't compile.
  • That leaves us with an Array on the C++ end, relying on PropertyHint and the right hint string to make the array appear as a typed multidimensional array to GDScript. However, the hint string in this situation would need to insert raw values of Variant enums, which is not possible with a mere C++ string literal.
    • Now obviously, having to lose type safety on the C++ end is enough reasons to discourage users from even trying this approach if it were hypothetically doable, nonetheless it's still a limitation.

The README has been updated with REG_PROPERTY's new features and the above limitation, along with a suggested workaround.

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.

1 participant