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

Expose property info 'usage' in C# Export Attribute #2957

Open
cgbeutler opened this issue Jul 7, 2021 · 4 comments
Open

Expose property info 'usage' in C# Export Attribute #2957

cgbeutler opened this issue Jul 7, 2021 · 4 comments
Milestone

Comments

@cgbeutler
Copy link

Describe the project you are working on

A platformer with some custom Resources.

Describe the problem or limitation you are having in your project

I have several fields I would like to export without the storage usage flag. The Export attribute has hint and hintString exposed, but not usage.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

It would be nice to have usage as a field, even if it isn't in the constructor. If it were there, I could extend the attribute to make attributes like a [ExportNoStorage] or [EditorOnly] or something. The property list aggregation glue could then use the usage field to build the PropertyInfo dictionaries.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

As stated above, it doen't necessarily need to be added to the constructor. A bare minimum version would be:

    public class ExportAttribute : Attribute
    {
        private PropertyHint hint;
        private string hintString;
        private PropertyUsageFlags usage = PropertyUsageFlags.Default;  // < Add this!
        ...
    }

As for where this field would be parsed out, looks like the code in question can be found here:
https://github.com/godotengine/godot/blob/4fcc5891450a7dca9c8ebae6ff3765f5f060c442/modules/mono/csharp_script.cpp#L2734-L2769
and would involve grabbing the attributes value, ensuring the usual bits like PROPERTY_USAGE_SCRIPT_VARIABLE, then setting it on line 2768.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Yes. A workaround is to override the _GetPropertyList function and export stuff the long way.

Is there a reason why this should be core and not an add-on in the asset library?

It would involve changing the csharp_script.cpp core file.

@neikeq
Copy link

neikeq commented Mar 1, 2022

I'll add this as separate attributes. Like [HideInEditor]/[HideInInspector], [NoStorage], [Range(0, 10)], etc.

@neikeq neikeq added this to the 4.0 milestone Mar 1, 2022
@cgbeutler
Copy link
Author

cgbeutler commented Mar 1, 2022

@neikeq That works. I think those mirror the proposed GDScript attributes, which would be good.

See #2539 (comment)

@cgbeutler
Copy link
Author

I'll add this as separate attributes. Like [HideInEditor]/[HideInInspector], [NoStorage], [Range(0, 10)], etc.

Just curious, does adding RangeAttribute mean that ExportAttribute is loosing its hint and hint_string fields?
If not, it may make sense to still add usage to ExportAttribute so it mirrors the dictionaries used by _GetPropertyList.

If hint and hint_string are being removed, will there be a HintAttribute or something for custom editors to use?
If HintAttribute is a thing, it would make sense if RangeAttribute and the like inherit from HintAttribute. In a similar vein NoStorage could inherit from UsageAttribute or something.

Sorry, that was a lot. Just trying to figure out the cleanest way to proceed with my project and still embrace those changes when they come.

@GeorgeS2019
Copy link

This PR: Add C# resource export could be relevant

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

No branches or pull requests

5 participants