Projects: Inital support for saving and loading projects #22
|
@ -1,8 +1,10 @@
|
|||
use crate::{gui::{main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
|
||||
use std::fmt::format;
|
||||
|
||||
use crate::{gui::{main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, VRAMInfo};
|
||||
use super::FileTab;
|
||||
use rfd::FileDialog;
|
||||
use slint::SharedString;
|
||||
use tim_tool::logic::tim::types::Encoding;
|
||||
use tim_tool::logic::{project::{Job, Project}, tim::{self, types::Encoding}};
|
||||
use tool_helper::Error;
|
||||
|
||||
pub(super) fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
|
@ -67,11 +69,33 @@ pub(super) fn on_load_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow)
|
|||
|
||||
pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, main_tab, _main_window| {
|
||||
let _tim_info = tim_manager.lock().expect("VRAM already locked").clone_added_tims();
|
||||
let _vram_info = main_tab.clone_vram_info();
|
||||
let tim_info = tim_manager.lock().expect("VRAM already locked").clone_added_tims();
|
||||
let vram_info = main_tab.clone_vram_info();
|
||||
|
||||
if tim_info.len() != vram_info.len() {
|
||||
return Err(Error::from_str("TIM and VRAM info not in sync! Please close program"));
|
||||
}
|
||||
|
||||
Err(Error::not_implemented("on_save_project_clicked"))
|
||||
let mut cur_job = None;
|
||||
let mut project = Project::new(tim_info.into_iter().zip(vram_info.into_iter()).filter_map(|(tim, vram)| {
|
||||
if vram.is_palette {
|
||||
// Add palette to cur_job
|
||||
None
|
||||
}
|
||||
|
||||
else {
|
||||
// We are done with the old job
|
||||
let prev_job = std::mem::replace(&mut cur_job, None);
|
||||
|
||||
cur_job = Some(Job::new("Planschi".to_owned(), std::path::PathBuf::from("value")));
|
||||
prev_job
|
||||
}
|
||||
}).collect());
|
||||
if let Some(cur_job) = cur_job {
|
||||
project.push(cur_job);
|
||||
}
|
||||
|
||||
Err(Error::from_text(format!("Adding {} jobs", project.len())))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
struct Job {
|
||||
pub struct Job {
|
||||
name: String,
|
||||
file_path: PathBuf,
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ impl Job {
|
|||
}
|
||||
}
|
||||
|
||||
struct Project {
|
||||
pub struct Project {
|
||||
jobs: Vec<Job>
|
||||
}
|
||||
|
||||
|
@ -19,4 +19,12 @@ impl Project {
|
|||
pub fn new(jobs: Vec<Job>) -> Project {
|
||||
Project{jobs}
|
||||
}
|
||||
|
||||
pub fn push(&mut self, job: Job) {
|
||||
self.jobs.push(job);
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.jobs.len()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue