1use bevy::prelude::*;
2mod basic;
3mod interface;
4mod intervals;
5mod lines;
6mod rw_data;
7mod search;
8mod settings;
9mod status_bar_text;
10mod vehicle_set;
11mod vehicles;
12
13use clap::Parser;
14
15#[derive(Parser, Resource)]
16#[command(version, about, long_about = None)]
17struct Cli {
18 #[arg(
19 short = 'o',
20 long = "open",
21 help = "Path to a .paiagram file (or any other compatible file formats) to open on startup"
22 )]
23 open: Option<String>,
24}
25
26fn main() {
28 let args = Cli::parse();
29 let app_window = Some(Window {
30 title: "Paiagram Drawer".into(),
31 fit_canvas_to_parent: true,
32 ..default()
33 });
34 App::new()
35 .insert_resource(args)
36 .add_systems(Startup, handle_args)
37 .add_plugins((
38 DefaultPlugins.set(WindowPlugin {
39 primary_window: app_window,
40 ..default()
41 }),
42 bevy_framepace::FramepacePlugin,
43 interface::InterfacePlugin,
44 intervals::IntervalsPlugin,
45 rw_data::RwDataPlugin,
46 search::SearchPlugin,
47 settings::SettingsPlugin,
48 vehicles::VehiclesPlugin,
49 ))
50 .run();
51}
52
53fn handle_args(cli: Res<Cli>, mut msg: MessageWriter<rw_data::ModifyData>, mut commands: Commands) {
54 if let Some(path) = &cli.open {
55 use rw_data::ModifyData;
56 match path.split('.').next_back() {
58 Some("paiagram") => {
59 warn!("Opening .paiagram files is not yet implemented.");
60 }
61 Some("json") | Some("pyetgr") => {
62 let file_content = std::fs::read_to_string(path).expect("Failed to read file");
64 msg.write(ModifyData::LoadQETRC(file_content));
65 }
66 Some("oud2") => {
67 let file_content = std::fs::read_to_string(path).expect("Failed to read file");
68 msg.write(ModifyData::LoadOuDiaSecond(file_content));
69 }
70 _ => {
71 warn!("Unsupported file format: {}", path);
72 }
73 }
74 }
75 commands.remove_resource::<Cli>();
76}