roblox_emulator: implement BrickColor
This commit is contained in:
parent
b34d3f89f9
commit
9aea73e134
lib/roblox_emulator/src/runner
33
lib/roblox_emulator/src/runner/brickcolor.rs
Normal file
33
lib/roblox_emulator/src/runner/brickcolor.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
use super::color3::Color3;
|
||||||
|
|
||||||
|
#[derive(Clone,Copy)]
|
||||||
|
pub struct BrickColor(rbx_types::BrickColor);
|
||||||
|
impl BrickColor{
|
||||||
|
pub fn from_name(name:&str)->Option<Self>{
|
||||||
|
Some(BrickColor(rbx_types::BrickColor::from_name(name)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||||
|
let brickcolor_table=lua.create_table()?;
|
||||||
|
|
||||||
|
brickcolor_table.raw_set("new",
|
||||||
|
lua.create_function(|_,name:mlua::String|
|
||||||
|
Ok(BrickColor::from_name(&*name.to_str()?))
|
||||||
|
)?
|
||||||
|
)?;
|
||||||
|
|
||||||
|
globals.set("BrickColor",brickcolor_table)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
impl mlua::UserData for BrickColor{
|
||||||
|
fn add_fields<F:mlua::UserDataFields<Self>>(fields:&mut F){
|
||||||
|
fields.add_field_method_get("Color",|_,BrickColor(this)|{
|
||||||
|
let rbx_types::Color3uint8{r,g,b}=this.to_color3uint8();
|
||||||
|
Ok(Color3::from_rgb(r,g,b))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type_from_lua_userdata!(BrickColor);
|
@ -8,6 +8,9 @@ impl Color3{
|
|||||||
pub const fn new(r:f32,g:f32,b:f32)->Self{
|
pub const fn new(r:f32,g:f32,b:f32)->Self{
|
||||||
Self{r,g,b}
|
Self{r,g,b}
|
||||||
}
|
}
|
||||||
|
pub const fn from_rgb(r:u8,g:u8,b:u8)->Self{
|
||||||
|
Color3::new(r as f32/255.0,g as f32/255.0,b as f32/255.0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl Into<rbx_types::Color3> for Color3{
|
impl Into<rbx_types::Color3> for Color3{
|
||||||
fn into(self)->rbx_types::Color3{
|
fn into(self)->rbx_types::Color3{
|
||||||
@ -25,7 +28,7 @@ pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
|||||||
)?;
|
)?;
|
||||||
color3_table.raw_set("fromRGB",
|
color3_table.raw_set("fromRGB",
|
||||||
lua.create_function(|_,(r,g,b):(u8,u8,u8)|
|
lua.create_function(|_,(r,g,b):(u8,u8,u8)|
|
||||||
Ok(Color3::new(r as f32/255.0,g as f32/255.0,b as f32/255.0))
|
Ok(Color3::from_rgb(r,g,b))
|
||||||
)?
|
)?
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ mod r#enum;
|
|||||||
mod color3;
|
mod color3;
|
||||||
mod cframe;
|
mod cframe;
|
||||||
mod vector3;
|
mod vector3;
|
||||||
|
mod brickcolor;
|
||||||
pub mod instance;
|
pub mod instance;
|
||||||
mod script_signal;
|
mod script_signal;
|
||||||
mod color_sequence;
|
mod color_sequence;
|
||||||
|
@ -36,6 +36,7 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{
|
|||||||
super::script_signal::set_globals(lua,&globals)?;
|
super::script_signal::set_globals(lua,&globals)?;
|
||||||
super::r#enum::set_globals(lua,&globals)?;
|
super::r#enum::set_globals(lua,&globals)?;
|
||||||
super::color3::set_globals(lua,&globals)?;
|
super::color3::set_globals(lua,&globals)?;
|
||||||
|
super::brickcolor::set_globals(lua,&globals)?;
|
||||||
super::vector3::set_globals(lua,&globals)?;
|
super::vector3::set_globals(lua,&globals)?;
|
||||||
super::cframe::set_globals(lua,&globals)?;
|
super::cframe::set_globals(lua,&globals)?;
|
||||||
super::instance::instance::set_globals(lua,&globals)?;
|
super::instance::instance::set_globals(lua,&globals)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user