Distinguish between exported and non-exported properties by lilizoey · Pull Request #309 · godot-rust/gdext (original) (raw)

Built on top of #311

Split #[export] into #[var] and #[export]

var is now for creating properties, and export for exporting to the editor. export implies var, meaning that the following two field declarations are equivalent:

#[var] #[export] field: SomeType

// and

#[export] field: SomeType

FieldVar and FieldExport are now the types used to store the information about the var and export attributes.

Add support for the various export annotation

things like @export_range and such

Add a list parser to godot-macros

ListParser is used to parse values from the KvParser into ordered lists of items.

We could've reused KvParser, but that would require for instance @export_range(0.0, 10.0, or_greater) to look something like:
#[export(range = (min = 0.0, max = 10.0, or_greater))]

Which to me doesn't seem ideal. I dont think we want people to look up the attribute names of the fields of an export annotation to figure out how to rewrite it in rust. With the list parser the above can instead just become:

#[export(range = (0.0, 10.0, or_greater))]

Split up Export trait into Property and Export

Property has a setter and getter function for generating setters/getters. In addition to an associated type for the intermediate value used to pass objects to and from godot.

Export is now only for default export info, and functioning as a marker trait for exportable types.

Add in functions to create ExportInfo structs based on each export annotation

Used as a typed api to ensure that the user passes in the right values and can in the future be used by the builder api too to ensure compatibility between the two APIs.

These are all placed in godot-core::property::export_info_functions.

Add ExportableObject for exportable GodotClass objects.

An object can be exported if it inherits from either Node or Resource. Unfortunately this means there is no really nice way to create a bound for that using the existing traits. So i made ExportableObject, which is automatically implemented by all objects inheriting from one of those two classes.

fixes #227