use core::fmt::Debug;
use bevy_ecs::{
component::Component,
query::With,
system::{Commands, Single, SystemParam},
};
use bevy_prng::EntropySource;
use crate::{
params::{RngEntity, RngEntityItem},
prelude::{RngEntityCommands, RngEntityCommandsExt},
};
#[derive(Debug, Component)]
pub struct GlobalRng;
#[derive(SystemParam)]
pub struct GlobalRngEntity<'w, 's, Rng: EntropySource> {
commands: Commands<'w, 's>,
data: Single<'w, 's, RngEntity<Rng>, With<GlobalRng>>,
}
impl<Rng: EntropySource> GlobalRngEntity<'_, '_, Rng> {
pub fn rng_commands(&mut self) -> RngEntityCommands<'_, '_, Rng> {
self.commands.rng(self.data.entity())
}
}
impl<'w, 's, Rng: EntropySource> core::ops::Deref for GlobalRngEntity<'w, 's, Rng> {
type Target = RngEntityItem<'w, 's, Rng>;
fn deref(&self) -> &Self::Target {
&self.data
}
}