diff --git a/Cargo.toml b/Cargo.toml index bb29946..a67082d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_rng" -version = "0.3.0" +version = "0.3.1" authors = ["Jean Mertz "] edition = "2018" repository = "https://github.com/rustic-games/bevy_rng" @@ -12,8 +12,8 @@ rand = { version = "0.8", default-features = false, features = ["getrandom"] } rand_seeder = "0.2" rand_xoshiro = "0.6" -bevy-stable = { package = "bevy", version = "0.4", default-features = false, optional = true } -bevy-nightly = { package = "bevy", version = "0.4", git = "https://github.com/bevyengine/bevy", rev = "c2a427f1a38db6b1d9798e631a7da7a8507fe18c", default-features = false, optional = true } +bevy-stable = { package = "bevy", version = "0.5", default-features = false, optional = true } +bevy-nightly = { package = "bevy", version = "0.5", git = "https://github.com/bevyengine/bevy", rev = "4f341430469acef478a709aff00bde375743f946", default-features = false, optional = true } [features] -default = ["bevy-stable"] +default = ["bevy-stable"] \ No newline at end of file diff --git a/examples/rng.rs b/examples/rng.rs index f704585..e3c2729 100644 --- a/examples/rng.rs +++ b/examples/rng.rs @@ -1,3 +1,8 @@ +#[cfg(all(feature = "bevy-nightly", not(feature = "bevy-stable")))] +use bevy_nightly as bevy; +#[cfg(all(feature = "bevy-stable", not(feature = "bevy-nightly")))] +use bevy_stable as bevy; + use bevy::app::ScheduleRunnerSettings; use bevy::prelude::*; use bevy_rng::*; @@ -6,7 +11,7 @@ use std::time::Duration; fn main() { // Don't register the plugin (non-deterministic)... App::build() - .add_resource(ScheduleRunnerSettings::run_once()) + .insert_resource(ScheduleRunnerSettings::run_once()) .add_plugins(MinimalPlugins) .add_system(random_number_1.system()) .add_system(random_number_2.system()) @@ -14,7 +19,7 @@ fn main() { // ...don't provide a seed (same as above)... App::build() - .add_resource(ScheduleRunnerSettings::run_once()) + .insert_resource(ScheduleRunnerSettings::run_once()) .add_plugins(MinimalPlugins) .add_plugin(RngPlugin::default()) .add_system(random_number_1.system()) @@ -23,7 +28,7 @@ fn main() { // ...seed from u64 (deterministic)... App::build() - .add_resource(ScheduleRunnerSettings::run_once()) + .insert_resource(ScheduleRunnerSettings::run_once()) .add_plugins(MinimalPlugins) .add_plugin(RngPlugin::from(42)) .add_system(random_number_1.system()) @@ -32,7 +37,7 @@ fn main() { // ...or from a string (same as above). App::build() - .add_resource(ScheduleRunnerSettings::run_loop(Duration::from_millis(100))) + .insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_millis(100))) .add_plugins(MinimalPlugins) .add_plugin(RngPlugin::from("your seed here")) .add_system(random_number_1.system()) diff --git a/src/lib.rs b/src/lib.rs index ad70d3d..e769362 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ use bevy_stable as bevy; use bevy::prelude::*; + pub use rand::Rng as _; /// `RngPlugin` allows you to inject a (optionally seeded) random number @@ -69,10 +70,7 @@ impl Plugin for RngPlugin { None => Xoshiro256StarStar::from_entropy(), }; - #[cfg(all(feature = "bevy-nightly", not(feature = "bevy-stable")))] app.insert_resource(RootRng { rng }); - #[cfg(all(feature = "bevy-stable", not(feature = "bevy-nightly")))] - app.add_resource(RootRng { rng }); } } @@ -105,10 +103,10 @@ impl DerefMut for Rng { } } -impl FromResources for Rng { - fn from_resources(resources: &Resources) -> Self { - let inner = match resources.get_mut::() { - Some(mut rng) => Xoshiro256StarStar::from_rng(&mut rng.deref_mut().rng) +impl FromWorld for Rng { + fn from_world(world: &mut World) -> Self { + let inner = match world.get_resource::() { + Some(rng) => Xoshiro256StarStar::from_rng(rng.rng.clone()) .expect("failed to create rng"), None => Xoshiro256StarStar::from_entropy(), };