From a8ca3bf8592b4efbca87145ccb5ff0f10d2703b0 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 2 Apr 2025 21:14:19 +0200 Subject: [PATCH] Create public function for loading files --- src/Tools/tim_tool/src/gui/file_tab/callbacks.rs | 14 +------------- src/Tools/tim_tool/src/logic/project/mod.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs b/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs index a8808e66..2cfdb929 100644 --- a/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs +++ b/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs @@ -77,19 +77,7 @@ pub(super) fn on_load_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu } for job in new_project.jobs { - let file_path = { - 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 file_path = Job::create_file_path(job.file_path, open_location.as_str()); let (_, _) = tim_manager.load_unadded_tim(&file_path)?; let (pal_width, pal_height) = job.palette_rect.size.into(); diff --git a/src/Tools/tim_tool/src/logic/project/mod.rs b/src/Tools/tim_tool/src/logic/project/mod.rs index 32f7b726..ab120cc1 100644 --- a/src/Tools/tim_tool/src/logic/project/mod.rs +++ b/src/Tools/tim_tool/src/logic/project/mod.rs @@ -75,6 +75,20 @@ impl 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} } + + pub fn create_file_path>(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)]