diff --git a/.gitignore b/.gitignore index 869df07..2953c26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +.devcontainer/ /target Cargo.lock \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index c313588..214e7c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,19 +9,19 @@ repository = "https://github.com/ickshonpe/bevy_stat_bars" description = "plugin for drawing floating stat bars" [dependencies.bevy] -version = "0.8" +version = "0.15" default-features = false -features = ["render"] +features = ["bevy_render", "bevy_color", "bevy_sprite"] [dependencies.copyless] -version = "0.1.5" +version = "0.1" [dev-dependencies.bevy] -version = "0.8" +version = "0.15" default-features = true [dev-dependencies.bevy-inspector-egui] -version = "0.13.0" +version = "0.28" [dev-dependencies.seq-macro] -version = "0.3.1" \ No newline at end of file +version = "0.3" diff --git a/README.md b/README.md index eb2e995..154f76c 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ Bevy crate for drawing floating statbars like health bars above enemy sprites et * Multiple Statbar components on one entity implemented using PhantomData. This requires ![/media/example.png](/media/example.png) -# - ## How to use Add the dependency to your Cargo.toml file with @@ -31,7 +29,7 @@ version = "0.3" Then register any components you want to observe with a statbar with your Bevy App: -```rust +```rust use bevy_stat_bars::*; App::new() @@ -43,7 +41,7 @@ App::new() You also need to implement the ```StatbarObservable``` trait on those components: -```rust +```rust impl StatbarObservable for HitPoints { fn get_statbar_value(&self) -> f32 { self.value / self.max @@ -69,13 +67,12 @@ commands.entity(enemy_id) ![/media/example2.png](/media/example2.png) -# - ## Examples There are six examples you can look at that cover most of the features and use cases, run them with -``` + +```bash cargo run --example minimal_standalone cargo run --example basic_interactive cargo run --example observe_resource @@ -83,45 +80,47 @@ cargo run --example demo cargo run --example stress --release cargo run --example stress2 --release ``` + The ```demo``` example is the probably the most useful to look at. The ```stress2``` example uses macros to add hundreds of marker types and can take a few minutes to compile. -# - ## Notes * Only supports 2D. * When I was writing the examples I made a mistake where instead of - ```rust - .add_statbar_component_observer::>() - ``` - I used - ```rust - .add_statbar_component_observer::() - ``` - which is quite easy to miss. The crate fails silently and just won't render anything in this case, leaving the user with a frustrating bug hunt. +```rust +.add_statbar_component_observer::>() +``` + +I used : + +```rust +.add_statbar_component_observer::() +``` + +Which is quite easy to miss. The crate fails silently and just won't render anything in this case, leaving the user with a frustrating bug hunt. - Likewise also when a statbar is set to observe its parent or another Entity that doesn't exist, it will render a statbar that doesn't update. +Likewise also when a statbar is set to observe its parent or another Entity that doesn't exist, it will render a statbar that doesn't update. * Statbars are drawn using Sprites with a z depth of 990, and if you translate the camera down more than 10 units they won't draw. -You can change the depth with the ```StatbarDepth``` resource. - - So with +You can change the depth with the ```StatbarDepth``` resource. - ```rust - commands.insert_resource(StatbarDepth(500.)); - ``` +So with: - all Statbars will now render with a z depth of 500. - There currently isn't any way to control the ordering in which the individual statbars are drawn. +```rust +commands.insert_resource(StatbarDepth(500.)); +``` + +All Statbars will now render with a z depth of 500. +There currently isn't any way to control the ordering in which the individual statbars are drawn. * Still uses sprites for rendering which isn't ideal but performance seems fine. You can run the ```stress``` example to see what its like under a heavy load. I get about 100fps on my rx580. -* ```add_statbar_component_observer``` adds six systems to your Bevy app per component observed. Again not ideal but doesn't seem to be a problem. I get ~100fps with the ```stress2``` example which spawns 100 entities with 200 Statbars each. -# +* `add_statbar_component_observer` adds six systems to your Bevy app per component observed. Again not ideal but doesn't seem to be a problem. I get ~100fps with the ```stress2``` example which spawns 100 entities with 200 Statbars each. + ## Future Plans * Replace the sprite based rendering with a custom renderer. I have some fragment shaders already written, and should be better performance with some nice effects like rounded corners and color gradients. @@ -130,14 +129,3 @@ You can change the depth with the ```StatbarDepth``` resource. * Some sort of, posibly feature gated or debug-only, falure detection that gives an error when you insert unregistered statbars, or when a statbar can't find the component it is meant to be observing. * Derive macro for StatbarObservable. * Auto arrangement/stacking of groups of statbars. I thought this would be more difficult but I dreamt up an easyish way to do it last night. - - - - - - - - - - - diff --git a/examples/basic_interactive.rs b/examples/basic_interactive.rs index db1f0e2..ba7418f 100644 --- a/examples/basic_interactive.rs +++ b/examples/basic_interactive.rs @@ -1,4 +1,7 @@ -use bevy::prelude::*; +use bevy::{ + prelude::*, + render::view::{RenderVisibleEntities, VisibleEntities}, +}; use bevy_stat_bars::*; // Spawns a red and navy statbar with a white border in the middle of the window. @@ -16,36 +19,35 @@ impl StatbarObservable for ObservedValue { } fn spawn_camera(mut commands: Commands) { - commands.spawn_bundle(Camera2dBundle::default()); + commands.spawn(Camera2d); } fn spawn_statbar(mut commands: Commands) { - commands - .spawn_bundle(( - Statbar:: { - color: Color::RED, - empty_color: Color::NAVY, - length: 400., - thickness: 40., - ..Default::default() - }, - StatbarBorder::::all(Color::WHITE, 4.0), - ObservedValue(0.35), - )) - .insert_bundle(SpatialBundle::default()); + commands.spawn(( + Statbar:: { + color: Color::from(bevy::color::palettes::css::RED), + empty_color: Color::from(bevy::color::palettes::css::NAVY), + length: 400., + thickness: 40., + ..Default::default() + }, + StatbarBorder::::all(Color::WHITE, 4.0), + ObservedValue(0.35), + Visibility::Visible, + )); } fn adjust_value( time: Res