This commit is contained in:
Piotr Siuszko 2025-09-24 14:27:29 +02:00
parent 176740a36e
commit 63b57ce3eb
5 changed files with 45 additions and 40 deletions

View File

@ -21,6 +21,14 @@ pub struct Spritesheet {
pub atlas_asset_json: Value, pub atlas_asset_json: Value,
} }
impl Spritesheet {
pub fn rebuild_json(&mut self) {
if let Ok(value) = serde_json::to_value(&self.atlas_asset) {
self.atlas_asset_json = value;
}
}
}
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub struct ImageFile { pub struct ImageFile {
pub id: String, pub id: String,

View File

@ -1,10 +1,10 @@
use crossbeam::queue::SegQueue; use crossbeam::queue::SegQueue;
use egui::containers::menu::MenuButton; use egui::containers::menu::MenuButton;
use egui::Grid;
use egui::{ use egui::{
util::undoer::Undoer, Button, Color32, FontFamily, FontId, Frame, Image, Label, Layout, util::undoer::Undoer, Button, Color32, FontFamily, FontId, Frame, Image, Label, Layout,
RichText, Sense, Slider, Ui, RichText, Sense, Slider, Ui,
}; };
use egui::{Grid, Vec2};
use egui_extras::{Column, TableBuilder}; use egui_extras::{Column, TableBuilder};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use rpack_cli::TilemapGenerationConfig; use rpack_cli::TilemapGenerationConfig;
@ -14,7 +14,7 @@ use rpack_cli::{
use texture_packer::{Rect, TexturePackerConfig}; use texture_packer::{Rect, TexturePackerConfig};
use crate::helpers::DroppedFileHelper; use crate::helpers::DroppedFileHelper;
static INPUT_QUEUE: Lazy<SegQueue<AppImageAction>> = Lazy::new(|| SegQueue::new()); static INPUT_QUEUE: Lazy<SegQueue<AppImageAction>> = Lazy::new(SegQueue::new);
pub const MY_ACCENT_COLOR32: Color32 = Color32::from_rgb(230, 102, 1); pub const MY_ACCENT_COLOR32: Color32 = Color32::from_rgb(230, 102, 1);
pub const GIT_HASH: &str = env!("GIT_HASH"); pub const GIT_HASH: &str = env!("GIT_HASH");
pub const VERSION: &str = concat!(" v ", env!("CARGO_PKG_VERSION"), " "); pub const VERSION: &str = concat!(" v ", env!("CARGO_PKG_VERSION"), " ");
@ -476,11 +476,9 @@ impl eframe::App for Application {
); );
ui.with_layout(Layout::right_to_left(egui::Align::Center), |ui| { ui.with_layout(Layout::right_to_left(egui::Align::Center), |ui| {
ui.add_space(10.0); ui.add_space(10.0);
if self.output.is_none() { if self.output.is_none() && ui.add(egui::Button::new("Open")).clicked() {
if ui.add(egui::Button::new("Open")).clicked() {
self.read_files(); self.read_files();
} }
}
if self.output.is_ok() { if self.output.is_ok() {
if ui.add(egui::Button::new("Save atlas image")).clicked() { if ui.add(egui::Button::new("Save atlas image")).clicked() {
if let Err(error) = self.save_atlas() { if let Err(error) = self.save_atlas() {
@ -517,28 +515,24 @@ impl eframe::App for Application {
let Ok(dir) = path.read_dir() else { let Ok(dir) = path.read_dir() else {
continue; continue;
}; };
for entry in dir { for entry in dir.flatten() {
if let Ok(entry) = entry { if let Some(dyn_image) = entry.metadata().ok().and_then(|metadata| {
if let Some(dyn_image) =
entry.metadata().ok().and_then(|metadata| {
if metadata.is_file() { if metadata.is_file() {
entry.create_image("") entry.create_image("")
} else { } else {
None None
} }
}) }) {
{
INPUT_QUEUE.push(AppImageAction::Add(dyn_image)); INPUT_QUEUE.push(AppImageAction::Add(dyn_image));
} }
} }
}
} else { } else {
let Some(path) = &file.path else { let Some(path) = &file.path else {
continue; continue;
}; };
if path.to_string_lossy().ends_with(".rpack_gen.json") { if path.to_string_lossy().ends_with(".rpack_gen.json") {
if let Ok(config) = if let Ok(config) =
rpack_cli::TilemapGenerationConfig::read_from_file(&path) rpack_cli::TilemapGenerationConfig::read_from_file(path)
{ {
INPUT_QUEUE INPUT_QUEUE
.push(AppImageAction::ReadFromConfig(config, path.clone())); .push(AppImageAction::ReadFromConfig(config, path.clone()));
@ -597,17 +591,24 @@ impl eframe::App for Application {
let mut changed = false; let mut changed = false;
Grid::new("settings_grid") Grid::new("settings_grid")
.num_columns(2) .num_columns(2)
.spacing((10.0, 10.0)) .spacing((0.0, 10.0))
.striped(true) .striped(true)
.show(ui, |ui| { .show(ui, |ui| {
ui.style_mut().visuals.faint_bg_color = ui.style_mut().visuals.faint_bg_color =
Color32::from_white_alpha(15); Color32::from_white_alpha(15);
ui.style_mut().interaction.selectable_labels = false; ui.style_mut().interaction.selectable_labels = false;
let id = ui.label("File Name").id; let id = ui.label("File Name").id;
changed |= ui if ui
.text_edit_singleline(&mut self.data.settings.output_path) .text_edit_singleline(&mut self.data.settings.output_path)
.labelled_by(id) .labelled_by(id)
.changed(); .changed()
{
if let SpriteSheetState::Ok(data) = &mut self.output {
data.atlas_asset.filename =
self.data.settings.output_path.clone();
data.rebuild_json();
}
}
ui.end_row(); ui.end_row();
ui.label("Output size"); ui.label("Output size");
let selected_size = match self.data.settings.size { let selected_size = match self.data.settings.size {
@ -639,7 +640,7 @@ impl eframe::App for Application {
false false
}) })
.1 .1
.map_or(false, |s| s.inner); .is_some_and(|s| s.inner);
ui.end_row(); ui.end_row();
changed |= slider_field( changed |= slider_field(
ui, ui,
@ -657,15 +658,20 @@ impl eframe::App for Application {
0..=10, 0..=10,
); );
ui.end_row(); ui.end_row();
let mut serialize_metadata = self let mut skip_metadata = self
.data .data
.settings .settings
.skip_serializing_metadata .skip_serializing_metadata
.unwrap_or_default(); .unwrap_or_default();
ui.label("Skip Metadata Serialization"); ui.label("Skip Metadata Serialization");
if ui.checkbox(&mut serialize_metadata, "").changed() { if ui.checkbox(&mut skip_metadata, "").changed() {
self.data.settings.skip_serializing_metadata = self.data.settings.skip_serializing_metadata =
Some(serialize_metadata); Some(skip_metadata);
if let SpriteSheetState::Ok(data) = &mut self.output {
data.atlas_asset.metadata.skip_serialization =
skip_metadata;
data.rebuild_json();
}
} }
}); });
ui.vertical_centered_justified(|ui| { ui.vertical_centered_justified(|ui| {
@ -902,10 +908,8 @@ impl eframe::App for Application {
let SpriteSheetState::Ok(data) = &self.output else { let SpriteSheetState::Ok(data) = &self.output else {
return; return;
}; };
// ui.add_space(10.0); ui.add(Image::from_uri("bytes://output.png").bg_fill(Color32::from_black_alpha(200)).max_size(Vec2::new(512.0,512.0)));
// ui.heading( ui.separator();
// egui::RichText::new("Created atlas").color(MY_ACCENT_COLOR32),
// );
ui.add_space(10.0); ui.add_space(10.0);
ui.horizontal(|ui|{ ui.horizontal(|ui|{
ui.label(format!( ui.label(format!(
@ -935,10 +939,6 @@ impl eframe::App for Application {
}); });
ui.add_space(10.0);
ui.separator();
ui.add(Image::from_uri("bytes://output.png").bg_fill(Color32::from_black_alpha(200)));
ui.separator();
ui.add_space(20.0); ui.add_space(20.0);
}); });
}); });

View File

@ -111,7 +111,6 @@ fn font_dirs() -> Vec<String> {
.nth(2) .nth(2)
.map(|p| p.join("Resources/fonts").to_string_lossy().into_owned()) .map(|p| p.join("Resources/fonts").to_string_lossy().into_owned())
}) { }) {
eprintln!("{}", &resources_font_dir);
dirs.push(resources_font_dir); dirs.push(resources_font_dir);
} }
} }

View File

@ -80,10 +80,8 @@ impl DroppedFileHelper for DroppedFile {
} }
fn dynamic_image(&self) -> Option<DynamicImage> { fn dynamic_image(&self) -> Option<DynamicImage> {
let bytes = self.bytes.as_ref().clone()?; let bytes = self.bytes.as_ref()?;
ImageImporter::import_from_memory(bytes) ImageImporter::import_from_memory(bytes).ok()
.ok()
.map(|r| r.into())
} }
} }

View File

@ -33,7 +33,7 @@ fn main() -> eframe::Result<()> {
#[cfg(all(not(target_arch = "wasm32"), feature = "profiler"))] #[cfg(all(not(target_arch = "wasm32"), feature = "profiler"))]
start_puffin_server(); start_puffin_server();
let file_arg: Option<String> = if std::env::args().len() > 1 { let file_arg: Option<String> = if std::env::args().len() > 1 {
std::env::args().skip(1).next() std::env::args().nth(1)
} else { } else {
None None
}; };