Support creating hpp file

This commit is contained in:
Jaby 2025-04-16 20:42:51 +02:00
parent 4ea7575057
commit e51908ae09
5 changed files with 69 additions and 8 deletions

View File

@ -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",

View File

@ -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"

View File

@ -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<PathBuf>, output_path: Option<PathBuf>, sub_command: SubCommands) -> Result<(), Error> {
@ -41,7 +41,7 @@ pub fn run_subcommand(compress_lz4: bool, input_path: Option<PathBuf>, 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),
}
};

View File

@ -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<PathBuf>) -> Result<CppHeader, Error> {
let mut file_out = tool_helper::open_output(file_path)?;
writeln!(file_out, "#pragma once")?;
writeln!(file_out, "#include <PSX/File/cd_file_types.hpp>")?;
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) {
}
}

View File

@ -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<PathBuf>, output_path: &Option<PathBuf>) -> Result<(), Error> {
#[derive(Args)]
pub struct Arguments {
#[clap(long="hpp", value_parser)]
hpp_out_path: Option<PathBuf>
}
pub fn run_project(input: Input, args: Arguments, input_path: Option<PathBuf>, output_path: &Option<PathBuf>) -> 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<PathBuf>, output_path: &Opti
}
output_path
} else {PathBuf::from(".")};
let project = serde_json::from_reader::<Input, Project>(input).map_err(|error|{Error::from_text(format!("Reading project failed: {}", error))})?;
let project = serde_json::from_reader::<Input, Project>(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<PathBuf>, 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<Arguments, Error> {
fn to_arguments(job: &Job) -> Result<IMGArguments, Error> {
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,