bones_bevy_utils/
lib.rs

1//! Bevy plugin for rendering Bones framework games.
2
3#![warn(missing_docs)]
4// This cfg_attr is needed because `rustdoc::all` includes lints not supported on stable
5#![cfg_attr(doc, allow(unknown_lints))]
6#![deny(rustdoc::all)]
7
8use type_ulid::TypeUlid;
9
10/// The prelude.
11pub mod prelude {
12    pub use crate::*;
13}
14
15/// Helper trait for converting bones types to Bevy types.
16pub trait IntoBevy<To> {
17    /// Convert the type to a Bevy type.
18    fn into_bevy(self) -> To;
19}
20
21/// Resource that contains a bevy world.
22///
23/// This may be used to give the bones ECS direct access to the bevy world.
24///
25/// One way to do this is to [`std::mem::swap`] an empty world in the [`BevyWorld`]` resource, with
26/// the actual Bevy world, immediatley before running the bones ECS systems. Then you can swap it
27/// back once the bones systems finish.
28#[derive(TypeUlid, Default)]
29#[ulid = "01GNX5CJAAHS31DA9HXZ2CF74B"]
30pub struct BevyWorld(pub Option<bevy_ecs::world::World>);
31
32impl Clone for BevyWorld {
33    fn clone(&self) -> Self {
34        if self.0.is_some() {
35            panic!("BevyWorld may not be cloned.");
36        } else {
37            Self(None)
38        }
39    }
40}
41
42impl std::ops::Deref for BevyWorld {
43    type Target = Option<bevy_ecs::world::World>;
44
45    fn deref(&self) -> &Self::Target {
46        &self.0
47    }
48}
49
50impl std::ops::DerefMut for BevyWorld {
51    fn deref_mut(&mut self) -> &mut Self::Target {
52        &mut self.0
53    }
54}