From 7ada66ffbf01e9f88bb9345b77930c1b95576c79 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 1 Oct 2024 13:00:54 -0700 Subject: [PATCH] split out rbxasset --- src/lib.rs | 5 ++++- src/rbxassetid.rs | 34 ++++++++++++++++++++++++++++++++++ src/roblox_legacy.rs | 36 +----------------------------------- 3 files changed, 39 insertions(+), 36 deletions(-) create mode 100644 src/rbxassetid.rs diff --git a/src/lib.rs b/src/lib.rs index c8b5e99..767528a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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() -} \ No newline at end of file +} diff --git a/src/rbxassetid.rs b/src/rbxassetid.rs new file mode 100644 index 0000000..daf227c --- /dev/null +++ b/src/rbxassetid.rs @@ -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{ + 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{} diff --git a/src/roblox_legacy.rs b/src/roblox_legacy.rs index 18263c7..a6480fe 100644 --- a/src/roblox_legacy.rs +++ b/src/roblox_legacy.rs @@ -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{ - 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{