Create a simple Job

This commit is contained in:
Jaby 2025-03-19 20:21:45 +01:00
parent b394330405
commit 7a197d9b71
4 changed files with 22 additions and 18 deletions

View File

@ -1,10 +1,8 @@
use std::fmt::format; use crate::{gui::{main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
use crate::{gui::{main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, VRAMInfo};
use super::FileTab; use super::FileTab;
use rfd::FileDialog; use rfd::FileDialog;
use slint::SharedString; use slint::SharedString;
use tim_tool::logic::{project::{Job, Project}, tim::{self, types::Encoding}}; use tim_tool::logic::{project::{Job, Project}, tim::types::Encoding};
use tool_helper::Error; use tool_helper::Error;
pub(super) fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static { pub(super) fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
@ -77,7 +75,7 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
} }
let mut cur_job = None; let mut cur_job = None;
let mut project = Project::new(tim_info.into_iter().zip(vram_info.into_iter()).filter_map(|(tim, vram)| { let mut project = Project::new(tim_info.into_iter().zip(vram_info.into_iter()).filter_map(|(tim, (file_name, vram))| {
if vram.is_palette { if vram.is_palette {
// Add palette to cur_job // Add palette to cur_job
None None
@ -87,7 +85,9 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
// We are done with the old job // We are done with the old job
let prev_job = std::mem::replace(&mut cur_job, None); let prev_job = std::mem::replace(&mut cur_job, None);
cur_job = Some(Job::new("Planschi".to_owned(), std::path::PathBuf::from("value"))); if let Some(tim) = tim {
cur_job = Some(Job::new(file_name, tim.get_path()));
}
prev_job prev_job
} }
}).collect()); }).collect());
@ -95,7 +95,7 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
project.push(cur_job); project.push(cur_job);
} }
Err(Error::from_text(format!("Adding {} jobs", project.len()))) Err(Error::from_text(format!("Adding {:?} jobs", project)))
} }
} }

View File

@ -155,13 +155,11 @@ impl MainTab {
} }
} }
pub fn clone_vram_info(&self) -> Vec<VRAMInfo> { pub fn clone_vram_info(&self) -> Vec<(String, VRAMInfo)> {
let vram_data = self.vram.lock().expect("VRAM already locked"); let vram_data = self.vram.lock().expect("VRAM already locked");
let mut infos = Vec::new();
for vram_data in vram_data.info.iter() { vram_data.info.iter().zip(vram_data.file_list.iter()).map(|(vram_data, file_name)| {
infos.push(vram_data.info.clone()); (file_name.text.to_string(), vram_data.info.clone())
} }).collect()
infos
} }
} }

View File

@ -1,5 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Debug)]
pub struct Job { pub struct Job {
name: String, name: String,
file_path: PathBuf, file_path: PathBuf,
@ -11,6 +12,7 @@ impl Job {
} }
} }
#[derive(Debug)]
pub struct Project { pub struct Project {
jobs: Vec<Job> jobs: Vec<Job>
} }

View File

@ -7,7 +7,7 @@ use types::Encoding;
#[derive(Clone)] #[derive(Clone)]
pub struct TIMInfo { pub struct TIMInfo {
_path: PathBuf, path: PathBuf,
image_data: SharedPixelBuffer<Rgba8Pixel>, image_data: SharedPixelBuffer<Rgba8Pixel>,
palette: Option<PaletteInfo>, palette: Option<PaletteInfo>,
} }
@ -53,7 +53,7 @@ impl TIMInfo {
_ => {return Err(Error::from_str("Only 4 and 8bit color depth are supported for indexed color images"));} _ => {return Err(Error::from_str("Only 4 and 8bit color depth are supported for indexed color images"));}
} }
} }
Ok(TIMInfo{_path: path.clone(), image_data, palette: Some(PaletteInfo::new(palette_colors))}) Ok(TIMInfo{path: path.clone(), image_data, palette: Some(PaletteInfo::new(palette_colors))})
} }
else { else {
@ -71,7 +71,7 @@ impl TIMInfo {
_ => {return Err(Error::from_str("Only 8bit color depth are supported for direct color images"));} _ => {return Err(Error::from_str("Only 8bit color depth are supported for direct color images"));}
} }
} }
Ok(TIMInfo{_path: path.clone(), image_data, palette: None}) Ok(TIMInfo{path: path.clone(), image_data, palette: None})
} }
} }
@ -118,6 +118,10 @@ impl TIMInfo {
None None
}) })
} }
pub fn get_path(&self) -> std::path::PathBuf {
self.path.clone()
}
} }
#[derive(Clone)] #[derive(Clone)]