diff --git a/validation/src/create.rs b/validation/src/create.rs index c6ea948..f29d4ca 100644 --- a/validation/src/create.rs +++ b/validation/src/create.rs @@ -1,5 +1,5 @@ use crate::download::download_asset_version; -use crate::rbx_util::{get_root_instance,get_mapinfo,read_dom,MapInfo,ReadDomError,GetRootInstanceError,ParseGameIDError}; +use crate::rbx_util::{get_root_instance,get_mapinfo,read_dom,MapInfo,ReadDomError,GetRootInstanceError,GameID}; #[allow(dead_code)] #[derive(Debug)] @@ -9,7 +9,6 @@ pub enum Error{ Download(crate::download::Error), ModelFileDecode(ReadDomError), GetRootInstance(GetRootInstanceError), - ParseGameID(ParseGameIDError), } impl std::fmt::Display for Error{ fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ @@ -24,10 +23,10 @@ pub struct CreateRequest{ } #[allow(nonstandard_style)] pub struct CreateResult{ - pub AssetOwner:i64, - pub DisplayName:String, - pub Creator:String, - pub GameID:i32, + pub AssetOwner:u64, + pub DisplayName:Option<String>, + pub Creator:Option<String>, + pub GameID:Option<GameID>, pub AssetVersion:u64, } impl crate::message_handler::MessageHandler{ @@ -63,13 +62,11 @@ impl crate::message_handler::MessageHandler{ game_id, }=get_mapinfo(&dom,model_instance); - let game_id=game_id.map_err(Error::ParseGameID)?; - Ok(CreateResult{ - AssetOwner:user_id as i64, - DisplayName:display_name.unwrap_or_default().to_owned(), - Creator:creator.unwrap_or_default().to_owned(), - GameID:game_id as i32, + AssetOwner:user_id, + DisplayName:display_name.ok().map(ToOwned::to_owned), + Creator:creator.ok().map(ToOwned::to_owned), + GameID:game_id.ok(), AssetVersion:asset_version, }) } diff --git a/validation/src/create_mapfix.rs b/validation/src/create_mapfix.rs index 010df43..9980c53 100644 --- a/validation/src/create_mapfix.rs +++ b/validation/src/create_mapfix.rs @@ -24,10 +24,11 @@ impl crate::message_handler::MessageHandler{ // call create on api self.api.create_mapfix(submissions_api::types::CreateMapfixRequest{ OperationID:create_info.OperationID, - AssetOwner:create_request.AssetOwner, - DisplayName:create_request.DisplayName.as_str(), - Creator:create_request.Creator.as_str(), - GameID:create_request.GameID, + AssetOwner:create_request.AssetOwner as i64, + DisplayName:create_request.DisplayName.as_deref().unwrap_or_default(), + Creator:create_request.Creator.as_deref().unwrap_or_default(), + // not great TODO: make this great + GameID:create_request.GameID.unwrap_or(crate::rbx_util::GameID::Bhop) as i32, AssetID:create_info.ModelID, AssetVersion:create_request.AssetVersion, TargetAssetID:create_info.TargetAssetID, diff --git a/validation/src/create_submission.rs b/validation/src/create_submission.rs index 370e80d..06485d4 100644 --- a/validation/src/create_submission.rs +++ b/validation/src/create_submission.rs @@ -1,5 +1,6 @@ use crate::nats_types::CreateSubmissionRequest; use crate::create::CreateRequest; +use crate::rbx_util::GameID; #[allow(dead_code)] #[derive(Debug)] @@ -19,13 +20,29 @@ impl crate::message_handler::MessageHandler{ let create_request=self.create_inner(CreateRequest{ ModelID:create_info.ModelID, }).await.map_err(Error::Create)?; + + // grab values from submission form, otherwise try to fill blanks from map data + let display_name=if create_info.DisplayName.is_empty(){ + create_request.DisplayName.as_deref().unwrap_or_default() + }else{ + create_info.DisplayName.as_str() + }; + + let creator=if create_info.Creator.is_empty(){ + create_request.Creator.as_deref().unwrap_or_default() + }else{ + create_info.Creator.as_str() + }; + + let game_id=create_info.GameID.try_into().ok().or(create_request.GameID).unwrap_or(GameID::Bhop); + // call create on api self.api.create_submission(submissions_api::types::CreateSubmissionRequest{ OperationID:create_info.OperationID, - AssetOwner:create_request.AssetOwner, - DisplayName:create_request.DisplayName.as_str(), - Creator:create_request.Creator.as_str(), - GameID:create_request.GameID, + AssetOwner:create_request.AssetOwner as i64, + DisplayName:display_name, + Creator:creator, + GameID:game_id as i32, AssetID:create_info.ModelID, AssetVersion:create_request.AssetVersion, }).await.map_err(Error::ApiActionSubmissionCreate)?; diff --git a/validation/src/nats_types.rs b/validation/src/nats_types.rs index bca6646..357e69b 100644 --- a/validation/src/nats_types.rs +++ b/validation/src/nats_types.rs @@ -10,6 +10,9 @@ pub struct CreateSubmissionRequest{ // operation_id is passed back in the response message pub OperationID:i32, pub ModelID:u64, + pub DisplayName:String, + pub Creator:String, + pub GameID:u32, } #[allow(nonstandard_style)] diff --git a/validation/src/rbx_util.rs b/validation/src/rbx_util.rs index 92f8fa4..598f35f 100644 --- a/validation/src/rbx_util.rs +++ b/validation/src/rbx_util.rs @@ -70,6 +70,18 @@ impl std::str::FromStr for GameID{ return Err(ParseGameIDError); } } +pub struct GameIDError; +impl TryFrom<u32> for GameID{ + type Error=GameIDError; + fn try_from(value:u32)->Result<Self,Self::Error>{ + match value{ + 1=>Ok(GameID::Bhop), + 2=>Ok(GameID::Surf), + 5=>Ok(GameID::FlyTrials), + _=>Err(GameIDError) + } + } +} pub struct MapInfo<'a>{ pub display_name:Result<&'a str,StringValueError>,