| 1 | //! Desktop shell for Paperdoll Renderer project files. |
| 2 | //! |
| 3 | //! The window edits a `.ppd` project and shows a live skinned glTF preview. |
| 4 | |
| 5 | use std::process::ExitCode; |
| 6 | |
| 7 | use paperdoll_renderer::editor::EditorApp; |
| 8 | use paperdoll_renderer::foundation::{help_text, parse_cli, report, CliError, CliRequest}; |
| 9 | |
| 10 | fn main() -> ExitCode { |
| 11 | let args: Vec<String> = std::env::args().skip(1).collect(); |
| 12 | let borrowed: Vec<&str> = args.iter().map(String::as_str).collect(); |
| 13 | match parse_cli(borrowed) { |
| 14 | Ok(CliRequest::PrintHelp) => { |
| 15 | println!("{}", help_text()); |
| 16 | ExitCode::SUCCESS |
| 17 | } |
| 18 | Ok(CliRequest::PrintStatus) => { |
| 19 | println!("{}", report()); |
| 20 | ExitCode::SUCCESS |
| 21 | } |
| 22 | Ok(CliRequest::PreviewFixtures) => open_window(true), |
| 23 | Ok(CliRequest::OpenWindow) => open_window(false), |
| 24 | Err(CliError::UnknownArgument(arg)) => { |
| 25 | eprintln!("paperdoll-renderer: onbekend argument '{arg}'."); |
| 26 | eprintln!("Gebruik --help."); |
| 27 | ExitCode::from(2) |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | fn open_window(fixtures: bool) -> ExitCode { |
| 33 | if let Some(message) = window_preflight() { |
| 34 | eprintln!("paperdoll-renderer: {message}"); |
| 35 | return ExitCode::from(1); |
| 36 | } |
| 37 | match run_window(fixtures) { |
| 38 | Ok(()) => ExitCode::SUCCESS, |
| 39 | Err(err) => { |
| 40 | eprintln!("paperdoll-renderer: het venster openen is mislukt: {err}"); |
| 41 | ExitCode::from(1) |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | fn window_preflight() -> Option<String> { |
| 47 | #[cfg(target_os = "linux")] |
| 48 | { |
| 49 | let missing = paperdoll_renderer::foundation::missing_window_libraries(); |
| 50 | if missing.is_empty() { |
| 51 | None |
| 52 | } else { |
| 53 | Some(paperdoll_renderer::foundation::missing_library_message( |
| 54 | &missing, |
| 55 | )) |
| 56 | } |
| 57 | } |
| 58 | #[cfg(not(target_os = "linux"))] |
| 59 | { |
| 60 | None |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | fn run_window(fixtures: bool) -> eframe::Result<()> { |
| 65 | let options = eframe::NativeOptions { |
| 66 | viewport: eframe::egui::ViewportBuilder::default() |
| 67 | .with_title("Paperdoll Renderer") |
| 68 | .with_inner_size([1180.0, 760.0]) |
| 69 | .with_min_inner_size([900.0, 560.0]), |
| 70 | ..Default::default() |
| 71 | }; |
| 72 | eframe::run_native( |
| 73 | "Paperdoll Renderer", |
| 74 | options, |
| 75 | Box::new(move |_creation| { |
| 76 | let mut app = EditorApp::default(); |
| 77 | if fixtures { |
| 78 | app.load_fixture_bodies(); |
| 79 | } |
| 80 | Ok(Box::new(app)) |
| 81 | }), |
| 82 | ) |
| 83 | } |