From 581a0d66997f81bf2e142e35d5070b9ac9e3330d Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 1 Jul 2024 11:59:22 -0700 Subject: [PATCH] quicksave --- Cargo.lock | 1 + rox_compiler/Cargo.toml | 1 + rox_compiler/src/common.rs | 3 +++ rox_compiler/src/compile.rs | 6 +++++- rox_compiler/src/decompile.rs | 37 ++++------------------------------- rox_compiler/src/lib.rs | 2 ++ rox_compiler/src/types.rs | 29 +++++++++++++++++++++++++++ src/main.rs | 11 ++++++++++- 8 files changed, 55 insertions(+), 35 deletions(-) create mode 100644 rox_compiler/src/common.rs create mode 100644 rox_compiler/src/types.rs diff --git a/Cargo.lock b/Cargo.lock index 15e18e8..904478a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1358,6 +1358,7 @@ version = "0.1.0" dependencies = [ "lazy-regex", "rbx_dom_weak", + "rbx_xml", "tokio", ] diff --git a/rox_compiler/Cargo.toml b/rox_compiler/Cargo.toml index 97c4a0d..cc6c259 100644 --- a/rox_compiler/Cargo.toml +++ b/rox_compiler/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" [dependencies] lazy-regex = "3.1.0" rbx_dom_weak = "2.7.0" +rbx_xml = "0.13.3" tokio = { version = "1.35.1", features = ["fs"] } diff --git a/rox_compiler/src/common.rs b/rox_compiler/src/common.rs new file mode 100644 index 0000000..9828830 --- /dev/null +++ b/rox_compiler/src/common.rs @@ -0,0 +1,3 @@ +pub(crate) fn sanitize<'a>(s:&'a str)->std::borrow::Cow<'a,str>{ + lazy_regex::regex!(r"[^A-z0-9.-]").replace_all(s,"_") +} diff --git a/rox_compiler/src/compile.rs b/rox_compiler/src/compile.rs index 03a1867..80edfc0 100644 --- a/rox_compiler/src/compile.rs +++ b/rox_compiler/src/compile.rs @@ -1,4 +1,8 @@ -use rbx_dom_weak::types::Ref; +use std::path::PathBuf; +use tokio::io::AsyncReadExt; + +use crate::types::{DecompileStyle,PropertiesOverride}; +use crate::common::sanitize; //holy smokes what am I doing lmao //This giant machine is supposed to search for files according to style rules diff --git a/rox_compiler/src/decompile.rs b/rox_compiler/src/decompile.rs index b7e7c82..eb9efea 100644 --- a/rox_compiler/src/decompile.rs +++ b/rox_compiler/src/decompile.rs @@ -1,6 +1,6 @@ -use std::path::PathBuf; - +use std::{io::Read, path::PathBuf}; use rbx_dom_weak::types::Ref; +use crate::{common::sanitize, types::{DecompileStyle, PropertiesOverride}}; #[derive(PartialEq)] enum Class{ @@ -43,33 +43,6 @@ enum WriteStackInstruction<'a>{ Destroy(Ref), } -#[derive(Default)] -struct PropertiesOverride{ - name:Option, - class:Option, -} -impl PropertiesOverride{ - fn is_some(&self)->bool{ - self.name.is_some() - ||self.class.is_some() - } -} -impl std::fmt::Display for PropertiesOverride{ - fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ - if let Some(name)=self.name.as_deref(){ - writeln!(f,"--!Properties.Name = \"{}\"",name)?; - } - if let Some(class)=self.class.as_deref(){ - writeln!(f,"--!Properties.ClassName = \"{}\"",class)?; - } - Ok(()) - } -} - -fn sanitize<'a>(s:&'a str)->std::borrow::Cow<'a,str>{ - lazy_regex::regex!(r"[^A-z0-9.-]").replace_all(s,"_") -} - fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:PathBuf,node:&TreeNode,node_name_override:String,mut properties:PropertiesOverride,style:DecompileStyle,write_models:bool,write_scripts:bool)->AResult<()>{ file.push(sanitize(node_name_override.as_str()).as_ref()); match node.class{ @@ -132,9 +105,7 @@ struct DecompiledContext{ tree_refs:std::collections::HashMap, } -fn generate_decompiled_context(input:R)->AResult{ - let dom=load_dom(input)?; - +fn generate_decompiled_context(dom:rbx_dom_weak::WeakDom)->Result{ let mut tree_refs=std::collections::HashMap::new(); tree_refs.insert(dom.root_ref(),TreeNode::new( "src".to_owned(), @@ -237,7 +208,7 @@ struct WriteConfig{ write_scripts:bool, } -async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult<()>{ +async fn write_files(config:WriteConfig,mut context:DecompiledContext)->Result<(),WriteError>{ let mut write_queue=Vec::new(); let mut destroy_queue=Vec::new(); diff --git a/rox_compiler/src/lib.rs b/rox_compiler/src/lib.rs index 9758e5d..99c92b1 100644 --- a/rox_compiler/src/lib.rs +++ b/rox_compiler/src/lib.rs @@ -1,2 +1,4 @@ +mod common; +pub mod types; pub mod compile; pub mod decompile; diff --git a/rox_compiler/src/types.rs b/rox_compiler/src/types.rs new file mode 100644 index 0000000..990b045 --- /dev/null +++ b/rox_compiler/src/types.rs @@ -0,0 +1,29 @@ +#[derive(Clone,Copy,Debug)] +pub enum DecompileStyle{ + Rox, + Rojo, + RoxRojo, +} + +#[derive(Default)] +pub(crate) struct PropertiesOverride{ + pub name:Option, + pub class:Option, +} +impl PropertiesOverride{ + pub fn is_some(&self)->bool{ + self.name.is_some() + ||self.class.is_some() + } +} +impl std::fmt::Display for PropertiesOverride{ + fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ + if let Some(name)=self.name.as_deref(){ + writeln!(f,"--!Properties.Name = \"{}\"",name)?; + } + if let Some(class)=self.class.as_deref(){ + writeln!(f,"--!Properties.ClassName = \"{}\"",class)?; + } + Ok(()) + } +} diff --git a/src/main.rs b/src/main.rs index 509702a..6ef2516 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,11 +180,20 @@ enum CookieType{ } #[derive(Clone,Copy,Debug,clap::ValueEnum)] -enum DecompileStyle{ +pub enum DecompileStyle{ Rox, Rojo, RoxRojo, } +impl DecompileStyle{ + fn rox(&self)->rox_compiler::types::DecompileStyle{ + match self{ + DecompileStyle::Rox=>rox_compiler::types::DecompileStyle::Rox, + DecompileStyle::Rojo=>rox_compiler::types::DecompileStyle::Rojo, + DecompileStyle::RoxRojo=>rox_compiler::types::DecompileStyle::RoxRojo, + } + } +} #[tokio::main] async fn main()->AResult<()>{