diff --git a/README.md b/README.md index 6d1bd82..0c92e69 100644 --- a/README.md +++ b/README.md @@ -37,15 +37,26 @@ DAR to OAR Converter CLI Usage: dar2oar.exe [OPTIONS] --src Options: - --src DAR source dir path - --dist OAR destination dir path(If not, it is inferred from src) - --name mod name in config.json & folder name(If not, it is inferred from src) - --author mod author in config.json - --mapping-file path to section name table - --log-level log_level trace | debug | info | warn | error [default: error] - --log-path [default: ./convert.log] - -h, --help Print help - -V, --version Print version + --src + DAR source dir path + --dist + OAR destination dir path(If not, it is inferred from src) + --name + mod name in config.json & folder name(If not, it is inferred from src) + --author + mod author in config.json + --mapping-file + path to section name table + --mapping-1person-file + path to section name table(For _1st_person) + --log-level + log_level trace | debug | info | warn | error [default: error] + --log-path + [default: ./convert.log] + -h, --help + Print help + -V, --version + Print version ``` ## What is the mapping file? @@ -64,6 +75,7 @@ Sample 8000000 Combat 8000001 8000002 +// This is a line comment. // to line breaks are ignored. 8000005 8000005 Female 8001000 diff --git a/dar2oar_cli/src/lib.rs b/dar2oar_cli/src/lib.rs index e36b465..f737976 100644 --- a/dar2oar_cli/src/lib.rs +++ b/dar2oar_cli/src/lib.rs @@ -21,6 +21,9 @@ pub struct Args { /// path to section name table #[arg(long)] mapping_file: Option, + /// path to section name table(For _1st_person) + #[arg(long)] + mapping_1person_file: Option, /// log_level trace | debug | info | warn | error #[arg(long, default_value = "error")] log_level: String, @@ -49,12 +52,21 @@ pub fn run_cli(args: Args) -> anyhow::Result<()> { None => None, }; + let table_1person = match args.mapping_1person_file { + Some(table_path) => { + let mapping = read_mapping_table(table_path)?; + Some(mapping) + } + None => None, + }; + convert_dar_to_oar( args.src, dist, args.name.as_deref(), args.author.as_deref(), table, + table_1person )?; Ok(()) } diff --git a/dar2oar_core/src/fs/mapping_table.rs b/dar2oar_core/src/fs/mapping_table.rs index 9be037b..9440cfb 100644 --- a/dar2oar_core/src/fs/mapping_table.rs +++ b/dar2oar_core/src/fs/mapping_table.rs @@ -22,6 +22,10 @@ fn parse_mapping_table(table: &str) -> HashMap { let mut current_section_name = String::new(); let mut idx = 0; for line in table.lines() { + if line.starts_with("//") { + continue; + }; + let mapping: Vec<&str> = line.split_whitespace().collect(); let section_name = match mapping.get(1) { Some(val) => { @@ -55,6 +59,7 @@ mod tests { 8000000 Combat 8000001 8000001 Base +// This is a line comment 8000002 8000005 8000005 Female diff --git a/dar2oar_core/src/fs/mod.rs b/dar2oar_core/src/fs/mod.rs index f8cbb88..f078c27 100644 --- a/dar2oar_core/src/fs/mod.rs +++ b/dar2oar_core/src/fs/mod.rs @@ -72,6 +72,7 @@ pub fn convert_dar_to_oar

( mod_name: Option<&str>, author: Option<&str>, section_table: Option>, + section_1person_table: Option>, ) -> Result<()> where P: AsRef, @@ -115,10 +116,13 @@ where // For this reason, an empty string should be put in the name space folder. let priority = &priority.unwrap_or_default(); - let section_name = section_table - .as_ref() - .and_then(|table| table.get(priority)) - .unwrap_or(priority); + let section_name = match is_1st_person { + true => section_1person_table + .as_ref() + .and_then(|table| table.get(priority)), + false => section_table.as_ref().and_then(|table| table.get(priority)), + } + .unwrap_or(priority); let section_root = oar_name_space_path.join(section_name); log::trace!("section root: {:?}", section_root); @@ -189,6 +193,7 @@ mod test { None, None, Some(mapping), + None, ) } } diff --git a/frontend/src/components/form.tsx b/frontend/src/components/form.tsx index 6e52d05..457f334 100644 --- a/frontend/src/components/form.tsx +++ b/frontend/src/components/form.tsx @@ -15,6 +15,7 @@ type FormProps = { modName: string; modAuthor: string; mappingPath: string; + mapping1personPath: string; logLevel: LogLevel; loading: boolean; }; @@ -43,6 +44,7 @@ export function ConvertForm() { modName: localStorage.getItem("modName") ?? "", modAuthor: localStorage.getItem("modAuthor") ?? "", mappingPath: localStorage.getItem("mappingPath") ?? "", + mapping1personPath: localStorage.getItem("mapping1personPath") ?? "", logLevel: tryGetLogLevel(), loading: false as boolean, } satisfies FormProps, @@ -65,15 +67,21 @@ export function ConvertForm() { modName, modAuthor, mappingPath, + mapping1personPath, }) => { setLoading(true); - await convertDar2oar({ src, dist, modName, modAuthor, mappingPath }).catch( - (e) => { - toast.error(`${e}`); - setLoading(false); - } - ); + await convertDar2oar({ + src, + dist, + modName, + modAuthor, + mappingPath, + mapping1personPath, + }).catch((e) => { + toast.error(`${e}`); + setLoading(false); + }); setLoading(false); }; @@ -153,7 +161,7 @@ export function ConvertForm() { + ( + <> + { + localStorage.setItem("mapping1personPath", e.target.value); + onChange(e); + }} + onBlur={onBlur} + error={Boolean(error)} + helperText={ + "Correspondence path that can change the priority number to your own section name instead of the dir name" + } + /> + + + )} + /> + { modName, modAuthor, mappingPath: props.mappingPath, + mapping1personPath: props.mapping1personPath, logLevel: props.logLevel, }); } catch (e) { diff --git a/src-tauri/src/cmd.rs b/src-tauri/src/cmd.rs index 0e18be3..1caf721 100644 --- a/src-tauri/src/cmd.rs +++ b/src-tauri/src/cmd.rs @@ -8,6 +8,7 @@ pub fn convert_dar2oar( mod_name: Option<&str>, mod_author: Option<&str>, mapping_path: Option, + mapping_1person_path: Option, log_level: Option, ) -> Result<(), String> { let dist = oar_mod_folder.and_then(|dist| match dist.is_empty() { @@ -24,6 +25,16 @@ pub fn convert_dar2oar( } None => None, }; + let table_1person = match mapping_1person_path { + Some(ref table_path) => { + let mapping = match read_mapping_table(table_path) { + Ok(table) => table, + Err(err) => return Err(err.to_string()), + }; + Some(mapping) + } + None => None, + }; let log_level = match log_level { Some(level) => match level.as_str() { @@ -38,6 +49,7 @@ pub fn convert_dar2oar( log::debug!("mod_name: {:?}", mod_name); log::debug!("mod_author: {:?}", mod_author); log::debug!("table path: {:?}", mapping_path.as_ref()); + log::debug!("1st person table path: {:?}", mapping_1person_path.as_ref()); log::debug!("log level: {:?}", log_level.as_str()); match convert_dar_to_oar( @@ -46,6 +58,7 @@ pub fn convert_dar2oar( mod_name.as_deref(), mod_author.as_deref(), table, + table_1person, ) { Ok(_) => Ok(()), Err(err) => return Err(err.to_string()), diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 6ee0e1a..3e6087f 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -74,7 +74,7 @@ "windows": [ { "fullscreen": false, - "height": 750, + "height": 850, "resizable": true, "theme": "Dark", "title": "DAR to OAR Converter",