use proc_macro2::TokenStream;
use quote::quote;
use crate::ParseResult;
use crate::derive::data_models::GodotConvert;
pub fn derive_var(item: venial::Item) -> ParseResult<TokenStream> {
let convert = GodotConvert::parse_declaration(item)?;
let name = convert.ty_name;
Ok(quote! {
impl ::godot::register::property::Var for #name {
type PubType = Self;
fn var_get(field: &Self) -> <Self as ::godot::meta::GodotConvert>::Via {
::godot::meta::ToGodot::to_godot(field)
}
fn var_set(field: &mut Self, value: <Self as ::godot::meta::GodotConvert>::Via) {
*field = ::godot::meta::FromGodot::from_godot(value);
}
fn var_pub_get(field: &Self) -> Self::PubType {
field.clone()
}
fn var_pub_set(field: &mut Self, value: Self::PubType) {
*field = value;
}
}
})
}