Compare commits
No commits in common. "5cc88e0b87f0c54e95fd7ec9e9f1f5103525e9a8" and "aae57e47e40a22e325ecbfc88744e2215b7403f1" have entirely different histories.
5cc88e0b87
...
aae57e47e4
|
@ -1,10 +1,10 @@
|
|||
use std::{fs::File, io::Write, path::PathBuf};
|
||||
use std::{fs::File, io::Write};
|
||||
|
||||
use crate::{gui::{self, main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
|
||||
use super::FileTab;
|
||||
use rfd::FileDialog;
|
||||
use slint::SharedString;
|
||||
use tim_tool::logic::{project::{ImagePosition, Job, PaletteRect, Project}, tim::types::Encoding};
|
||||
use tim_tool::logic::{project::{Job, PaletteRect, Project}, tim::types::Encoding};
|
||||
use tool_helper::Error;
|
||||
|
||||
pub(super) fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
|
@ -62,21 +62,8 @@ pub(super) fn on_add_image(tim_manager: MutexTIMManager) -> impl FnMut(&mut File
|
|||
}
|
||||
|
||||
pub(super) fn on_load_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, main_window| {
|
||||
let open_location = main_window.get_project_widget_open_project_path();
|
||||
if open_location.is_empty() {
|
||||
return Err(Error::from_str("Please specify location for project file to open"));
|
||||
}
|
||||
|
||||
let file_content = tool_helper::read_file_to_string(&PathBuf::from(open_location.as_str()))?;
|
||||
let _new_project = match serde_json::from_str::<Project>(&file_content) {
|
||||
Ok(project) => project,
|
||||
Err(error) => {
|
||||
return Err(Error::from_error(error));
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
move |_file_tab, _main_window| {
|
||||
Err(Error::not_implemented("on_load_project_clicked"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,17 +81,10 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
|||
return Err(Error::from_str("TIM and VRAM info not in sync! Please close program"));
|
||||
}
|
||||
|
||||
let mut cur_job:Option<Job> = None;
|
||||
let mut cur_palette:Option<PaletteRect> = None;
|
||||
let mut cur_job = None;
|
||||
let mut project = Project::new(tim_info.into_iter().zip(vram_info.into_iter()).filter_map(|(tim, (file_name, vram))| {
|
||||
if vram.is_palette {
|
||||
let cur_palette = std::mem::replace(&mut cur_palette, None);
|
||||
if let Some(mut cur_palette) = cur_palette {
|
||||
cur_palette.pos = ImagePosition::new(vram.x as u16, vram.y as u16);
|
||||
if let Some(cur_job) = &mut cur_job {
|
||||
cur_job.add_palette(cur_palette);
|
||||
}
|
||||
}
|
||||
// Add palette to cur_job
|
||||
None
|
||||
}
|
||||
|
||||
|
@ -113,10 +93,12 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
|||
let prev_job = std::mem::replace(&mut cur_job, None);
|
||||
|
||||
if let Some(tim) = tim {
|
||||
let mut job = Job::new(file_name, tim.get_path(), (vram.x as u16, vram.y as u16));
|
||||
|
||||
if let Some((width, height)) = tim.get_palette_size() {
|
||||
cur_palette = Some(PaletteRect::new(0, 0, width, height));
|
||||
job.add_palette(PaletteRect::new(0, 0, width, height));
|
||||
}
|
||||
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())));
|
||||
cur_job = Some(job);
|
||||
}
|
||||
prev_job
|
||||
}
|
||||
|
@ -141,23 +123,17 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
|||
}
|
||||
|
||||
pub(super) fn on_browse_open_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, main_window| {
|
||||
let file_path = create_project_file_dialog()
|
||||
.set_title("Save location for TIM project file")
|
||||
.pick_file();
|
||||
|
||||
if let Some(file_path) = file_path {
|
||||
if let Some(file_path) = file_path.to_str() {
|
||||
main_window.set_project_widget_open_project_path(SharedString::from(file_path));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
move |_file_tab, _main_window| {
|
||||
Err(Error::not_implemented("on_browse_open_project_clicked"))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_browse_save_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, main_window| {
|
||||
let file_path = create_project_file_dialog()
|
||||
let file_path = FileDialog::new()
|
||||
.add_filter("TIM project file (.tim_project)", &["tim_project"])
|
||||
.add_filter("JSON file (.json; .jsn)", &["json", "jsn"])
|
||||
.add_filter("All", &["*"])
|
||||
.set_title("Save location for TIM project file")
|
||||
.save_file();
|
||||
|
||||
|
@ -169,10 +145,3 @@ pub(super) fn on_browse_save_project_clicked() -> impl FnMut(&mut FileTab, &Main
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn create_project_file_dialog() -> FileDialog {
|
||||
FileDialog::new()
|
||||
.add_filter("TIM project file (.tim_project)", &["tim_project"])
|
||||
.add_filter("JSON file (.json; .jsn)", &["json", "jsn"])
|
||||
.add_filter("All", &["*"])
|
||||
}
|
|
@ -1,47 +1,34 @@
|
|||
use super::tim::types::Encoding;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ImagePosition {
|
||||
struct ImagePosition {
|
||||
pub x: u16,
|
||||
pub y: u16,
|
||||
}
|
||||
|
||||
impl ImagePosition {
|
||||
pub fn new(x: u16, y: u16) -> ImagePosition {
|
||||
ImagePosition{x, y}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for ImagePosition {
|
||||
fn default() -> Self {
|
||||
ImagePosition::new(0, 0)
|
||||
ImagePosition{x: 0, y: 0}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ImageSize {
|
||||
struct ImageSize {
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
}
|
||||
|
||||
impl ImageSize {
|
||||
pub fn new(width: u16, height: u16) -> ImageSize {
|
||||
ImageSize{width, height}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for ImageSize {
|
||||
fn default() -> Self {
|
||||
ImageSize::new(0, 0)
|
||||
ImageSize{width: 0, height: 0}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct PaletteRect {
|
||||
pub pos: ImagePosition,
|
||||
pub size: ImageSize,
|
||||
pos: ImagePosition,
|
||||
size: ImageSize,
|
||||
}
|
||||
|
||||
impl PaletteRect {
|
||||
|
@ -62,20 +49,16 @@ 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), 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 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 add_encoding(&mut self, encoding: Encoding) {
|
||||
self.encoding = encoding;
|
||||
}
|
||||
|
||||
pub fn add_palette(&mut self, palette_rect: PaletteRect) {
|
||||
pub fn add_palette(&mut self, palette_rect: PaletteRect) -> &mut Self {
|
||||
self.palette_rect = palette_rect;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Deserialize, Serialize)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum Encoding {
|
||||
FourBit,
|
||||
EightBit,
|
||||
|
@ -19,13 +17,4 @@ 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,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue