diff --git a/src/Tools/psxfileconv/Cargo.lock b/src/Tools/psxfileconv/Cargo.lock index e2dd85b3..3cfe647c 100644 --- a/src/Tools/psxfileconv/Cargo.lock +++ b/src/Tools/psxfileconv/Cargo.lock @@ -1195,6 +1195,14 @@ dependencies = [ "syn 2.0.96", ] +[[package]] +name = "cpp_out" +version = "1.0.2" +dependencies = [ + "clap", + "tool_helper", +] + [[package]] name = "cpufeatures" version = "0.2.17" @@ -4065,6 +4073,7 @@ dependencies = [ "bitflags 2.8.0", "cdtypes", "clap", + "cpp_out", "hound", "image 0.24.9", "paste", diff --git a/src/Tools/psxfileconv/Cargo.toml b/src/Tools/psxfileconv/Cargo.toml index b5d4748b..8a0462cd 100644 --- a/src/Tools/psxfileconv/Cargo.toml +++ b/src/Tools/psxfileconv/Cargo.toml @@ -28,6 +28,7 @@ symphonia-vorbis = ["symphonia", "symphonia/vorbis"] [dependencies] bitflags = "2.8.0" cdtypes = {path = "../cdtypes"} +cpp_out = {path = "../cpp_out"} clap = {version = "4.5.27", features = ["derive"]} image = "0.24.9" hound = "3.5.1" diff --git a/src/Tools/psxfileconv/src/lib.rs b/src/Tools/psxfileconv/src/lib.rs index 13baabe6..d7551c11 100644 --- a/src/Tools/psxfileconv/src/lib.rs +++ b/src/Tools/psxfileconv/src/lib.rs @@ -17,7 +17,7 @@ pub enum SubCommands { TIM(tim::Arguments), VAG(vag::Arguments), XA(xa::Arguments), - Project, + Project(project::Arguments), } pub fn run_subcommand(compress_lz4: bool, input_path: Option, output_path: Option, sub_command: SubCommands) -> Result<(), Error> { @@ -41,7 +41,7 @@ pub fn run_subcommand(compress_lz4: bool, input_path: Option, output_pa SubCommands::TIM(args) => tim::convert(args, input, dst_buffer), SubCommands::VAG(args) => audio::vag::convert(args, &output_path, input, dst_buffer), SubCommands::XA(args) => audio::xa::convert(args, input, dst_buffer), - SubCommands::Project => project::run_project(input, input_path, &output_path), + SubCommands::Project(args) => project::run_project(input, args, input_path, &output_path), } }; diff --git a/src/Tools/psxfileconv/src/project/hpp_out.rs b/src/Tools/psxfileconv/src/project/hpp_out.rs new file mode 100644 index 00000000..cf8a3375 --- /dev/null +++ b/src/Tools/psxfileconv/src/project/hpp_out.rs @@ -0,0 +1,39 @@ +use std::path::PathBuf; +use tim_tool::logic::project::Job; +use tool_helper::{Error, Output}; + +pub struct CppHeader { + file_out: Output, +} + +impl CppHeader { + pub fn new(file_path: &Option) -> Result { + let mut file_out = tool_helper::open_output(file_path)?; + + writeln!(file_out, "#pragma once")?; + writeln!(file_out, "#include ")?; + writeln!(file_out, "")?; + + Ok(CppHeader{file_out}) + } + + pub fn push_job(&mut self, job: &Job) -> Result<(), Error> { + let name = job.name.replace('.', "_"); + let (clut_x, clut_y) = if let Some(palette_rect) = &job.palette_rect {(palette_rect.pos.x, palette_rect.pos.y)} else {(0, 0)}; + + writeln!(self.file_out, "namespace {} {{", name)?; + writeln!(self.file_out, "\tusing namespace JabyEngine;")?; + writeln!(self.file_out, "")?; + writeln!(self.file_out, "\tstatic constexpr auto tim = SimpleTIM::create({}, {}, {}, {});", job.image_pos.x, job.image_pos.y, clut_x, clut_y)?; + writeln!(self.file_out, "\tstatic constexpr auto size = GPU::SizeI16::create({}, {});", 0, 0)?; + writeln!(self.file_out, "}}")?; + + Ok(()) + } +} + +impl Drop for CppHeader { + fn drop(&mut self) { + + } +} \ No newline at end of file diff --git a/src/Tools/psxfileconv/src/project/mod.rs b/src/Tools/psxfileconv/src/project/mod.rs index 9d433144..130d43a2 100644 --- a/src/Tools/psxfileconv/src/project/mod.rs +++ b/src/Tools/psxfileconv/src/project/mod.rs @@ -1,9 +1,19 @@ -use crate::images::args::{Arguments, ClutAlignment, ColorType}; +mod hpp_out; + +use crate::images::args::{Arguments as IMGArguments, ClutAlignment, ColorType}; +use clap::Args; +use hpp_out::CppHeader; use std::path::PathBuf; use tool_helper::{Error, Input}; use tim_tool::logic::{tim::types::Encoding, project::*}; -pub fn run_project(input: Input, input_path: Option, output_path: &Option) -> Result<(), Error> { +#[derive(Args)] +pub struct Arguments { + #[clap(long="hpp", value_parser)] + hpp_out_path: Option +} + +pub fn run_project(input: Input, args: Arguments, input_path: Option, output_path: &Option) -> Result<(), Error> { let location_path = if let Some(input_path) = input_path {input_path} else {PathBuf::from(".")}; let output_path = if let Some(output_path) = &output_path { let mut output_path = output_path.clone(); @@ -12,9 +22,12 @@ pub fn run_project(input: Input, input_path: Option, output_path: &Opti } output_path } else {PathBuf::from(".")}; - let project = serde_json::from_reader::(input).map_err(|error|{Error::from_text(format!("Reading project failed: {}", error))})?; + let project = serde_json::from_reader::(input).map_err(|error|{Error::from_text(format!("Reading project failed: {}", error))})?; + let mut hpp_out = CppHeader::new(&args.hpp_out_path)?; for job in project.jobs { + hpp_out.push_job(&job)?; + let args = to_arguments(&job)?; let output_path = { let mut path = output_path.clone(); @@ -26,16 +39,15 @@ pub fn run_project(input: Input, input_path: Option, output_path: &Opti let sub_command = crate::SubCommands::SimpleTIM(args); crate::run_subcommand(job.settings.compress, Some(Job::create_file_path(job.file_path, &location_path)), Some(output_path), sub_command)?; - // Create .cpp file } Ok(()) } -fn to_arguments(job: &Job) -> Result { +fn to_arguments(job: &Job) -> Result { let (semi_transparent, transparent_palette) = get_transparency(&job.settings.transparency); - return Ok(Arguments { + return Ok(IMGArguments { color_depth: get_encoding(&job.settings.encoding), clut_align: get_palette_rect(&job.palette_rect)?, semi_transparent,