diff --git a/Makefile b/Makefile index d40660e..1cc2bca 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ dist/trees: mkdir -p dist/trees # Build the web version -release/trees/web: +release/trees/web: src/bin/trees/main.rs src/bin/trees/mono.rs cargo build --bin trees --release --target wasm32-unknown-unknown # Use wasm-bindgen to do some magic diff --git a/examples/sensors.rs b/examples/sensors.rs index 6b56a39..709d92b 100644 --- a/examples/sensors.rs +++ b/examples/sensors.rs @@ -11,7 +11,7 @@ use games::*; /// This shows how to do that. fn main() { App::new() - .add_plugins(BaseGamePlugin) + .add_plugins(BaseGamePlugin::default()) .init_resource::() .add_systems( Startup, diff --git a/examples/sync_resource_to_ui.rs b/examples/sync_resource_to_ui.rs index 4738f18..5966ca5 100644 --- a/examples/sync_resource_to_ui.rs +++ b/examples/sync_resource_to_ui.rs @@ -3,7 +3,7 @@ use games::*; fn main() { App::new() .init_resource::() - .add_plugins(BaseGamePlugin) + .add_plugins(BaseGamePlugin::default()) .add_systems(Startup, init_ui) .add_systems( Update, diff --git a/src/base_game.rs b/src/base_game.rs index 685c878..9f1132d 100644 --- a/src/base_game.rs +++ b/src/base_game.rs @@ -1,14 +1,24 @@ use super::*; /// A good starting place for creating a game building on top of the base Bevy app -pub struct BaseGamePlugin; +pub struct BaseGamePlugin { + pub name: String, +} + +impl Default for BaseGamePlugin { + fn default() -> Self { + BaseGamePlugin { + name: "mygame".into(), + } + } +} impl Plugin for BaseGamePlugin { fn build(&self, app: &mut App) { app.add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { fit_canvas_to_parent: true, - canvas: Some("game".into()), + canvas: Some(format!("#{}-canvas", self.name)), ..default() }), ..default() diff --git a/src/bin/hum/main.rs b/src/bin/hum/main.rs index fa860fa..6be0ce8 100644 --- a/src/bin/hum/main.rs +++ b/src/bin/hum/main.rs @@ -1,5 +1,7 @@ use games::*; fn main() { - App::new().add_plugins(BaseGamePlugin).run(); + App::new() + .add_plugins(BaseGamePlugin { name: "hum".into() }) + .run(); } diff --git a/src/bin/tetris/main.rs b/src/bin/tetris/main.rs index fa860fa..baa1daf 100644 --- a/src/bin/tetris/main.rs +++ b/src/bin/tetris/main.rs @@ -1,5 +1,9 @@ use games::*; fn main() { - App::new().add_plugins(BaseGamePlugin).run(); + App::new() + .add_plugins(BaseGamePlugin { + name: "tetris-rpg".into(), + }) + .run(); } diff --git a/src/bin/trees/main.rs b/src/bin/trees/main.rs index f0189ec..41e658b 100644 --- a/src/bin/trees/main.rs +++ b/src/bin/trees/main.rs @@ -5,13 +5,15 @@ mod mono; use bevy::platform::hash::RandomState; -use std::hash::BuildHasher; use games::*; use mono::*; +use std::hash::BuildHasher; fn main() { App::new() - .add_plugins(BaseGamePlugin) + .add_plugins(BaseGamePlugin { + name: "trees".into(), + }) .add_plugins(MonologueAssetsPlugin) .add_event::() .init_state::() @@ -523,8 +525,20 @@ fn delete_tree(trigger: Trigger>, mut commands: Commands) { } } -fn load_monologues(server: ResMut, mut loaded_folder: Local>) { +/// Load all monologues so they are in the asset store and trigger on-load events +fn load_monologues( + server: ResMut, + mut loaded_folder: Local>, + mut loaded_assets: Local>>, +) { + // TODO: Figure out a programatic way to load all assets in the web version... + // Likely a mega asset that points to all sub-assets or something silly *loaded_folder = server.load_folder("trees"); + *loaded_assets = vec![ + server.load("trees/red.mono"), + server.load("trees/green.mono"), + server.load("trees/blue.mono"), + ]; } fn spawn_debug_buttons( @@ -637,7 +651,7 @@ fn populate_tree( mut materials: ResMut>, ) { if !trees.contains(trigger.target()) { - return + return; } // Generate "random" X and Y Coordinates for this tree diff --git a/src/debug.rs b/src/debug.rs index 018f285..a779b01 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -125,6 +125,7 @@ fn toggle_debug_state( } /// Simple system that enables/disables rapier debug visuals when the debugging state changes +#[cfg(not(target_arch = "wasm32"))] fn toggle_rapier_debug_render( state: Res>, mut context: ResMut, @@ -232,10 +233,12 @@ fn hover_ui( }); } +#[cfg(not(target_arch = "wasm32"))] fn enable_wireframe(mut wireframe_config: ResMut) { wireframe_config.global = true; } +#[cfg(not(target_arch = "wasm32"))] fn disable_wireframe(mut wireframe_config: ResMut) { wireframe_config.global = false; } diff --git a/web/trees.html b/web/trees.html index cbda8f7..468f597 100644 --- a/web/trees.html +++ b/web/trees.html @@ -1,6 +1,7 @@ +