BlueGit

golden-age paperdoll-renderer

Files

paperdoll-renderer / src / main.rs

main.rs

main.rs 4.4 KiB Download Raw
1//! Desktop shell for Paperdoll Renderer project files.
2//!
3//! The window edits a `.ppd` project and shows a live skinned glTF/GLB or FBX preview.
4
5use std::process::ExitCode;
6
7use paperdoll_renderer::editor::EditorApp;
8use paperdoll_renderer::foundation::{help_text, parse_cli, report, CliError, CliRequest};
9
10fn 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::InstallDesktop) => {
15 #[cfg(target_os = "linux")]
16 {
17 let exe = std::env::var_os("APPIMAGE")
18 .map(std::path::PathBuf::from)
19 .or_else(|| std::env::current_exe().ok());
20 match exe
21 .ok_or_else(|| "geen uitvoerbaar pad".to_string())
22 .and_then(|exe| paperdoll_renderer::file_assoc::install_linux_integration(&exe))
23 {
24 Ok(()) => {
25 println!("Openen met is geregistreerd.");
26 ExitCode::SUCCESS
27 }
28 Err(error) => {
29 eprintln!("{error}");
30 ExitCode::FAILURE
31 }
32 }
33 }
34 #[cfg(not(target_os = "linux"))]
35 {
36 eprintln!("--install-desktop is voor Linux");
37 ExitCode::from(2)
38 }
39 }
40 Ok(CliRequest::PrintHelp) => {
41 println!("{}", help_text());
42 ExitCode::SUCCESS
43 }
44 Ok(CliRequest::PrintStatus) => {
45 println!("{}", report());
46 ExitCode::SUCCESS
47 }
48 Ok(CliRequest::PreviewFixtures) => open_window(true, None),
49 Ok(CliRequest::OpenWindow) => open_window(false, None),
50 Ok(CliRequest::OpenProject(path)) => {
51 open_window(false, Some(std::path::PathBuf::from(path)))
52 }
53 Err(CliError::Usage(message)) => {
54 eprintln!("paperdoll-renderer: {message}");
55 ExitCode::from(2)
56 }
57 Err(CliError::UnknownArgument(arg)) => {
58 eprintln!("paperdoll-renderer: onbekend argument '{arg}'.");
59 eprintln!("Gebruik --help.");
60 ExitCode::from(2)
61 }
62 }
63}
64
65fn open_window(fixtures: bool, path: Option<std::path::PathBuf>) -> ExitCode {
66 #[cfg(windows)]
67 if let Ok(exe) = std::env::current_exe() {
68 if let Err(error) = paperdoll_renderer::file_assoc::ensure_user_file_association(&exe) {
69 eprintln!("Openen met registreren: {error}");
70 }
71 }
72 if let Some(message) = window_preflight() {
73 eprintln!("paperdoll-renderer: {message}");
74 return ExitCode::from(1);
75 }
76 match run_window(fixtures, path) {
77 Ok(()) => ExitCode::SUCCESS,
78 Err(err) => {
79 eprintln!("paperdoll-renderer: het venster openen is mislukt: {err}");
80 ExitCode::from(1)
81 }
82 }
83}
84
85fn window_preflight() -> Option<String> {
86 #[cfg(target_os = "linux")]
87 {
88 let missing = paperdoll_renderer::foundation::missing_window_libraries();
89 if missing.is_empty() {
90 None
91 } else {
92 Some(paperdoll_renderer::foundation::missing_library_message(
93 &missing,
94 ))
95 }
96 }
97 #[cfg(not(target_os = "linux"))]
98 {
99 None
100 }
101}
102
103fn run_window(fixtures: bool, path: Option<std::path::PathBuf>) -> eframe::Result<()> {
104 let (width, height, rgba) = paperdoll_renderer::icon::window_icon_rgba();
105 let options = eframe::NativeOptions {
106 viewport: eframe::egui::ViewportBuilder::default()
107 .with_title("Paperdoll Renderer")
108 .with_app_id(paperdoll_renderer::icon::APP_ID)
109 .with_inner_size(paperdoll_renderer::session::START_WINDOW)
110 .with_min_inner_size([420.0, 220.0])
111 .with_icon(eframe::egui::IconData {
112 rgba,
113 width,
114 height,
115 }),
116 ..paperdoll_renderer::preview_gl::native_options()
117 };
118 eframe::run_native(
119 "Paperdoll Renderer",
120 options,
121 Box::new(move |_creation| {
122 let mut app = EditorApp::default();
123 if fixtures {
124 app.open_fixture_project();
125 }
126 if let Some(path) = path {
127 app.open_path(path);
128 }
129 Ok(Box::new(app))
130 }),
131 )
132}