Create public function for loading files

This commit is contained in:
Jaby 2025-04-02 21:14:19 +02:00
parent ec6c20185e
commit a8ca3bf859
2 changed files with 15 additions and 13 deletions

View File

@ -77,19 +77,7 @@ pub(super) fn on_load_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
} }
for job in new_project.jobs { for job in new_project.jobs {
let file_path = { let file_path = Job::create_file_path(job.file_path, open_location.as_str());
if job.file_path.is_file() {
job.file_path
}
else {
let mut new_file_path = PathBuf::from(open_location.as_str());
new_file_path.pop();
new_file_path.push(job.file_path);
new_file_path
}
};
let (_, _) = tim_manager.load_unadded_tim(&file_path)?; let (_, _) = tim_manager.load_unadded_tim(&file_path)?;
let (pal_width, pal_height) = job.palette_rect.size.into(); let (pal_width, pal_height) = job.palette_rect.size.into();

View File

@ -75,6 +75,20 @@ impl Job {
pub fn new(name: String, file_path: PathBuf, image_pos: (u16, u16), encoding: Encoding) -> Job { pub fn new(name: String, file_path: PathBuf, image_pos: (u16, u16), encoding: Encoding) -> Job {
Job{name, file_path, image_pos: ImagePosition{x: image_pos.0, y: image_pos.1}, palette_rect: PaletteRect::default(), encoding} Job{name, file_path, image_pos: ImagePosition{x: image_pos.0, y: image_pos.1}, palette_rect: PaletteRect::default(), encoding}
} }
pub fn create_file_path<T:?Sized + std::convert::AsRef<std::ffi::OsStr>>(file_path: PathBuf, location_path: &T) -> PathBuf {
if file_path.is_file() {
file_path
}
else {
let mut new_file_path = PathBuf::from(location_path);
new_file_path.pop();
new_file_path.push(file_path);
new_file_path
}
}
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]