Skip to content

Commit

Permalink
fix simple setup example (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
cBournhonesque authored Jan 26, 2025
1 parent db2edcf commit 41c3fc3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
14 changes: 7 additions & 7 deletions examples/common/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ impl Apps {
}

#[cfg(feature = "gui")]
fn window_plugin() -> WindowPlugin {
pub fn window_plugin() -> WindowPlugin {
WindowPlugin {
primary_window: Some(Window {
title: format!("Lightyear Example: {}", env!("CARGO_PKG_NAME")),
Expand All @@ -473,7 +473,7 @@ fn window_plugin() -> WindowPlugin {
}
}

fn log_plugin() -> LogPlugin {
pub fn log_plugin() -> LogPlugin {
LogPlugin {
level: Level::INFO,
filter: "wgpu=error,bevy_render=info,bevy_ecs=warn,bevy_time=warn".to_string(),
Expand All @@ -482,7 +482,7 @@ fn log_plugin() -> LogPlugin {
}

#[cfg(feature = "gui")]
fn new_gui_app(add_inspector: bool) -> App {
pub fn new_gui_app(add_inspector: bool) -> App {
let mut app = App::new();
app.add_plugins(
DefaultPlugins
Expand All @@ -501,7 +501,7 @@ fn new_gui_app(add_inspector: bool) -> App {
app
}

fn new_headless_app() -> App {
pub fn new_headless_app() -> App {
let mut app = App::new();
app.add_plugins((
MinimalPlugins,
Expand All @@ -516,7 +516,7 @@ fn new_headless_app() -> App {
/// Build the client app with the `ClientPlugins` added.
/// Takes in a `net_config` parameter so that we configure the network transport.
#[cfg(feature = "client")]
fn client_app(settings: Settings, net_config: client::NetConfig) -> (App, ClientConfig) {
pub fn client_app(settings: Settings, net_config: client::NetConfig) -> (App, ClientConfig) {
let app = new_gui_app(settings.client.inspector);

let client_config = ClientConfig {
Expand All @@ -533,7 +533,7 @@ fn client_app(settings: Settings, net_config: client::NetConfig) -> (App, Client

/// Build the server app with the `ServerPlugins` added.
#[cfg(feature = "server")]
fn server_app(
pub fn server_app(
enable_gui: bool,
settings: Settings,
extra_transport_configs: Vec<server::ServerTransport>,
Expand Down Expand Up @@ -567,7 +567,7 @@ fn server_app(

/// An `App` that contains both the client and server plugins
#[cfg(all(feature = "client", feature = "server"))]
fn combined_app(
pub fn combined_app(
settings: Settings,
extra_transport_configs: Vec<server::ServerTransport>,
client_net_config: client::NetConfig,
Expand Down
4 changes: 2 additions & 2 deletions examples/common/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn modify_digest_on_wasm(client_settings: &mut ClientSettings) -> Option<Str
}

#[cfg(target_family = "wasm")]
fn get_digest_on_wasm() -> Option<String> {
pub fn get_digest_on_wasm() -> Option<String> {
let window = web_sys::window().expect("expected window");

if let Ok(obj) = window.location().hash() {
Expand Down Expand Up @@ -358,7 +358,7 @@ pub fn get_server_net_configs(settings: &Settings) -> Vec<server::NetConfig> {
}

/// Build a netcode config for the client
pub(crate) fn build_client_netcode_config(
pub fn build_client_netcode_config(
client_id: u64,
server_addr: SocketAddr,
conditioner: Option<&Conditioner>,
Expand Down
21 changes: 8 additions & 13 deletions examples/simple_setup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@ categories = ["game-development", "network-programming"]
license = "MIT OR Apache-2.0"
publish = false

[features]
gui = [
"bevy/bevy_render",
"bevy/bevy_core_pipeline",
"bevy/bevy_winit",
"bevy/bevy_window",
]
client = ["gui"]
server = []
visualizer = ["lightyear/visualizer", "gui"]

[dependencies]
lightyear = { workspace = true, features = ["steam", "websocket", "leafwing"] }

bevy.workspace = true
clap.workspace = true
lightyear.workspace = true
bevy = { workspace = true, features = [
"bevy_render",
"bevy_core_pipeline",
"bevy_winit",
"bevy_window"
]}
serde.workspace = true
32 changes: 25 additions & 7 deletions examples/simple_setup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,38 @@
#![allow(unused_variables)]
#![allow(dead_code)]

#[cfg(feature = "client")]
mod client;
#[cfg(feature = "server")]
mod server;
mod shared;

use bevy::prelude::*;
use clap::{Parser, Subcommand, ValueEnum};

/// CLI options to create an [`App`]
#[derive(Parser, Debug)]
#[command(version, about)]
pub struct Cli {
#[command(subcommand)]
pub mode: Mode,
}

#[derive(Subcommand, Debug)]
pub enum Mode {
Client,
Server
}

fn main() {
let cli = Cli::parse();
let mut app = App::new();
#[cfg(feature = "client")]
app.add_plugins(client::ExampleClientPlugin);
#[cfg(feature = "server")]
app.add_plugins(server::ExampleServerPlugin);


match cli.mode {
Mode::Client => {
app.add_plugins(client::ExampleClientPlugin);
}
Mode::Server => {
app.add_plugins(server::ExampleServerPlugin);
}
}
app.run();
}

0 comments on commit 41c3fc3

Please sign in to comment.