2024-01-31 04:25:07 +00:00
|
|
|
use std::io::Read;
|
|
|
|
|
|
|
|
mod rbx;
|
2024-03-13 01:08:44 +00:00
|
|
|
mod mesh;
|
2024-01-31 01:41:16 +00:00
|
|
|
mod primitives;
|
2024-01-31 04:25:07 +00:00
|
|
|
|
2024-03-13 01:08:44 +00:00
|
|
|
pub mod data{
|
|
|
|
pub struct RobloxMeshBytes(Vec<u8>);
|
|
|
|
impl RobloxMeshBytes{
|
|
|
|
pub fn new(bytes:Vec<u8>)->Self{
|
|
|
|
Self(bytes)
|
|
|
|
}
|
2024-03-13 03:31:30 +00:00
|
|
|
pub(crate) fn cursor(self)->std::io::Cursor<Vec<u8>>{
|
2024-03-13 01:08:44 +00:00
|
|
|
std::io::Cursor::new(self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-14 05:27:28 +00:00
|
|
|
pub struct Dom(rbx_dom_weak::WeakDom);
|
|
|
|
|
2024-01-31 04:25:07 +00:00
|
|
|
#[derive(Debug)]
|
2024-02-14 05:27:28 +00:00
|
|
|
pub enum ReadError{
|
2024-01-31 04:25:07 +00:00
|
|
|
RbxBinary(rbx_binary::DecodeError),
|
|
|
|
RbxXml(rbx_xml::DecodeError),
|
|
|
|
Io(std::io::Error),
|
|
|
|
UnknownFileFormat,
|
|
|
|
}
|
2024-02-14 05:27:28 +00:00
|
|
|
impl std::fmt::Display for ReadError{
|
|
|
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
|
|
write!(f,"{self:?}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl std::error::Error for ReadError{}
|
2024-01-31 04:25:07 +00:00
|
|
|
|
2024-02-14 05:27:28 +00:00
|
|
|
pub fn read<R:Read>(input:R)->Result<Dom,ReadError>{
|
2024-01-31 04:25:07 +00:00
|
|
|
let mut buf=std::io::BufReader::new(input);
|
2024-02-14 05:27:28 +00:00
|
|
|
let peek=std::io::BufRead::fill_buf(&mut buf).map_err(ReadError::Io)?;
|
2024-01-31 04:25:07 +00:00
|
|
|
match &peek[0..8]{
|
2024-02-14 05:27:28 +00:00
|
|
|
b"<roblox!"=>rbx_binary::from_reader(buf).map(Dom).map_err(ReadError::RbxBinary),
|
|
|
|
b"<roblox "=>rbx_xml::from_reader_default(buf).map(Dom).map_err(ReadError::RbxXml),
|
|
|
|
_=>Err(ReadError::UnknownFileFormat),
|
2024-01-31 04:25:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-14 05:27:28 +00:00
|
|
|
//ConvertError
|
|
|
|
|
2024-03-09 18:47:29 +00:00
|
|
|
pub fn convert<AcquireRenderConfigId,AcquireMeshId>(
|
|
|
|
dom:&Dom,
|
|
|
|
acquire_render_config_id:AcquireRenderConfigId,
|
|
|
|
acquire_mesh_id:AcquireMeshId
|
|
|
|
)->rbx::PartialMap1
|
|
|
|
where
|
|
|
|
AcquireRenderConfigId:FnMut(Option<&str>)->strafesnet_common::model::RenderConfigId,
|
|
|
|
AcquireMeshId:FnMut(&str)->strafesnet_common::model::MeshId,
|
|
|
|
{
|
|
|
|
rbx::convert(&dom.0,acquire_render_config_id,acquire_mesh_id)
|
2024-01-31 04:25:07 +00:00
|
|
|
}
|