Move primitives around

This commit is contained in:
Jaby 2025-04-05 23:19:06 +02:00 committed by cody
parent 5a1997873d
commit 751533dcf6
1 changed files with 40 additions and 40 deletions

View File

@ -2,6 +2,46 @@ use super::tim::types::Encoding;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Serialize, Deserialize)]
pub struct Job {
pub name: String,
pub file_path: PathBuf,
pub image_pos: ImagePosition,
pub palette_rect: Option<PaletteRect>,
pub 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: None, encoding}
}
pub fn create_file_path<T:?Sized + std::convert::AsRef<std::ffi::OsStr>>(file_path: PathBuf, location_path: &T) -> PathBuf {
if file_path.is_file() {
file_path
}
else {
let mut new_file_path = PathBuf::from(location_path);
new_file_path.pop();
new_file_path.push(file_path);
new_file_path
}
}
}
#[derive(Serialize, Deserialize)]
pub struct Project {
pub jobs: Vec<Job>
}
impl Project {
pub fn new(jobs: Vec<Job>) -> Project {
Project{jobs}
}
}
#[derive(Serialize, Deserialize)]
pub struct ImagePosition {
pub x: u16,
@ -67,43 +107,3 @@ impl std::default::Default for PaletteRect {
PaletteRect{pos: ImagePosition::default(), size: ImageSize::default()}
}
}
#[derive(Serialize, Deserialize)]
pub struct Job {
pub name: String,
pub file_path: PathBuf,
pub image_pos: ImagePosition,
pub palette_rect: Option<PaletteRect>,
pub 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: None, encoding}
}
pub fn create_file_path<T:?Sized + std::convert::AsRef<std::ffi::OsStr>>(file_path: PathBuf, location_path: &T) -> PathBuf {
if file_path.is_file() {
file_path
}
else {
let mut new_file_path = PathBuf::from(location_path);
new_file_path.pop();
new_file_path.push(file_path);
new_file_path
}
}
}
#[derive(Serialize, Deserialize)]
pub struct Project {
pub jobs: Vec<Job>
}
impl Project {
pub fn new(jobs: Vec<Job>) -> Project {
Project{jobs}
}
}