wip compile
This commit is contained in:
parent
48ab23bae5
commit
7e27b378e9
89
src/main.rs
89
src/main.rs
@ -163,7 +163,11 @@ async fn main()->AResult<()>{
|
|||||||
}).collect()
|
}).collect()
|
||||||
).await,
|
).await,
|
||||||
Commands::Upload=>upload_list(cookie.unwrap(),cli.group,vec![(cli.asset_id.unwrap(),cli.output.unwrap())]).await,
|
Commands::Upload=>upload_list(cookie.unwrap(),cli.group,vec![(cli.asset_id.unwrap(),cli.output.unwrap())]).await,
|
||||||
Commands::Compile=>compile(cli.input.unwrap(),cli.output.unwrap()),
|
Commands::Compile=>compile(CompileConfig{
|
||||||
|
input_folder:cli.input.unwrap(),
|
||||||
|
output_file:cli.output.unwrap(),
|
||||||
|
template:None,
|
||||||
|
}),
|
||||||
Commands::Decompile=>decompile(DecompileConfig{
|
Commands::Decompile=>decompile(DecompileConfig{
|
||||||
style:decompile_style.unwrap(),
|
style:decompile_style.unwrap(),
|
||||||
input_file:cli.input.unwrap(),
|
input_file:cli.input.unwrap(),
|
||||||
@ -1080,6 +1084,87 @@ async fn download_and_decompile_history_into_git(config:DownloadAndDecompileHist
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile(_folder:std::path::PathBuf,_file:std::path::PathBuf)->AResult<()>{
|
enum CompileClass{
|
||||||
|
Folder,
|
||||||
|
Script(String),
|
||||||
|
LocalScript(String),
|
||||||
|
ModuleScript(String),
|
||||||
|
Model(Vec<u8>),
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CompileNode{
|
||||||
|
folder:Option<tokio::fs::ReadDir>,
|
||||||
|
class:CompileClass,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum CompileStackInstruction{
|
||||||
|
Referent(rbx_dom_weak::types::Ref),
|
||||||
|
PushFolder(String),
|
||||||
|
PopFolder,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CompileConfig{
|
||||||
|
input_folder:std::path::PathBuf,
|
||||||
|
output_file:std::path::PathBuf,
|
||||||
|
template:Option<std::path::PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compile(config:CompileConfig)->AResult<()>{
|
||||||
|
//basically decompile in reverse order
|
||||||
|
//load template dom
|
||||||
|
let input={
|
||||||
|
let template_path=config.template.unwrap_or_else(||{
|
||||||
|
let mut template_path=config.input_folder.clone();
|
||||||
|
template_path.push("template.rbxlx");
|
||||||
|
template_path
|
||||||
|
});
|
||||||
|
std::io::BufReader::new(std::fs::File::open(template_path)?)
|
||||||
|
};
|
||||||
|
let mut dom=load_dom(input)?;
|
||||||
|
|
||||||
|
//add in scripts and models
|
||||||
|
let mut folder=config.input_folder.clone();
|
||||||
|
folder.push("src");
|
||||||
|
let mut stack:Vec<CompileStackInstruction>=dom.root().children().into_iter().map(|&referent|CompileStackInstruction::Referent(referent)).collect();
|
||||||
|
while let Some(instruction)=stack.pop(){
|
||||||
|
match instruction{
|
||||||
|
CompileStackInstruction::Referent(item_ref)=>{
|
||||||
|
let item=dom.get_by_ref(item_ref).ok_or(anyhow::Error::msg("null child ref"))?;
|
||||||
|
//check if item exists in folder or subfolder of same name
|
||||||
|
let what=||async{
|
||||||
|
//figure out something clever for this
|
||||||
|
|
||||||
|
let mut what=CompileNode{
|
||||||
|
class:CompileClass::Folder,
|
||||||
|
folder:None,
|
||||||
|
};
|
||||||
|
let mut contents_folder=folder.clone();
|
||||||
|
contents_folder.push(item.name.as_str());
|
||||||
|
//folder
|
||||||
|
if let Ok(dir)=tokio::fs::read_dir(contents_folder.as_path()).await{
|
||||||
|
what.folder=Some(dir);
|
||||||
|
}else{
|
||||||
|
contents_folder.pop();
|
||||||
|
}
|
||||||
|
//tokio::join!(a,b,c);
|
||||||
|
//rox
|
||||||
|
let mut rox_path=contents_folder.clone();
|
||||||
|
rox_path.push(format!("{}.lua",item.name.as_str()));
|
||||||
|
if let Ok(file)=tokio::fs::File::open(rox_path).await{
|
||||||
|
//CompileClass::ModuleScript
|
||||||
|
}
|
||||||
|
//rox-rojo
|
||||||
|
//rojo
|
||||||
|
};
|
||||||
|
//push child objects onto dom
|
||||||
|
//push dom children objects onto stack
|
||||||
|
stack.push(CompileStackInstruction::PopFolder);
|
||||||
|
stack.extend(item.children().into_iter().map(|&referent|CompileStackInstruction::Referent(referent)));
|
||||||
|
stack.push(CompileStackInstruction::PushFolder(sanitize(item.name.as_str()).to_string()));
|
||||||
|
},
|
||||||
|
CompileStackInstruction::PushFolder(component)=>folder.push(component),
|
||||||
|
CompileStackInstruction::PopFolder=>assert!(folder.pop(),"pop folder bad"),
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user