diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/tscn-to-bsn/src/bin/tscn2bsn.rs | 8 | ||||
| -rw-r--r-- | tools/tscn-to-bsn/src/cmd/cmd_build_cache.rs | 23 | ||||
| -rw-r--r-- | tools/tscn-to-bsn/src/cmd/cmd_convert.rs | 10 | ||||
| -rw-r--r-- | tools/tscn-to-bsn/src/cmd/mod.rs | 14 | ||||
| -rw-r--r-- | tools/tscn-to-bsn/src/lib.rs | 1 | ||||
| -rw-r--r-- | tools/tscn-to-bsn/src/res/gd_proj_dir.rs | 43 | ||||
| -rw-r--r-- | tools/tscn-to-bsn/src/res/mod.rs | 1 |
7 files changed, 92 insertions, 8 deletions
diff --git a/tools/tscn-to-bsn/src/bin/tscn2bsn.rs b/tools/tscn-to-bsn/src/bin/tscn2bsn.rs index 198a5e8..4ac1f5a 100644 --- a/tools/tscn-to-bsn/src/bin/tscn2bsn.rs +++ b/tools/tscn-to-bsn/src/bin/tscn2bsn.rs @@ -1,11 +1,15 @@ use mingling::picker::parselib::{ParserStyle, WINDOWS_STYLE}; -use tscn_to_bsn::{ThisProgram, cmd::cmd_convert::CMDConvert}; +use tscn_to_bsn::ThisProgram; +use tscn_to_bsn::cmd::CommandsSetup; +use tscn_to_bsn::res::gd_proj_dir::GodotProjectSetup; fn main() { let mut program = ThisProgram::new(); ParserStyle::set_global_style(&WINDOWS_STYLE); - program.with_dispatcher(CMDConvert); + program.with_setup(CommandsSetup); + program.with_setup(GodotProjectSetup); + program.exec_and_exit(); } diff --git a/tools/tscn-to-bsn/src/cmd/cmd_build_cache.rs b/tools/tscn-to-bsn/src/cmd/cmd_build_cache.rs new file mode 100644 index 0000000..28e6334 --- /dev/null +++ b/tools/tscn-to-bsn/src/cmd/cmd_build_cache.rs @@ -0,0 +1,23 @@ +use mingling::macros::{buffer, command, empty_result, pack_err, r_println, renderer}; + +use crate::{Next, res::gd_proj_dir::ResGodotProjectDirectory}; + +pack_err!(ErrorGodotProjectNotFound); + +#[command(node = "build-cache")] +pub fn build_cache(proj: &ResGodotProjectDirectory) -> Next { + let Some(ref dir) = proj.dir else { + return ErrorGodotProjectNotFound::default().into(); + }; + + empty_result!() +} + +#[renderer(buffer)] +pub fn render_error_godot_project_not_found(_: ErrorGodotProjectNotFound) { + r_println!("Error: Godot project not found. "); + r_println!(""); + r_println!( + "Please specify the project directory with `/P` or run this command in the project directory!" + ) +} diff --git a/tools/tscn-to-bsn/src/cmd/cmd_convert.rs b/tools/tscn-to-bsn/src/cmd/cmd_convert.rs index efa18b2..a9b16fc 100644 --- a/tools/tscn-to-bsn/src/cmd/cmd_convert.rs +++ b/tools/tscn-to-bsn/src/cmd/cmd_convert.rs @@ -2,13 +2,11 @@ use std::path::PathBuf; use mingling::{ Grouped, Routable, - macros::{arg, buffer, chain, dispatcher, pack_err, r_println, renderer, routeify}, + macros::{arg, buffer, chain, command, pack_err, r_println, renderer, routeify}, picker::{EntryPicker, value::FilePath}, }; -use crate::{Next, gd_res_structure::parse}; - -dispatcher!("convert"); +use crate::{Entry, Next, gd_res_structure::parse}; #[derive(Grouped)] pub struct StateConvert { @@ -25,8 +23,8 @@ pub struct ResultConvertedToRon { pack_err!(ErrorRequirePaths); -#[chain(routeify)] -pub fn handle_convert(args: EntryConvert) -> Next { +#[command(routeify)] +pub fn convert(args: Entry) -> Next { let (tscn_file, output_file) = args .pick_or_route(&arg![input: FilePath, 'I'], || { ErrorRequirePaths::default().into() diff --git a/tools/tscn-to-bsn/src/cmd/mod.rs b/tools/tscn-to-bsn/src/cmd/mod.rs index f488f44..1b0cdcd 100644 --- a/tools/tscn-to-bsn/src/cmd/mod.rs +++ b/tools/tscn-to-bsn/src/cmd/mod.rs @@ -1 +1,15 @@ +use mingling::{Program, macros::program_setup}; + +use crate::{ + ThisProgram, + cmd::{cmd_build_cache::CMDBuildCache, cmd_convert::CMDConvert}, +}; + +pub mod cmd_build_cache; pub mod cmd_convert; + +#[program_setup] +pub fn commands_setup(p: &mut Program<ThisProgram>) { + p.with_dispatcher(CMDConvert); + p.with_dispatcher(CMDBuildCache); +} diff --git a/tools/tscn-to-bsn/src/lib.rs b/tools/tscn-to-bsn/src/lib.rs index faaa93a..d243e10 100644 --- a/tools/tscn-to-bsn/src/lib.rs +++ b/tools/tscn-to-bsn/src/lib.rs @@ -3,5 +3,6 @@ use mingling::macros::gen_program; pub mod cmd; pub mod err; pub mod gd_res_structure; +pub mod res; gen_program!(); diff --git a/tools/tscn-to-bsn/src/res/gd_proj_dir.rs b/tools/tscn-to-bsn/src/res/gd_proj_dir.rs new file mode 100644 index 0000000..30f25a5 --- /dev/null +++ b/tools/tscn-to-bsn/src/res/gd_proj_dir.rs @@ -0,0 +1,43 @@ +use std::{env::current_dir, path::PathBuf}; + +use mingling::{ + Program, + macros::{arg, program_setup}, + picker::{PickerHelper, value::DirPath}, +}; + +use crate::ThisProgram; + +#[derive(Default, Clone)] +pub struct ResGodotProjectDirectory { + pub dir: Option<PathBuf>, +} + +#[program_setup] +pub fn godot_project_setup(p: &mut Program<ThisProgram>) { + let dir = p + .pick_argument(&arg![project_path: Option<DirPath>, 'P']) + .unwrap(); + + if let Some(dir) = dir + && dir.to_path_buf().join("project.godot").exists() + { + p.with_resource(ResGodotProjectDirectory { + dir: Some(dir.to_path_buf()), + }); + return; + } + + let mut cwd = current_dir().unwrap(); + loop { + if cwd.join("project.godot").exists() { + p.with_resource(ResGodotProjectDirectory { dir: Some(cwd) }); + return; + } + if !cwd.pop() { + break; + } + } + + p.with_resource(ResGodotProjectDirectory { dir: None }); +} diff --git a/tools/tscn-to-bsn/src/res/mod.rs b/tools/tscn-to-bsn/src/res/mod.rs new file mode 100644 index 0000000..f3e08a7 --- /dev/null +++ b/tools/tscn-to-bsn/src/res/mod.rs @@ -0,0 +1 @@ +pub mod gd_proj_dir; |
