1use core::fmt::Debug;
2
3use bevy_ecs::{
4 component::Component,
5 query::With,
6 system::{Commands, Single, SystemParam},
7};
8use bevy_prng::EntropySource;
9
10use crate::{
11 params::{RngEntity, RngEntityItem},
12 prelude::{RngEntityCommands, RngEntityCommandsExt},
13};
14
15#[derive(Debug, Component)]
18pub struct GlobalRng;
19
20#[derive(SystemParam)]
33pub struct GlobalRngEntity<'w, 's, Rng: EntropySource> {
34 commands: Commands<'w, 's>,
35 data: Single<'w, 's, RngEntity<Rng>, With<GlobalRng>>,
36}
37
38impl<Rng: EntropySource> GlobalRngEntity<'_, '_, Rng> {
39 pub fn rng_commands(&mut self) -> RngEntityCommands<'_, '_, Rng> {
41 self.commands.rng(self.data.entity())
42 }
43}
44
45impl<'w, 's, Rng: EntropySource> core::ops::Deref for GlobalRngEntity<'w, 's, Rng> {
46 type Target = RngEntityItem<'w, 's, Rng>;
47
48 fn deref(&self) -> &Self::Target {
49 &self.data
50 }
51}