Color3
This commit is contained in:
parent
fb38f1076d
commit
c06ba65662
50
src/runner/color3.rs
Normal file
50
src/runner/color3.rs
Normal file
@ -0,0 +1,50 @@
|
||||
#[derive(Clone,Copy)]
|
||||
pub struct Color3{
|
||||
r:f32,
|
||||
g:f32,
|
||||
b:f32,
|
||||
}
|
||||
impl Color3{
|
||||
pub const fn new(r:f32,g:f32,b:f32)->Self{
|
||||
Self{r,g,b}
|
||||
}
|
||||
}
|
||||
impl Into<rbx_types::Color3> for Color3{
|
||||
fn into(self)->rbx_types::Color3{
|
||||
rbx_types::Color3::new(self.r,self.g,self.b)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table<'_>)->Result<(),mlua::Error>{
|
||||
let color3_table=lua.create_table()?;
|
||||
|
||||
color3_table.raw_set("new",
|
||||
lua.create_function(|ctx,(r,g,b):(f32,f32,f32)|
|
||||
Ok(ctx.create_userdata(Color3::new(r,g,b)))
|
||||
)?
|
||||
)?;
|
||||
color3_table.raw_set("fromRGB",
|
||||
lua.create_function(|ctx,(r,g,b):(u8,u8,u8)|
|
||||
Ok(ctx.create_userdata(Color3::new(r as f32/255.0,g as f32/255.0,b as f32/255.0)))
|
||||
)?
|
||||
)?;
|
||||
|
||||
globals.set("Color3",color3_table)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl mlua::UserData for Color3{
|
||||
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(fields:&mut F){
|
||||
}
|
||||
fn add_methods<'lua,M:mlua::UserDataMethods<'lua,Self>>(methods:&mut M){
|
||||
}
|
||||
}
|
||||
impl<'lua> mlua::FromLua<'lua> for Color3{
|
||||
fn from_lua(value:mlua::prelude::LuaValue<'lua>,_lua:&'lua mlua::prelude::Lua)->mlua::prelude::LuaResult<Self>{
|
||||
match value{
|
||||
mlua::Value::UserData(ud)=>ud.take()?,
|
||||
other=>Err(mlua::Error::runtime(format!("Expected Color3 got {:?}",other))),
|
||||
}
|
||||
}
|
||||
}
|
@ -160,6 +160,10 @@ impl Instance{
|
||||
let typed_value:f32=coerce_float32(&value).ok_or(mlua::Error::runtime("Expected f32"))?;
|
||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Float32(typed_value));
|
||||
},
|
||||
rbx_types::Variant::Color3(_)=>{
|
||||
let typed_value:super::color3::Color3=value.as_userdata().ok_or(mlua::Error::runtime("Expected Userdata"))?.take()?;
|
||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Color3(typed_value.into()));
|
||||
},
|
||||
other=>return Err(mlua::Error::runtime(format!("Unimplemented property type: {other:?}"))),
|
||||
}
|
||||
Ok(())
|
||||
|
@ -1,5 +1,6 @@
|
||||
mod runner;
|
||||
|
||||
mod color3;
|
||||
mod cframe;
|
||||
mod vector3;
|
||||
pub mod instance;
|
||||
|
@ -29,6 +29,7 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{
|
||||
//global environment
|
||||
let globals=lua.globals();
|
||||
|
||||
super::color3::set_globals(lua,&globals)?;
|
||||
super::vector3::set_globals(lua,&globals)?;
|
||||
super::cframe::set_globals(lua,&globals)?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user