Compare commits
No commits in common. "a8ca3bf8592b4efbca87145ccb5ff0f10d2703b0" and "2e6aa8dbe96c6720b716a36774b2ac8d3839050c" have entirely different histories.
a8ca3bf859
...
2e6aa8dbe9
|
@ -3150,12 +3150,6 @@ version = "1.0.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pathdiff"
|
|
||||||
version = "0.2.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.1"
|
version = "2.3.1"
|
||||||
|
@ -4117,7 +4111,6 @@ dependencies = [
|
||||||
name = "tim_tool"
|
name = "tim_tool"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pathdiff",
|
|
||||||
"png",
|
"png",
|
||||||
"rfd",
|
"rfd",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -7,13 +7,12 @@ edition = "2021"
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pathdiff = "0.2.3"
|
|
||||||
png = "0.17.16"
|
png = "0.17.16"
|
||||||
rfd = "0.15.2"
|
rfd = "0.15.2"
|
||||||
slint = "1.9.2"
|
slint = "1.9.2"
|
||||||
serde = {version = "1.0.140", features = ["derive"]}
|
|
||||||
serde_json = "1.0"
|
|
||||||
tiny-skia = "0.11.4"
|
tiny-skia = "0.11.4"
|
||||||
|
serde = {version = "1.0.140", features = ["derive"]}
|
||||||
|
serde_json = "1.0"
|
||||||
tool_helper = {path = "../tool_helper"}
|
tool_helper = {path = "../tool_helper"}
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
|
@ -76,21 +76,12 @@ pub(super) fn on_load_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
||||||
main_window.invoke_clear_file_tab_current_selected_file();
|
main_window.invoke_clear_file_tab_current_selected_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
for job in new_project.jobs {
|
for job in new_project.jobs {
|
||||||
let file_path = Job::create_file_path(job.file_path, open_location.as_str());
|
let (_, _) = tim_manager.load_unadded_tim(&job.file_path)?;
|
||||||
let (_, _) = tim_manager.load_unadded_tim(&file_path)?;
|
|
||||||
let (pal_width, pal_height) = job.palette_rect.size.into();
|
let (pal_width, pal_height) = job.palette_rect.size.into();
|
||||||
|
|
||||||
tim_manager.change_unadded_tim_palette_size(pal_width, pal_height)?;
|
tim_manager.change_unadded_tim_palette_size(pal_width, pal_height)?;
|
||||||
let unadded_tim = UnaddedTIM{
|
add_unadded_tim(main_tab, &mut tim_manager, UnaddedTIM::from_job(&job))?;
|
||||||
file_name: &job.name,
|
|
||||||
image_x: job.image_pos.x,
|
|
||||||
image_y: job.image_pos.y,
|
|
||||||
palette_x: job.palette_rect.pos.x,
|
|
||||||
palette_y: job.palette_rect.pos.y,
|
|
||||||
encoding: job.encoding
|
|
||||||
};
|
|
||||||
add_unadded_tim(main_tab, &mut tim_manager, unadded_tim)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main_window.invoke_change_to_main();
|
main_window.invoke_change_to_main();
|
||||||
|
@ -105,9 +96,8 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
||||||
return Err(Error::from_str("Please specify save location for project file"));
|
return Err(Error::from_str("Please specify save location for project file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let tim_info = tim_manager.lock().expect("VRAM already locked").clone_added_tims();
|
let tim_info = tim_manager.lock().expect("VRAM already locked").clone_added_tims();
|
||||||
let vram_info = main_tab.clone_vram_info();
|
let vram_info = main_tab.clone_vram_info();
|
||||||
let use_rel_path = main_window.get_project_widget_use_rel_paths();
|
|
||||||
|
|
||||||
if tim_info.len() != vram_info.len() {
|
if tim_info.len() != vram_info.len() {
|
||||||
return Err(Error::from_str("TIM and VRAM info not in sync! Please close program"));
|
return Err(Error::from_str("TIM and VRAM info not in sync! Please close program"));
|
||||||
|
@ -115,12 +105,7 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
||||||
|
|
||||||
let mut cur_job:Option<Job> = None;
|
let mut cur_job:Option<Job> = None;
|
||||||
let mut cur_palette:Option<PaletteRect> = None;
|
let mut cur_palette:Option<PaletteRect> = None;
|
||||||
let mut map_result = Ok(());
|
let mut project = Project::new(tim_info.into_iter().zip(vram_info.into_iter()).filter_map(|(tim, (file_name, vram))| {
|
||||||
let mut project = Project::new(tim_info.into_iter().zip(vram_info.into_iter()).filter_map(|(tim, (name, vram))| {
|
|
||||||
if map_result.is_err() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
if vram.is_palette {
|
if vram.is_palette {
|
||||||
let cur_palette = std::mem::replace(&mut cur_palette, None);
|
let cur_palette = std::mem::replace(&mut cur_palette, None);
|
||||||
if let Some(mut cur_palette) = cur_palette {
|
if let Some(mut cur_palette) = cur_palette {
|
||||||
|
@ -140,22 +125,11 @@ 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));
|
||||||
}
|
}
|
||||||
let file_path = if use_rel_path {
|
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())));
|
||||||
match tim.get_path_rel_to(PathBuf::from(save_location.as_str())) {
|
|
||||||
Ok(file_path) => file_path,
|
|
||||||
Err(error) => {
|
|
||||||
map_result = Err(error);
|
|
||||||
PathBuf::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {tim.get_path()};
|
|
||||||
cur_job = Some(Job::new(name, file_path, (vram.x as u16, vram.y as u16), Encoding::from_str(vram.encoding_str.as_str())));
|
|
||||||
}
|
}
|
||||||
prev_job
|
prev_job
|
||||||
}
|
}
|
||||||
}).collect());
|
}).collect());
|
||||||
map_result?;
|
|
||||||
|
|
||||||
if let Some(cur_job) = cur_job {
|
if let Some(cur_job) = cur_job {
|
||||||
project.jobs.push(cur_job);
|
project.jobs.push(cur_job);
|
||||||
}
|
}
|
||||||
|
@ -218,6 +192,10 @@ impl<'a> UnaddedTIM<'a> {
|
||||||
pub fn new(file_name: &String, encoding: Encoding,) -> UnaddedTIM {
|
pub fn new(file_name: &String, encoding: Encoding,) -> UnaddedTIM {
|
||||||
UnaddedTIM{file_name, image_x: 0, image_y: 0, palette_x: 0, palette_y: 0, encoding}
|
UnaddedTIM{file_name, image_x: 0, image_y: 0, palette_x: 0, palette_y: 0, encoding}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_job(job: &Job) -> UnaddedTIM {
|
||||||
|
UnaddedTIM{file_name: &job.name, image_x: job.image_pos.x, image_y: job.image_pos.y, palette_x: job.palette_rect.pos.x, palette_y: job.palette_rect.pos.y, encoding: job.encoding }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_unadded_tim(main_tab: &mut MainTab, tim_manager: &mut TIMManager, unadded_tim: UnaddedTIM) -> Result<(), Error> {
|
fn add_unadded_tim(main_tab: &mut MainTab, tim_manager: &mut TIMManager, unadded_tim: UnaddedTIM) -> Result<(), Error> {
|
||||||
|
|
|
@ -75,20 +75,6 @@ impl Job {
|
||||||
pub fn new(name: String, file_path: PathBuf, image_pos: (u16, u16), encoding: Encoding) -> 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}
|
Job{name, file_path, image_pos: ImagePosition{x: image_pos.0, y: image_pos.1}, palette_rect: PaletteRect::default(), 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)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
use pathdiff::diff_paths;
|
|
||||||
use std::{fs::File, path::PathBuf};
|
use std::{fs::File, path::PathBuf};
|
||||||
use slint::{Rgba8Pixel, SharedPixelBuffer};
|
use slint::{Rgba8Pixel, SharedPixelBuffer};
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
|
@ -20,8 +19,8 @@ impl TIMInfo {
|
||||||
*iter.next()?, *iter.next()?, *iter.next()?,
|
*iter.next()?, *iter.next()?, *iter.next()?,
|
||||||
if load_alpha {*iter.next()?} else {0xFF}))
|
if load_alpha {*iter.next()?} else {0xFF}))
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut reader = png::Decoder::new(File::open(path).map_err(|error| Error::from_text(format!("Failed loading \"{}\" with {}", path.to_string_lossy().as_ref(), error)))?).read_info().or_else(|error| {Err(Error::from_error(error))})?;
|
let mut reader = png::Decoder::new(File::open(path)?).read_info().or_else(|error| {Err(Error::from_error(error))})?;
|
||||||
let info = reader.info().clone();
|
let info = reader.info().clone();
|
||||||
|
|
||||||
let mut buffer = vec![0; reader.output_buffer_size()];
|
let mut buffer = vec![0; reader.output_buffer_size()];
|
||||||
|
@ -133,15 +132,6 @@ impl TIMInfo {
|
||||||
pub fn get_path(&self) -> std::path::PathBuf {
|
pub fn get_path(&self) -> std::path::PathBuf {
|
||||||
self.path.clone()
|
self.path.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_path_rel_to(&self, mut reference_path: std::path::PathBuf) -> Result<std::path::PathBuf, Error> {
|
|
||||||
let file_path = self.path.clone();
|
|
||||||
|
|
||||||
reference_path.pop();
|
|
||||||
diff_paths(&file_path, &reference_path).ok_or_else(|| {
|
|
||||||
Error::from_text(format!("Can not create relative path from {} to {}", file_path.to_string_lossy().as_ref(), reference_path.to_string_lossy().as_ref()))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
@ -44,8 +44,10 @@ component ProjectWidget inherits Rectangle {
|
||||||
HorizontalLayout {
|
HorizontalLayout {
|
||||||
alignment: start;
|
alignment: start;
|
||||||
CheckBox {
|
CheckBox {
|
||||||
text: "Append elements from project to existing elements";
|
text: "Append elements from project to existing elements";
|
||||||
checked <=> root.append_project_elements;
|
toggled() => {
|
||||||
|
root.append_project_elements = self.checked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HorizontalLayout {
|
HorizontalLayout {
|
||||||
|
@ -81,8 +83,8 @@ component ProjectWidget inherits Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CheckBox {
|
CheckBox {
|
||||||
text: "Use relative path for files";
|
text: "Use relative path for files";
|
||||||
checked <=> root.use_rel_paths;
|
checked: root.use_rel_paths;
|
||||||
}
|
}
|
||||||
HorizontalLayout {
|
HorizontalLayout {
|
||||||
alignment: start;
|
alignment: start;
|
||||||
|
|
Loading…
Reference in New Issue