From 17bfbef4821651a163c0d69d6a0ac9ffcc6e3865 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 24 Jan 2024 14:42:16 -0800 Subject: [PATCH] misc tweaks + tweak Query objects + remove ScriptHint::Undetermined --- src/main.rs | 59 ++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/src/main.rs b/src/main.rs index f6ffb20..f9674f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1125,25 +1125,30 @@ type QueryHintResult=Result; trait Query{ async fn resolve(self)->QueryHintResult; } -struct QuerySingle(tokio::task::JoinHandle>); +type QueryHandle=tokio::task::JoinHandle>; +struct QuerySingle{ + script:QueryHandle, +} impl QuerySingle{ fn rox(search_path:&std::path::PathBuf,search_name:&str)->Self{ - Self(tokio::spawn(get_file_async(search_path.clone(),format!("{}.lua",search_name)))) + Self{ + script:tokio::spawn(get_file_async(search_path.clone(),format!("{}.lua",search_name))) + } } } impl Query for QuerySingle{ async fn resolve(self)->QueryHintResult{ - match self.0.await{ - Ok(Ok(file))=>Ok(FileHint{file,hint:ScriptHint::Undetermined}), + match self.script.await{ + Ok(Ok(file))=>Ok(FileHint{file,hint:ScriptHint::ModuleScript}), Ok(Err(e))=>Err(e), Err(e)=>Err(QueryResolveError::JoinError(e)), } } } struct QueryTriple{ - module:QuerySingle, - server:QuerySingle, - client:QuerySingle, + module:QueryHandle, + server:QueryHandle, + client:QueryHandle, } impl QueryTriple{ fn rox_rojo(search_path:&std::path::PathBuf,search_name:&str,search_module:bool)->Self{ @@ -1154,9 +1159,9 @@ impl QueryTriple{ format!("{}.lua",search_name) }; Self{ - module:QuerySingle(tokio::spawn(get_file_async(search_path.clone(),module_name))), - server:QuerySingle(tokio::spawn(get_file_async(search_path.clone(),format!("{}.server.lua",search_name)))), - client:QuerySingle(tokio::spawn(get_file_async(search_path.clone(),format!("{}.client.lua",search_name)))), + module:tokio::spawn(get_file_async(search_path.clone(),module_name)), + server:tokio::spawn(get_file_async(search_path.clone(),format!("{}.server.lua",search_name))), + client:tokio::spawn(get_file_async(search_path.clone(),format!("{}.client.lua",search_name))), } } fn rojo(search_path:&std::path::PathBuf)->Self{ @@ -1214,7 +1219,7 @@ fn mega_quadruple_join(query_quad:(QueryHintResult,QueryHintResult,QueryHintResu } impl Query for QueryTriple{ async fn resolve(self)->QueryHintResult{ - let (module,server,client)=tokio::join!(self.module.0,self.server.0,self.client.0); + let (module,server,client)=tokio::join!(self.module,self.server,self.client); mega_triple_join(( module.map_err(|e|QueryResolveError::JoinError(e))?.map(|file|FileHint{file,hint:ScriptHint::ModuleScript}), server.map_err(|e|QueryResolveError::JoinError(e))?.map(|file|FileHint{file,hint:ScriptHint::Script}), @@ -1223,16 +1228,16 @@ impl Query for QueryTriple{ } } struct QueryQuad{ - module_implicit:QuerySingle, - module_explicit:QuerySingle, - server:QuerySingle, - client:QuerySingle, + module_implicit:QueryHandle, + module_explicit:QueryHandle, + server:QueryHandle, + client:QueryHandle, } impl QueryQuad{ fn rox_rojo(search_path:&std::path::PathBuf,search_name:&str)->Self{ let fill=QueryTriple::rox_rojo(search_path,search_name,true); Self{ - module_implicit:QuerySingle::rox(search_path,search_name),//Script.lua + module_implicit:QuerySingle::rox(search_path,search_name).script,//Script.lua module_explicit:fill.module,//Script.module.lua server:fill.server, client:fill.client, @@ -1241,7 +1246,7 @@ impl QueryQuad{ } impl Query for QueryQuad{ async fn resolve(self)->QueryHintResult{ - let (module_implicit,module_explicit,server,client)=tokio::join!(self.module_implicit.0,self.module_explicit.0,self.server.0,self.client.0); + let (module_implicit,module_explicit,server,client)=tokio::join!(self.module_implicit,self.module_explicit,self.server,self.client); mega_quadruple_join(( module_implicit.map_err(|e|QueryResolveError::JoinError(e))?.map(|file|FileHint{file,hint:ScriptHint::ModuleScript}), module_explicit.map_err(|e|QueryResolveError::JoinError(e))?.map(|file|FileHint{file,hint:ScriptHint::ModuleScript}), @@ -1287,7 +1292,7 @@ async fn script_node(search_name:&str,mut file:tokio::fs::File,hint:ScriptHint)- name:script_with_overrides.overrides.name.unwrap_or_else(||search_name.to_owned()), class:match (script_with_overrides.overrides.class.as_deref(),hint){ (Some("ModuleScript"),_) - |(None,ScriptHint::ModuleScript|ScriptHint::Undetermined)=>CompileClass::ModuleScript(script_with_overrides.source), + |(None,ScriptHint::ModuleScript)=>CompileClass::ModuleScript(script_with_overrides.source), (Some("LocalScript"),_) |(None,ScriptHint::Script)=>CompileClass::LocalScript(script_with_overrides.source), (Some("Script"),_) @@ -1308,18 +1313,9 @@ async fn model_node(search_name:&str,mut file:tokio::fs::File)->AResult)->AResult>{ +async fn locate_override_file(entry:&tokio::fs::DirEntry,style:Option)->AResult>{ let contents_folder=entry.path(); let file_name=entry.file_name(); - //is folder? else exit flow control - match tokio::fs::read_dir(contents_folder.as_path()).await{ - Ok(_)=>(),//continue flow - Err(e)=>{println!("{:?}",e.raw_os_error());match e.raw_os_error(){ - Some(0)//std::io::ErrorKind::NotFound - |Some(20)=>return Ok(None),//std::io::ErrorKind::NotADirectory (not allowed to be used but returns it anyways) - _=>Err(e)?, - }} - } let search_name=file_name.to_str().unwrap(); //scan inside the folder for an object to define the class of the folder let script_query=async {match style{ @@ -1362,8 +1358,8 @@ async fn discern_file(entry:&tokio::fs::DirEntry,style:Option)-> let path=entry.path(); let file_discernment=match path.extension(){ Some(extension)=>match extension.to_str(){ - Some("lua")=>FileDiscernment::Script(ScriptHint::Undetermined), - Some("module.lua")=>FileDiscernment::Script(ScriptHint::ModuleScript), + Some("lua") + |Some("module.lua")=>FileDiscernment::Script(ScriptHint::ModuleScript), Some("client.lua")=>FileDiscernment::Script(ScriptHint::LocalScript), Some("server.lua")=>FileDiscernment::Script(ScriptHint::Script), Some("rbxmx")=>FileDiscernment::Model, @@ -1391,7 +1387,6 @@ enum ScriptHint{ Script, LocalScript, ModuleScript, - Undetermined, } struct FileHint{ file:tokio::fs::File, @@ -1485,7 +1480,7 @@ async fn compile(config:CompileConfig)->AResult<()>{ join_set.spawn(async move{ let met=entry.metadata().await?; let scooby_doo=if met.is_dir(){ - discern_node(&entry,style).await + locate_override_file(&entry,style).await }else{ discern_file(&entry,style).await };