diff --git a/rox_compiler/src/compile.rs b/rox_compiler/src/compile.rs index 7fccd1a..9b3a666 100644 --- a/rox_compiler/src/compile.rs +++ b/rox_compiler/src/compile.rs @@ -2,8 +2,7 @@ use std::path::PathBuf; use futures::{StreamExt, TryStreamExt}; use tokio::io::AsyncReadExt; -use crate::types::{Style,PropertiesOverride}; -use crate::common::sanitize; +use crate::common::{sanitize,Style,PropertiesOverride}; //holy smokes what am I doing lmao //This giant machine is supposed to search for files according to style rules @@ -190,6 +189,12 @@ struct ScriptWithOverrides{ pub enum ScriptWithOverridesError{ 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{ fn from_source(mut source:String)->Result{ @@ -240,6 +245,12 @@ enum CompileNodeError{ }, 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{ Model, @@ -407,6 +418,12 @@ pub enum CompileError{ DecodeError(rbx_xml::DecodeError), 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>{ //add in scripts and models diff --git a/rox_compiler/src/decompile.rs b/rox_compiler/src/decompile.rs index 30ac076..8ec6148 100644 --- a/rox_compiler/src/decompile.rs +++ b/rox_compiler/src/decompile.rs @@ -43,11 +43,17 @@ enum WriteStackInstruction<'a>{ Destroy(Ref), } -enum WriteError{ +pub enum WriteError{ ClassNotScript(String), IO(std::io::Error), 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>{ 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{ - style:Style, - output_folder:PathBuf, - write_template:bool, - write_models:bool, - write_scripts:bool, + pub style:Style, + pub output_folder:PathBuf, + pub write_template:bool, + pub write_models:bool, + pub write_scripts:bool, } pub struct DecompiledContext{ diff --git a/src/main.rs b/src/main.rs index aff51d0..1beffd3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -563,12 +563,12 @@ async fn decompile(config:DecompileConfig)->AResult<()>{ //read 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 //delete models and scripts from dom - context.write_files(WriteConfig{ - style:config.style, + context.write_files(rox_compiler::WriteConfig{ + style:config.style.rox(), output_folder:config.output_folder, write_template:config.write_template, write_models:config.write_models,