1pub mod audio;
2pub mod check;
3pub mod editor;
4pub mod input;
5pub mod inspect;
6pub mod level;
7pub mod log;
8pub mod outline;
9pub mod pgpu;
10pub mod script;
11pub mod session;
12pub mod snap;
13pub mod theme;
14pub mod ui;
15pub mod ui_level;
16pub mod view;
17
18use std::path::Path;
19
20use pfx_play::Game;
21
22pub const USAGE: &str = "usage: pfx edit <scene.toml>|<project folder>";
23
24fn setup() -> session::Setup {
25 session::Setup {
26 pgpu: std::env::var("PFX_EDIT_PGPU").map_or(true, |value| value != "off")
27 && std::env::var_os("PATH").is_some_and(|path| pgpu::on_path(&path)),
28 audio: true,
29 }
30}
31
32fn window(session: session::Session) -> Result<(), String> {
33 pfx_editor_shell::window(session, None).map_err(|error| error.to_string())
34}
35
36pub fn run(args: &[String]) -> Result<(), String> {
37 match args {
38 [path] if !path.starts_with('-') => {
39 let path = Path::new(path);
40 if path.is_dir() {
41 return window(session::Session::open_project(path, setup(), None)?);
42 }
43 if !path.is_file() {
44 return Err(format!(
45 "{}: no such scene file or project folder",
46 path.display()
47 ));
48 }
49 window(session::Session::open(path, setup())?)
50 }
51 _ => Err(USAGE.to_string()),
52 }
53}
54
55pub fn factory<G: Game + 'static>(make: impl Fn() -> G + 'static) -> session::Factory {
56 pfx_game::factory(make)
57}
58
59pub fn run_project(
60 project: &Path,
61 factory: session::Factory,
62 config: pfx_game::Config,
63) -> Result<(), String> {
64 window(session::Session::open_game(
65 project,
66 setup(),
67 factory,
68 config,
69 )?)
70}
71
72#[cfg(test)]
73mod tests;