rbx_loader/src/lib.rs

36 lines
997 B
Rust
Raw Normal View History

use std::io::Read;
mod rbx;
2024-01-31 01:41:16 +00:00
mod primitives;
2024-02-14 05:27:28 +00:00
pub struct Dom(rbx_dom_weak::WeakDom);
#[derive(Debug)]
2024-02-14 05:27:28 +00:00
pub enum ReadError{
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-02-14 05:27:28 +00:00
pub fn read<R:Read>(input:R)->Result<Dom,ReadError>{
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)?;
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-02-14 05:27:28 +00:00
//ConvertError
pub fn convert<F:FnMut(&str)->Option<strafesnet_common::model::TextureId>>(dom:&Dom,acquire_id:F)->strafesnet_common::map::CompleteMap{
rbx::convert(&dom.0,acquire_id)
}