split out rbxasset

This commit is contained in:
Quaternions 2024-10-01 13:00:54 -07:00
parent 72caf29ad8
commit 7ada66ffbf
3 changed files with 39 additions and 36 deletions

View File

@ -7,6 +7,9 @@ mod roblox;
#[cfg(feature="source")]
mod source;
#[cfg(any(feature="roblox",feature="legacy"))]
pub mod rbxassetid;
pub mod texture;
#[cfg(any(feature="source",feature="legacy"))]
pub mod valve_mesh;
@ -28,4 +31,4 @@ pub fn roblox()->roblox::Loader{
#[cfg(feature="source")]
pub fn source()->source::Loader{
source::Loader::new()
}
}

34
src/rbxassetid.rs Normal file
View File

@ -0,0 +1,34 @@
#[derive(Hash,Eq,PartialEq)]
pub struct RobloxAssetId(pub u64);
#[derive(Debug)]
#[allow(dead_code)]
pub enum RobloxAssetIdParseErr{
Url(url::ParseError),
UnknownScheme(String),
ParseInt(std::num::ParseIntError),
MissingAssetId(String),
}
impl std::str::FromStr for RobloxAssetId{
type Err=RobloxAssetIdParseErr;
fn from_str(s:&str)->Result<Self,Self::Err>{
let url=url::Url::parse(s).map_err(RobloxAssetIdParseErr::Url)?;
let parsed_asset_id=match url.scheme(){
"rbxassetid"=>url.domain().ok_or_else(||RobloxAssetIdParseErr::MissingAssetId(s.to_owned()))?.parse(),
"http"|"https"=>{
let (_,asset_id)=url.query_pairs()
.find(|(id,_)|
id.to_lowercase()=="id"
).ok_or_else(||RobloxAssetIdParseErr::MissingAssetId(s.to_owned()))?;
asset_id.parse()
},
_=>Err(RobloxAssetIdParseErr::UnknownScheme(s.to_owned()))?,
};
Ok(Self(parsed_asset_id.map_err(RobloxAssetIdParseErr::ParseInt)?))
}
}
impl std::fmt::Display for RobloxAssetIdParseErr{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for RobloxAssetIdParseErr{}

View File

@ -3,41 +3,7 @@ use std::collections::HashMap;
use crate::roblox_mesh;
use crate::texture::{RenderConfigs,Texture};
use strafesnet_common::model::{MeshId,RenderConfig,RenderConfigId,TextureId};
#[derive(Hash,Eq,PartialEq)]
struct RobloxAssetId(u64);
#[derive(Debug)]
#[allow(dead_code)]
pub enum RobloxAssetIdParseErr{
Url(url::ParseError),
UnknownScheme(String),
ParseInt(std::num::ParseIntError),
MissingAssetId(String),
}
impl std::str::FromStr for RobloxAssetId{
type Err=RobloxAssetIdParseErr;
fn from_str(s:&str)->Result<Self,Self::Err>{
let url=url::Url::parse(s).map_err(RobloxAssetIdParseErr::Url)?;
let parsed_asset_id=match url.scheme(){
"rbxassetid"=>url.domain().ok_or_else(||RobloxAssetIdParseErr::MissingAssetId(s.to_owned()))?.parse(),
"http"|"https"=>{
let (_,asset_id)=url.query_pairs()
.find(|(id,_)|
id.to_lowercase()=="id"
).ok_or_else(||RobloxAssetIdParseErr::MissingAssetId(s.to_owned()))?;
asset_id.parse()
},
_=>Err(RobloxAssetIdParseErr::UnknownScheme(s.to_owned()))?,
};
Ok(Self(parsed_asset_id.map_err(RobloxAssetIdParseErr::ParseInt)?))
}
}
impl std::fmt::Display for RobloxAssetIdParseErr{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for RobloxAssetIdParseErr{}
use crate::rbxassetid::RobloxAssetId;
#[derive(Default)]
pub struct RenderConfigLoader{