mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 21:10:36 +00:00
Handle OptionalCFrame in roblox conversion layer
This commit is contained in:
parent
e3bcf79f09
commit
1161b9f4e8
2 changed files with 30 additions and 14 deletions
|
@ -1,5 +1,3 @@
|
||||||
use std::any::type_name;
|
|
||||||
|
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
|
|
||||||
use rbx_dom_weak::types::{Variant as RbxVariant, VariantType as RbxVariantType};
|
use rbx_dom_weak::types::{Variant as RbxVariant, VariantType as RbxVariantType};
|
||||||
|
@ -121,7 +119,6 @@ impl<'lua> RbxVariantToLua<'lua> for LuaAnyUserData<'lua> {
|
||||||
// check `EnumItem::from_instance_property` for specifics
|
// check `EnumItem::from_instance_property` for specifics
|
||||||
Ok(match variant.clone() {
|
Ok(match variant.clone() {
|
||||||
// Not yet implemented datatypes
|
// Not yet implemented datatypes
|
||||||
// Rbx::OptionalCFrame(_) => todo!(),
|
|
||||||
// Rbx::PhysicalProperties(_) => todo!(),
|
// Rbx::PhysicalProperties(_) => todo!(),
|
||||||
// Rbx::Ray(_) => todo!(),
|
// Rbx::Ray(_) => todo!(),
|
||||||
// Rbx::Region3(_) => todo!(),
|
// Rbx::Region3(_) => todo!(),
|
||||||
|
@ -131,6 +128,10 @@ impl<'lua> RbxVariantToLua<'lua> for LuaAnyUserData<'lua> {
|
||||||
Rbx::Faces(value) => lua.create_userdata(Faces::from(value))?,
|
Rbx::Faces(value) => lua.create_userdata(Faces::from(value))?,
|
||||||
|
|
||||||
Rbx::CFrame(value) => lua.create_userdata(CFrame::from(value))?,
|
Rbx::CFrame(value) => lua.create_userdata(CFrame::from(value))?,
|
||||||
|
Rbx::OptionalCFrame(value) => match value {
|
||||||
|
Some(value) => lua.create_userdata(CFrame::from(value))?,
|
||||||
|
None => lua.create_userdata(CFrame::IDENTITY)?
|
||||||
|
},
|
||||||
|
|
||||||
Rbx::BrickColor(value) => lua.create_userdata(BrickColor::from(value))?,
|
Rbx::BrickColor(value) => lua.create_userdata(BrickColor::from(value))?,
|
||||||
Rbx::Color3(value) => lua.create_userdata(Color3::from(value))?,
|
Rbx::Color3(value) => lua.create_userdata(Color3::from(value))?,
|
||||||
|
@ -175,6 +176,10 @@ impl<'lua> LuaToRbxVariant<'lua> for LuaAnyUserData<'lua> {
|
||||||
RbxVariantType::Faces => convert::<Faces, rbx::Faces>,
|
RbxVariantType::Faces => convert::<Faces, rbx::Faces>,
|
||||||
|
|
||||||
RbxVariantType::CFrame => convert::<CFrame, rbx::CFrame>,
|
RbxVariantType::CFrame => convert::<CFrame, rbx::CFrame>,
|
||||||
|
RbxVariantType::OptionalCFrame => return match self.borrow::<CFrame>() {
|
||||||
|
Ok(value) => Ok(RbxVariant::OptionalCFrame(Some(rbx::CFrame::from(*value)))),
|
||||||
|
Err(e) => Err(lua_userdata_error_to_conversion_error(variant_type, e)),
|
||||||
|
},
|
||||||
|
|
||||||
RbxVariantType::BrickColor => convert::<BrickColor, rbx::BrickColor>,
|
RbxVariantType::BrickColor => convert::<BrickColor, rbx::BrickColor>,
|
||||||
RbxVariantType::Color3 => convert::<Color3, rbx::Color3>,
|
RbxVariantType::Color3 => convert::<Color3, rbx::Color3>,
|
||||||
|
@ -216,15 +221,24 @@ where
|
||||||
{
|
{
|
||||||
match userdata.borrow::<Datatype>() {
|
match userdata.borrow::<Datatype>() {
|
||||||
Ok(value) => Ok(RbxType::from(value.clone()).into()),
|
Ok(value) => Ok(RbxType::from(value.clone()).into()),
|
||||||
Err(LuaError::UserDataTypeMismatch) => Err(DatatypeConversionError::ToRbxVariant {
|
Err(e) => Err(lua_userdata_error_to_conversion_error(variant_type, e)),
|
||||||
to: variant_type.variant_name(),
|
}
|
||||||
from: type_name::<Datatype>(),
|
}
|
||||||
detail: Some("Type mismatch".to_string()),
|
|
||||||
}),
|
fn lua_userdata_error_to_conversion_error(
|
||||||
Err(e) => Err(DatatypeConversionError::ToRbxVariant {
|
variant_type: RbxVariantType,
|
||||||
to: variant_type.variant_name(),
|
error: LuaError,
|
||||||
from: type_name::<Datatype>(),
|
) -> DatatypeConversionError {
|
||||||
detail: Some(format!("Internal error: {e}")),
|
match error {
|
||||||
}),
|
LuaError::UserDataTypeMismatch => DatatypeConversionError::ToRbxVariant {
|
||||||
|
to: variant_type.variant_name(),
|
||||||
|
from: "userdata",
|
||||||
|
detail: Some("Type mismatch".to_string()),
|
||||||
|
},
|
||||||
|
e => DatatypeConversionError::ToRbxVariant {
|
||||||
|
to: variant_type.variant_name(),
|
||||||
|
from: "userdata",
|
||||||
|
detail: Some(format!("Internal error: {e}")),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ use super::{super::*, Vector3};
|
||||||
pub struct CFrame(Mat4);
|
pub struct CFrame(Mat4);
|
||||||
|
|
||||||
impl CFrame {
|
impl CFrame {
|
||||||
|
pub const IDENTITY: Self = Self(Mat4::IDENTITY);
|
||||||
|
|
||||||
fn position(&self) -> Vec3 {
|
fn position(&self) -> Vec3 {
|
||||||
self.0.w_axis.truncate()
|
self.0.w_axis.truncate()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue