extract_script_overrides

This commit is contained in:
Quaternions 2024-01-23 20:19:47 -08:00
parent 8ee041918b
commit db2c760c49

View File

@ -1266,6 +1266,31 @@ impl Query for QueryQuad{
}
}
struct ScriptWithOverrides{
overrides:PropertiesOverride,
source:String,
}
fn extract_script_overrides(mut source:String)->AResult<ScriptWithOverrides>{
let mut overrides=PropertiesOverride::default();
let mut count=0;
for line in source.lines(){
//only string type properties are supported atm
if let Some(captures)=lazy_regex::regex!(r#"^\-\-\!\s*Properties\.([A-z]\w*)\s*\=\s*"(\w+)"$"#)
.captures(line){
count+=line.len();
match &captures[1]{
"Name"=>overrides.name=Some(captures[2].to_owned()),
"ClassName"=>overrides.class=Some(captures[2].to_owned()),
other=>return Err(anyhow::Error::msg(format!("Unimplemented property {other}"))),
}
}else{
break;
}
}
Ok(ScriptWithOverrides{overrides,source:source.split_off(count)})
}
async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Option<DecompileStyle>)->AResult<Option<CompileNode>>{
let mut contents_folder=search_path.clone();
contents_folder.push(search_name);
@ -1293,10 +1318,19 @@ async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Opt
let mut buf=String::new();
file.read_to_string(&mut buf).await?;
//regex script according to Properties lines at the top
todo!("unimplemented");
let script_with_overrides=extract_script_overrides(buf)?;
//script
CompileNode{
class:CompileClass::Script(buf),
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),
(Some("LocalScript"),_)
|(None,ScriptHint::Script)=>CompileClass::LocalScript(script_with_overrides.source),
(Some("Script"),_)
|(None,ScriptHint::LocalScript)=>CompileClass::Script(script_with_overrides.source),
other=>return Err(anyhow::Error::msg(format!("Invalid hint or class {other:?}"))),
},
folder:Some(dir),
}
},
@ -1306,6 +1340,7 @@ async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Opt
file.read_to_end(&mut buf).await?;
//model
CompileNode{
name:search_name.to_owned(),
class:CompileClass::Model(buf),
folder:Some(dir),
}
@ -1313,6 +1348,7 @@ async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Opt
(Ok(_),Ok(_))=>Err(QueryResolveError::Ambiguous)?,
//neither
(Err(QueryResolveError::NotFound),Err(QueryResolveError::NotFound))=>CompileNode{
name:search_name.to_owned(),
class:CompileClass::Folder,
folder:Some(dir),
},
@ -1325,7 +1361,7 @@ async fn discern_node(search_path:&std::path::PathBuf,search_name:&str,style:Opt
None
})
}
#[derive(Debug)]
enum ScriptHint{
Script,
LocalScript,
@ -1346,8 +1382,9 @@ enum CompileClass{
}
struct CompileNode{
folder:Option<tokio::fs::ReadDir>,
name:String,
class:CompileClass,
folder:Option<tokio::fs::ReadDir>,
}
enum CompileStackInstruction{