Skip to content

Commit

Permalink
fix: fix 1st_person path
Browse files Browse the repository at this point in the history
  • Loading branch information
SARDONYX-sard committed Oct 1, 2023
1 parent fd91680 commit 50e5e4c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
20 changes: 14 additions & 6 deletions dar2oar_core/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,25 @@ where
for entry in WalkDir::new(dar_dir) {
let entry = entry?;
let path = entry.path();
let (oar_name_space_path, parsed_mod_name, priority, remain) = match parse_dar_path(&path) {
Ok(data) => data,
Err(_) => continue, // NOTE: The first search is skipped because it does not yet lead to the DAR file.
};
let (oar_name_space_path, is_1st_person, parsed_mod_name, priority, remain) =
match parse_dar_path(&path) {
Ok(data) => data,
Err(_) => continue, // NOTE: The first search is skipped because it does not yet lead to the DAR file.
};
let parsed_mod_name = mod_name
.and_then(|s| Some(s.to_string()))
.unwrap_or(parsed_mod_name.unwrap_or("Unknown".into()));
let oar_name_space_path = oar_dir
.as_ref()
.unwrap_or(&oar_name_space_path)
.to_path_buf()
.and_then(|path| {
Some(match is_1st_person {
true => path.join(
"meshes/actors/character/_1stperson/animations/OpenAnimationReplacer",
),
false => path.join("meshes/actors/character/animations/OpenAnimationReplacer"),
})
})
.unwrap_or(oar_name_space_path)
.join(mod_name.unwrap_or(&parsed_mod_name));

if path.is_dir() {
Expand Down
23 changes: 18 additions & 5 deletions dar2oar_core/src/fs/path_changer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ffi::OsStr;
use std::path::{Path, PathBuf};

/// # Returns
/// oar root path, mod name, priority, non leaf remain(Path excluding file from priority to the end)
/// oar root path, is_1st_person_dir, mod name, priority, non leaf remain(Path excluding file from priority to the end)
///
/// # Errors
/// - If `DynamicAnimationReplacer` is not found in path
Expand All @@ -21,10 +21,21 @@ use std::path::{Path, PathBuf};
/// - "\<ABS or related ParentDir\>/\<ModName\>/_1stperson/character/animations/DynamicAnimationReplacer/_CustomConditions/\<priority\>/_conditions.txt"
pub fn parse_dar_path(
path: impl AsRef<Path>,
) -> Result<(PathBuf, Option<String>, Option<String>, Option<PathBuf>)> {
) -> Result<(
PathBuf,
bool,
Option<String>,
Option<String>,
Option<PathBuf>,
)> {
let path = path.as_ref();
let paths: Vec<&OsStr> = path.iter().collect();

let is_1st_person = path
.iter()
.position(|os_str| os_str == OsStr::new("_1stperson"))
.is_some();

let oar_root = path
.iter()
.position(|os_str| os_str == OsStr::new("DynamicAnimationReplacer"))
Expand Down Expand Up @@ -83,7 +94,7 @@ pub fn parse_dar_path(
})
});

Ok((oar_root, mod_name, priority, non_leaf_remain))
Ok((oar_root, is_1st_person, mod_name, priority, non_leaf_remain))
}

#[cfg(test)]
Expand All @@ -98,14 +109,15 @@ mod test {
let result = parse_dar_path(path);

assert!(result.is_ok());
let (oar_root, mod_name, priority, remain) = result.unwrap();
let (oar_root, is_1st_person, mod_name, priority, remain) = result.unwrap();

assert_eq!(
oar_root,
PathBuf::from(
"../ModName/meshes/actors/character/_1stperson/animations/OpenAnimationReplacer"
)
);
assert_eq!(is_1st_person, true);
assert_eq!(mod_name, Some("ModName".to_string()));
assert_eq!(priority, Some("8107000".to_string()));
assert_eq!(remain, None);
Expand All @@ -117,12 +129,13 @@ mod test {
let result = parse_dar_path(path);

assert!(result.is_ok());
let (oar_root, mod_name, priority, remain) = result.unwrap();
let (oar_root, is_1st_person, mod_name, priority, remain) = result.unwrap();

assert_eq!(
oar_root,
PathBuf::from("../ModName/meshes/actors/character/animations/OpenAnimationReplacer")
);
assert_eq!(is_1st_person, false);
assert_eq!(mod_name, Some("ModName".to_string()));
assert_eq!(priority, Some("8107000".to_string()));
assert_eq!(remain, Some(Path::new("InnerDir").to_path_buf()));
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export function ConvertForm() {
}}
onBlur={onBlur}
error={Boolean(error)}
helperText={error?.message}
helperText={
"Any path under a dir named DynamicAnimationReplacer can be specified."
}
/>
<PathSelector path={value} isDir setValue={setStorage("src")} />
</>
Expand All @@ -121,7 +123,7 @@ export function ConvertForm() {
<>
<TextField
label="OAR(dist) Directory"
placeholder="<MOD NAME>/OpenAnimationReplacer/_CustomCondition/"
placeholder="<MOD NAME>"
value={value}
variant="outlined"
margin="dense"
Expand All @@ -131,7 +133,9 @@ export function ConvertForm() {
}}
onBlur={onBlur}
error={Boolean(error)}
helperText={error?.message}
helperText={
"A dir named meshes/actors/ will be created in the specified directory."
}
/>
<PathSelector path={value} isDir setValue={setStorage("dist")} />
</>
Expand Down Expand Up @@ -159,7 +163,9 @@ export function ConvertForm() {
}}
onBlur={onBlur}
error={Boolean(error)}
helperText={error?.message}
helperText={
"Correspondence path that can change the priority number to your own section name instead of the dir name"
}
/>
<PathSelector path={value} setValue={setStorage("mappingPath")} />
</>
Expand Down

0 comments on commit 50e5e4c

Please sign in to comment.