Projects: Inital support for saving and loading projects #22

Merged
cody merged 17 commits from topic/jb/project-files into main 2025-04-05 19:56:33 +00:00
3 changed files with 22 additions and 6 deletions
Showing only changes of commit 2345b3da57 - Show all commits

View File

@ -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() { if let Some((width, height)) = tim.get_palette_size() {
cur_palette = Some(PaletteRect::new(0, 0, width, height)); 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 prev_job
} }

View File

@ -1,3 +1,4 @@
use super::tim::types::Encoding;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;
@ -61,16 +62,20 @@ pub struct Job {
file_path: PathBuf, file_path: PathBuf,
image_pos: ImagePosition, image_pos: ImagePosition,
palette_rect: PaletteRect, palette_rect: PaletteRect,
encoding: Encoding,
} }
impl Job { impl Job {
pub fn new(name: String, file_path: PathBuf, image_pos: (u16, u16)) -> 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()} 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.palette_rect = palette_rect;
self
} }
} }

View File

@ -1,4 +1,6 @@
#[derive(Clone, Copy)] use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Deserialize, Serialize)]
pub enum Encoding { pub enum Encoding {
FourBit, FourBit,
EightBit, EightBit,
@ -17,4 +19,13 @@ impl Encoding {
Encoding::FullColor => Self::FULL_COLOR_NAME, 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,
}
}
} }