~starkingdoms/starkingdoms

ref: 265fc540b0a0a8ba38d66066fa6c570968f59e37 starkingdoms/crates/unified/src/main.rs -rw-r--r-- 1.7 KiB
265fc540 — core chore: newtype linearsplines for particle system 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use bevy::log::{Level, tracing_subscriber};
use bevy::prelude::*;
use clap::Parser;
use starkingdoms::client_plugins::ClientPluginGroup;
#[cfg(not(target_arch = "wasm32"))]
use starkingdoms::server_plugins::ServerPluginGroup;
use starkingdoms::shared_plugins::SharedPluginGroup;
use std::net::SocketAddr;
use std::process::exit;
use tracing_subscriber::EnvFilter;
use tracing_subscriber::util::SubscriberInitExt;

#[derive(Parser, Debug)]
#[command(version, about)]
enum Cli {
    Client {
        #[arg(short, long)]
        server: String,
    },
    #[cfg(not(target_arch = "wasm32"))]
    Server {
        #[arg(short = 'b', long)]
        bind: SocketAddr,
        #[arg(short = 'r', long)]
        tick_rate: f64,
        #[arg(short = 'C', long)]
        max_clients: usize,
    },
}

fn main() -> AppExit {
    let cli = Cli::parse();
    let mut app = App::new();

    tracing_subscriber::fmt()
        .with_env_filter(
            EnvFilter::builder()
                .with_default_directive(Level::INFO.into())
                .from_env_lossy(),
        )
        .finish()
        .init();

    match cli {
        Cli::Client { server } => {
            app.add_plugins(ClientPluginGroup { server });
        }
        #[cfg(not(target_arch = "wasm32"))]
        Cli::Server {
            bind,
            tick_rate,
            max_clients,
        } => {
            if cfg!(target_family = "wasm") {
                eprintln!("the server cannot run on webassembly");
                exit(1);
            }

            app.add_plugins(ServerPluginGroup {
                bind,
                tick_rate,
                max_clients,
            });
        }
    }

    app.add_plugins(SharedPluginGroup);

    app.run()
}