1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! The bones framework for game development.
//!
#![cfg_attr(feature = "document-features", doc = "## Features")]
#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
#![warn(missing_docs)]
// This cfg_attr is needed because `rustdoc::all` includes lints not supported on stable
#![cfg_attr(doc, allow(unknown_lints))]
#![deny(rustdoc::all)]

#[doc(inline)]
pub use bones_lib as lib;

#[doc(inline)]
pub use bones_asset as asset;

/// Math library.
#[doc(inline)]
pub use glam;

/// The prelude.
pub mod prelude {
    pub use crate::{
        animation::*, debug, input::prelude::*, params::*, render::prelude::*, storage::*, time::*,
        utils::*, AssetServerExt, DefaultGamePlugin, DefaultSessionPlugin,
    };

    #[cfg(not(target_arch = "wasm32"))]
    pub use crate::networking::prelude::*;

    pub use bones_asset::anyhow::Context;
    pub use bones_asset::prelude::*;
    pub use bones_lib::prelude::*;
    pub use glam::*;

    pub use serde::{Deserialize, Serialize};

    #[cfg(feature = "scripting")]
    pub use bones_scripting::prelude::*;

    #[cfg(feature = "localization")]
    pub use crate::localization::*;
}

pub mod animation;
pub mod debug;
pub mod input;
pub mod params;
pub mod render;
pub mod storage;
pub mod time;
pub mod utils;

#[cfg(not(target_arch = "wasm32"))]
pub mod networking;

#[cfg(feature = "scripting")]
pub use bones_scripting as scripting;

#[cfg(feature = "localization")]
pub mod localization;

/// External crate documentation.
///
/// This module only exists during docs builds and serves to make it eaiser to link to relevant
/// documentation in external crates.
#[cfg(doc)]
pub mod external {
    #[doc(inline)]
    pub use ggrs;

    #[doc(inline)]
    pub use bones_matchmaker_proto;
}

/// Default plugins for bones framework sessions.
pub struct DefaultSessionPlugin;
impl lib::SessionPlugin for DefaultSessionPlugin {
    fn install(self, session: &mut lib::Session) {
        session
            .install_plugin(animation::animation_plugin)
            .install_plugin(render::render_plugin);
    }
}

/// Default plugins for bones framework games.
pub struct DefaultGamePlugin;
impl lib::GamePlugin for DefaultGamePlugin {
    fn install(self, game: &mut lib::Game) {
        game.install_plugin(render::audio::game_plugin);

        #[cfg(feature = "scripting")]
        game.install_plugin(bones_scripting::ScriptingGamePlugin::default());
    }
}

/// Extension trait for the bones [`AssetServer`][bones_asset::AssetServer].
pub trait AssetServerExt {
    /// Register the default assets from `bones_framework`.
    fn register_default_assets(self) -> Self;
}
impl AssetServerExt for &mut bones_asset::AssetServer {
    fn register_default_assets(self) -> Self {
        use crate::prelude::*;

        // Register asset schemas
        Image::register_schema();
        Atlas::register_schema();

        #[cfg(feature = "localization")]
        {
            LocalizationAsset::register_schema();
            FluentBundleAsset::register_schema();
            FluentResourceAsset::register_schema();
        }

        #[cfg(feature = "ui")]
        Font::register_schema();

        self
    }
}