From 2345b3da570070d443f7dca36048fcd9173a1d80 Mon Sep 17 00:00:00 2001 From: Jaby Date: Thu, 20 Mar 2025 21:16:41 +0100 Subject: [PATCH] Save encoding information --- src/Tools/tim_tool/src/gui/file_tab/callbacks.rs | 2 +- src/Tools/tim_tool/src/logic/project/mod.rs | 13 +++++++++---- src/Tools/tim_tool/src/logic/tim/types.rs | 13 ++++++++++++- 3 files changed, 22 insertions(+), 6 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 2481c0ce..38e1f532 100644 --- a/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs +++ b/src/Tools/tim_tool/src/gui/file_tab/callbacks.rs @@ -103,7 +103,7 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu if let Some((width, height)) = tim.get_palette_size() { cur_palette = Some(PaletteRect::new(0, 0, width, height)); } - cur_job = Some(Job::new(file_name, tim.get_path(), (vram.x as u16, vram.y as u16))); + cur_job = Some(Job::new(file_name, tim.get_path(), (vram.x as u16, vram.y as u16), Encoding::from_str(vram.encoding_str.as_str()))); } prev_job } diff --git a/src/Tools/tim_tool/src/logic/project/mod.rs b/src/Tools/tim_tool/src/logic/project/mod.rs index 2dca49be..bfaeca04 100644 --- a/src/Tools/tim_tool/src/logic/project/mod.rs +++ b/src/Tools/tim_tool/src/logic/project/mod.rs @@ -1,3 +1,4 @@ +use super::tim::types::Encoding; use serde::{Deserialize, Serialize}; use std::path::PathBuf; @@ -61,16 +62,20 @@ pub struct Job { file_path: PathBuf, image_pos: ImagePosition, palette_rect: PaletteRect, + encoding: Encoding, } impl Job { - pub fn new(name: String, file_path: PathBuf, image_pos: (u16, u16)) -> Job { - Job{name, file_path, image_pos: ImagePosition{x: image_pos.0, y: image_pos.1}, palette_rect: PaletteRect::default()} + 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 add_palette(&mut self, palette_rect: PaletteRect) -> &mut Self { + pub fn add_encoding(&mut self, encoding: Encoding) { + self.encoding = encoding; + } + + pub fn add_palette(&mut self, palette_rect: PaletteRect) { self.palette_rect = palette_rect; - self } } diff --git a/src/Tools/tim_tool/src/logic/tim/types.rs b/src/Tools/tim_tool/src/logic/tim/types.rs index 01ef2f10..8b84f01d 100644 --- a/src/Tools/tim_tool/src/logic/tim/types.rs +++ b/src/Tools/tim_tool/src/logic/tim/types.rs @@ -1,4 +1,6 @@ -#[derive(Clone, Copy)] +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Copy, Deserialize, Serialize)] pub enum Encoding { FourBit, EightBit, @@ -17,4 +19,13 @@ impl Encoding { Encoding::FullColor => Self::FULL_COLOR_NAME, } } + + pub fn from_str(str: &str) -> Encoding { + match str { + Self::FOUR_BIT_NAME => Encoding::FourBit, + Self::EIGHT_BIT_NAME => Encoding::EightBit, + Self::FULL_COLOR_NAME => Encoding::FullColor, + _ => Encoding::FullColor, + } + } } \ No newline at end of file