bones_framework/
lib.rs

1//! The bones framework for game development.
2//!
3#![cfg_attr(feature = "document-features", doc = "## Features")]
4#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
5#![warn(missing_docs)]
6// This cfg_attr is needed because `rustdoc::all` includes lints not supported on stable
7#![cfg_attr(doc, allow(unknown_lints))]
8#![deny(rustdoc::all)]
9
10#[doc(inline)]
11pub use bones_lib as lib;
12
13#[doc(inline)]
14pub use bones_asset as asset;
15
16/// Math library.
17#[doc(inline)]
18pub use glam;
19
20/// The prelude.
21pub mod prelude {
22    pub use crate::{
23        animation::*, input::prelude::*, params::*, render::prelude::*, storage::*, time::*,
24        utils::*, AssetServerExt, DefaultGamePlugin, DefaultSessionPlugin, ExitBones,
25    };
26
27    pub use futures_lite::future::Boxed as BoxedFuture;
28
29    #[cfg(feature = "ui")]
30    pub use crate::debug;
31
32    #[cfg(not(target_arch = "wasm32"))]
33    pub use crate::networking::prelude::*;
34
35    pub use bones_asset::anyhow::Context;
36    pub use bones_asset::prelude::*;
37    pub use bones_lib::prelude::*;
38    pub use glam::*;
39
40    pub use serde::{Deserialize, Serialize};
41
42    #[cfg(feature = "scripting")]
43    pub use bones_scripting::prelude::*;
44
45    #[cfg(feature = "localization")]
46    pub use crate::localization::*;
47
48    #[cfg(feature = "logging")]
49    pub use crate::logging::prelude::*;
50}
51
52pub mod animation;
53pub mod input;
54pub mod params;
55pub mod render;
56pub mod storage;
57pub mod time;
58pub mod utils;
59
60#[cfg(feature = "audio")]
61pub mod audio;
62
63#[cfg(feature = "ui")]
64pub mod debug;
65
66#[cfg(not(target_arch = "wasm32"))]
67pub mod networking;
68
69#[cfg(feature = "scripting")]
70pub use bones_scripting as scripting;
71
72#[cfg(feature = "localization")]
73pub mod localization;
74
75#[cfg(feature = "logging")]
76pub mod logging;
77
78/// External crate documentation.
79///
80/// This module only exists during docs builds and serves to make it eaiser to link to relevant
81/// documentation in external crates.
82#[cfg(doc)]
83pub mod external {
84    #[doc(inline)]
85    pub use ggrs;
86
87    #[doc(inline)]
88    pub use bones_matchmaker_proto;
89}
90
91/// Default plugins for bones framework sessions.
92pub struct DefaultSessionPlugin;
93impl lib::SessionPlugin for DefaultSessionPlugin {
94    fn install(self, session: &mut lib::SessionBuilder) {
95        session
96            .install_plugin(animation::animation_plugin)
97            .install_plugin(render::render_plugin);
98    }
99}
100
101/// Default plugins for bones framework games.
102pub struct DefaultGamePlugin;
103impl lib::GamePlugin for DefaultGamePlugin {
104    #[allow(unused_variables)]
105    fn install(self, game: &mut lib::Game) {
106        #[cfg(feature = "audio")]
107        game.install_plugin(audio::game_plugin);
108
109        #[cfg(feature = "scripting")]
110        game.install_plugin(bones_scripting::ScriptingGamePlugin::default());
111    }
112}
113
114/// Extension trait for the bones [`AssetServer`][bones_asset::AssetServer].
115pub trait AssetServerExt {
116    /// Register the default assets from `bones_framework`.
117    fn register_default_assets(self) -> Self;
118}
119impl AssetServerExt for &mut bones_asset::AssetServer {
120    fn register_default_assets(self) -> Self {
121        use crate::prelude::*;
122
123        // Register asset schemas
124        Image::register_schema();
125        Atlas::register_schema();
126
127        #[cfg(feature = "localization")]
128        {
129            LocalizationAsset::register_schema();
130            FluentBundleAsset::register_schema();
131            FluentResourceAsset::register_schema();
132        }
133
134        #[cfg(feature = "ui")]
135        Font::register_schema();
136
137        self
138    }
139}
140
141/// Resource for exiting bones games.
142///
143/// ## Notes
144/// This has to be supported by the platform that is using bones.
145/// Though it is not enforced, whether or not the platform inserts
146/// this as a shared resource on your bones game should determine
147/// whether or not it supports an exit functionality.
148#[derive(bones_schema::HasSchema, Default, Clone)]
149pub struct ExitBones(pub bool);
150
151impl std::ops::Deref for ExitBones {
152    type Target = bool;
153
154    fn deref(&self) -> &Self::Target {
155        &self.0
156    }
157}
158impl std::ops::DerefMut for ExitBones {
159    fn deref_mut(&mut self) -> &mut Self::Target {
160        &mut self.0
161    }
162}