quicksave

This commit is contained in:
Quaternions 2024-07-01 11:59:22 -07:00
parent 2efbc3b437
commit 581a0d6699
8 changed files with 55 additions and 35 deletions

1
Cargo.lock generated
View File

@ -1358,6 +1358,7 @@ version = "0.1.0"
dependencies = [
"lazy-regex",
"rbx_dom_weak",
"rbx_xml",
"tokio",
]

View File

@ -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"] }

View File

@ -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,"_")
}

View File

@ -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

View File

@ -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<String>,
class:Option<String>,
}
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<rbx_dom_weak::types::Ref,TreeNode>,
}
fn generate_decompiled_context<R:Read>(input:R)->AResult<DecompiledContext>{
let dom=load_dom(input)?;
fn generate_decompiled_context(dom:rbx_dom_weak::WeakDom)->Result<DecompiledContext,DecompileError>{
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();

View File

@ -1,2 +1,4 @@
mod common;
pub mod types;
pub mod compile;
pub mod decompile;

29
rox_compiler/src/types.rs Normal file
View File

@ -0,0 +1,29 @@
#[derive(Clone,Copy,Debug)]
pub enum DecompileStyle{
Rox,
Rojo,
RoxRojo,
}
#[derive(Default)]
pub(crate) struct PropertiesOverride{
pub name:Option<String>,
pub class:Option<String>,
}
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(())
}
}

View File

@ -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<()>{