This commit is contained in:
Quaternions 2024-07-01 14:09:52 -07:00
parent f7f309b2bb
commit b09f3a6ab0
3 changed files with 34 additions and 11 deletions

View File

@ -2,8 +2,7 @@ use std::path::PathBuf;
use futures::{StreamExt, TryStreamExt}; use futures::{StreamExt, TryStreamExt};
use tokio::io::AsyncReadExt; use tokio::io::AsyncReadExt;
use crate::types::{Style,PropertiesOverride}; use crate::common::{sanitize,Style,PropertiesOverride};
use crate::common::sanitize;
//holy smokes what am I doing lmao //holy smokes what am I doing lmao
//This giant machine is supposed to search for files according to style rules //This giant machine is supposed to search for files according to style rules
@ -190,6 +189,12 @@ struct ScriptWithOverrides{
pub enum ScriptWithOverridesError{ pub enum ScriptWithOverridesError{
UnimplementedProperty(String), UnimplementedProperty(String),
} }
impl std::fmt::Display for ScriptWithOverridesError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for ScriptWithOverridesError{}
impl ScriptWithOverrides{ impl ScriptWithOverrides{
fn from_source(mut source:String)->Result<Self,ScriptWithOverridesError>{ fn from_source(mut source:String)->Result<Self,ScriptWithOverridesError>{
@ -240,6 +245,12 @@ enum CompileNodeError{
}, },
NoExtension, NoExtension,
} }
impl std::fmt::Display for CompileNodeError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for CompileNodeError{}
enum FileDiscernment{ enum FileDiscernment{
Model, Model,
@ -407,6 +418,12 @@ pub enum CompileError{
DecodeError(rbx_xml::DecodeError), DecodeError(rbx_xml::DecodeError),
JoinError(tokio::task::JoinError), JoinError(tokio::task::JoinError),
} }
impl std::fmt::Display for CompileError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for CompileError{}
pub async fn compile(config:CompileConfig,mut dom:&mut rbx_dom_weak::WeakDom)->Result<(),CompileError>{ pub async fn compile(config:CompileConfig,mut dom:&mut rbx_dom_weak::WeakDom)->Result<(),CompileError>{
//add in scripts and models //add in scripts and models

View File

@ -43,11 +43,17 @@ enum WriteStackInstruction<'a>{
Destroy(Ref), Destroy(Ref),
} }
enum WriteError{ pub enum WriteError{
ClassNotScript(String), ClassNotScript(String),
IO(std::io::Error), IO(std::io::Error),
EncodeError(rbx_xml::EncodeError), EncodeError(rbx_xml::EncodeError),
} }
impl std::fmt::Display for WriteError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for WriteError{}
fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:PathBuf,node:&TreeNode,node_name_override:String,mut properties:PropertiesOverride,style:Style,write_models:bool,write_scripts:bool)->Result<(),WriteError>{ fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:PathBuf,node:&TreeNode,node_name_override:String,mut properties:PropertiesOverride,style:Style,write_models:bool,write_scripts:bool)->Result<(),WriteError>{
file.push(sanitize(node_name_override.as_str()).as_ref()); file.push(sanitize(node_name_override.as_str()).as_ref());
@ -107,11 +113,11 @@ fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:PathBuf,node:&TreeNode,node_na
} }
pub struct WriteConfig{ pub struct WriteConfig{
style:Style, pub style:Style,
output_folder:PathBuf, pub output_folder:PathBuf,
write_template:bool, pub write_template:bool,
write_models:bool, pub write_models:bool,
write_scripts:bool, pub write_scripts:bool,
} }
pub struct DecompiledContext{ pub struct DecompiledContext{

View File

@ -563,12 +563,12 @@ async fn decompile(config:DecompileConfig)->AResult<()>{
//read file //read file
let dom=load_dom(std::io::BufReader::new(std::fs::File::open(config.input_file)?))?; let dom=load_dom(std::io::BufReader::new(std::fs::File::open(config.input_file)?))?;
let context=rox_compiler::decompile::DecompiledContext::from_dom(dom); let context=rox_compiler::DecompiledContext::from_dom(dom);
//generate folders, models, and scripts //generate folders, models, and scripts
//delete models and scripts from dom //delete models and scripts from dom
context.write_files(WriteConfig{ context.write_files(rox_compiler::WriteConfig{
style:config.style, style:config.style.rox(),
output_folder:config.output_folder, output_folder:config.output_folder,
write_template:config.write_template, write_template:config.write_template,
write_models:config.write_models, write_models:config.write_models,