Add CLI for networking
This commit is contained in:
parent
62da4093ea
commit
b7804bd547
3 changed files with 37 additions and 9 deletions
31
src/lib.rs
31
src/lib.rs
|
@ -1,7 +1,8 @@
|
|||
use std::net::SocketAddr;
|
||||
|
||||
use avian2d::{math::Vector, prelude::*};
|
||||
use bevy::{input::common_conditions::input_pressed, prelude::*};
|
||||
use bevy_rand::prelude::{EntropyPlugin, WyRand};
|
||||
use clap::Parser;
|
||||
use clap::{Args, Parser};
|
||||
|
||||
mod game;
|
||||
use game::{
|
||||
|
@ -15,14 +16,25 @@ use game::{
|
|||
#[derive(Parser)]
|
||||
#[command(version, about)]
|
||||
pub struct AppSettings {
|
||||
#[arg(short, long, default_value = ":)")]
|
||||
pub seed: Seed,
|
||||
#[command(flatten)]
|
||||
source: Source,
|
||||
|
||||
#[arg(short, long, default_value = "25565")]
|
||||
port: u16,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
#[group(required = false, multiple = false)]
|
||||
struct Source {
|
||||
#[arg(short, long)]
|
||||
seed: Option<Seed>,
|
||||
#[arg(short, long)]
|
||||
connect: Option<SocketAddr>,
|
||||
}
|
||||
|
||||
impl Plugin for AppSettings {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(Gravity(Vector::ZERO))
|
||||
.insert_resource(self.seed.clone())
|
||||
.add_plugins((
|
||||
DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Window {
|
||||
|
@ -34,7 +46,6 @@ impl Plugin for AppSettings {
|
|||
..default()
|
||||
}),
|
||||
PhysicsPlugins::default().with_length_unit(50.0),
|
||||
EntropyPlugin::<WyRand>::with_seed(self.seed.clone().into()),
|
||||
))
|
||||
.add_systems(
|
||||
Startup,
|
||||
|
@ -53,5 +64,13 @@ impl Plugin for AppSettings {
|
|||
),
|
||||
)
|
||||
.add_systems(PostUpdate, move_camera);
|
||||
if let Some(ref seed) = self.source.seed {
|
||||
app.insert_resource(seed.clone());
|
||||
} else if let Some(ref peer) = self.source.connect {
|
||||
println!("{peer}");
|
||||
todo!("Handle connecting to peer and retrieving seed");
|
||||
} else {
|
||||
app.insert_resource(Seed::random());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue