validator: prepare for checks

This commit is contained in:
Quaternions 2025-04-07 16:54:57 -07:00
parent 7334e88b55
commit e2c72c90c7
Signed by: Quaternions
GPG Key ID: D0DF5964F79AC131
2 changed files with 16 additions and 9 deletions
validation/src

@ -1,4 +1,4 @@
use crate::rbx_util::{get_mapinfo,read_dom,MapInfo,ReadDomError,GetMapInfoError,ParseGameIDError};
use crate::rbx_util::{get_root_instance,get_mapinfo,read_dom,MapInfo,ReadDomError,GetRootInstanceError,ParseGameIDError};
#[allow(dead_code)]
#[derive(Debug)]
@ -11,7 +11,7 @@ pub enum Error{
ParseUserID(core::num::ParseIntError),
ParseModelVersion(core::num::ParseIntError),
ModelFileDecode(ReadDomError),
GetMapInfo(GetMapInfoError),
GetRootInstance(GetRootInstanceError),
ParseGameID(ParseGameIDError),
}
impl std::fmt::Display for Error{
@ -66,12 +66,15 @@ impl crate::message_handler::MessageHandler{
// decode dom (slow!)
let dom=read_dom(std::io::Cursor::new(model_data)).map_err(Error::ModelFileDecode)?;
// extract the root instance
let model_instance=get_root_instance(&dom).map_err(Error::GetRootInstance)?;
// parse create fields out of asset
let MapInfo{
display_name,
creator,
game_id,
}=get_mapinfo(&dom).map_err(Error::GetMapInfo)?;
}=get_mapinfo(&dom,model_instance);
let game_id=game_id.map_err(Error::ParseGameID)?;

@ -100,20 +100,24 @@ fn string_value(instance:Option<&rbx_dom_weak::Instance>)->Result<&str,StringVal
}
#[derive(Debug)]
pub enum GetMapInfoError{
pub enum GetRootInstanceError{
ModelFileRootMustHaveOneChild,
ModelFileChildRefIsNil,
}
pub fn get_mapinfo(dom:&rbx_dom_weak::WeakDom)->Result<MapInfo,GetMapInfoError>{
pub fn get_root_instance(dom:&rbx_dom_weak::WeakDom)->Result<&rbx_dom_weak::Instance,GetRootInstanceError>{
let &[map_ref]=dom.root().children()else{
return Err(GetMapInfoError::ModelFileRootMustHaveOneChild);
return Err(GetRootInstanceError::ModelFileRootMustHaveOneChild);
};
let model_instance=dom.get_by_ref(map_ref).ok_or(GetMapInfoError::ModelFileChildRefIsNil)?;
let model_instance=dom.get_by_ref(map_ref).ok_or(GetRootInstanceError::ModelFileChildRefIsNil)?;
Ok(MapInfo{
Ok(model_instance)
}
pub fn get_mapinfo<'a>(dom:&'a rbx_dom_weak::WeakDom,model_instance:&rbx_dom_weak::Instance)->MapInfo<'a>{
MapInfo{
display_name:string_value(find_first_child_class(dom,model_instance,"DisplayName","StringValue")),
creator:string_value(find_first_child_class(dom,model_instance,"Creator","StringValue")),
game_id:model_instance.name.parse(),
})
}
}