mut
This commit is contained in:
parent
6dfa46bc67
commit
e799f6a094
@ -429,18 +429,22 @@ impl ClassMethods<'_>{
|
||||
|
||||
/// A virtual property pointer definition shorthand.
|
||||
type VirtualPropertyFunctionPointer=fn(&rbx_types::Variant)->Option<rbx_types::Variant>;
|
||||
type VirtualPropertyFunctionPointerMut=fn(&mut rbx_types::Variant,rbx_types::Variant)->Option<()>;
|
||||
const fn vpp(
|
||||
property:&'static str,
|
||||
pointer:VirtualPropertyFunctionPointer,
|
||||
access:VirtualPropertyFunctionPointer,
|
||||
access_mut:VirtualPropertyFunctionPointerMut,
|
||||
)->VirtualProperty{
|
||||
VirtualProperty{
|
||||
property,
|
||||
pointer,
|
||||
access,
|
||||
access_mut,
|
||||
}
|
||||
}
|
||||
struct VirtualProperty{
|
||||
property:&'static str,// Source property name
|
||||
pointer:VirtualPropertyFunctionPointer,
|
||||
access:VirtualPropertyFunctionPointer,
|
||||
access_mut:VirtualPropertyFunctionPointerMut,
|
||||
}
|
||||
type VPD=phf::Map<&'static str,// Class name
|
||||
phf::Map<&'static str,// Virtual property name
|
||||
@ -449,13 +453,26 @@ type VPD=phf::Map<&'static str,// Class name
|
||||
>;
|
||||
static VIRTUAL_PROPERTY_DATABASE:VPD=phf::phf_map!{
|
||||
"BasePart"=>phf::phf_map!{
|
||||
"Position"=>vpp("CFrame",|c:&rbx_types::Variant|{
|
||||
let c=match c{
|
||||
rbx_types::Variant::CFrame(c)=>c,
|
||||
_=>return None,//fail silently and ungracefully
|
||||
};
|
||||
Some(rbx_types::Variant::Vector3(c.position))
|
||||
}),
|
||||
"Position"=>vpp(
|
||||
"CFrame",
|
||||
//Get
|
||||
|c|{
|
||||
let c=match c{
|
||||
rbx_types::Variant::CFrame(c)=>c,
|
||||
_=>return None,//fail silently and ungracefully
|
||||
};
|
||||
Some(rbx_types::Variant::Vector3(c.position))
|
||||
},
|
||||
//Set
|
||||
|c,p|{
|
||||
let (c,p)=match (c,p){
|
||||
(rbx_types::Variant::CFrame(c),rbx_types::Variant::Vector3(p))=>(c,p),
|
||||
_=>return None,//fail silently and ungracefully
|
||||
};
|
||||
c.position=p;
|
||||
Some(())
|
||||
}
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
@ -472,5 +489,5 @@ fn find_virtual_property(
|
||||
let variant=properties.get(virtual_property.property)?;
|
||||
|
||||
//Transform Source property with provided function
|
||||
(virtual_property.pointer)(variant)
|
||||
(virtual_property.access)(variant)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user