demo_assets_minimal/
main.rs

1use bones_bevy_renderer::BonesBevyRenderer;
2use bones_framework::prelude::*;
3
4//
5// NOTE: You must run this example from within the `demos/assets_minimal` folder. Also, be sure to
6// look at the `demo/assets_minimal/assets` folder to see the asset files for this example.
7//
8
9/// Create our "root" asset type.
10#[derive(HasSchema, Clone, Default)]
11#[repr(C)]
12// We must mark this as a metadata asset, and we set the type to "game".
13//
14// This means that any files with names like `game.yaml`, `game.yml`, `game.json`, `name.game.yaml`,
15// etc. will be loaded as a `GameMeta` asset.
16#[type_data(metadata_asset("game"))]
17struct GameMeta {
18    title: String,
19}
20
21fn main() {
22    // Setup logging
23    setup_logs!();
24
25    // First create bones game.
26    let mut game = Game::new();
27
28    game
29        // We initialize the asset server.
30        .init_shared_resource::<AssetServer>();
31
32    // We must register all of our asset types before they can be loaded by the asset server. This
33    // may be done by calling schema() on each of our types, to register them with the schema
34    // registry.
35    GameMeta::register_schema();
36
37    // Create a new session for the game menu. Each session is it's own bones world with it's own
38    // plugins, systems, and entities.
39    let mut menu_session_builder = SessionBuilder::new("menu");
40
41    // Install the default bones_framework plugin for this session
42    menu_session_builder
43        .install_plugin(DefaultSessionPlugin)
44        // Add our menu system to the update stage
45        .add_system_to_stage(Update, menu_system);
46
47    // Finalize session and register with game sessions.
48    menu_session_builder.finish_and_add(&mut game.sessions);
49
50    BonesBevyRenderer::new(game).app().run();
51}
52
53/// System to render the home menu.
54fn menu_system(
55    egui_ctx: Res<EguiCtx>,
56    // We can access our root asset by using the Root parameter.
57    meta: Root<GameMeta>,
58) {
59    egui::CentralPanel::default()
60        .frame(egui::Frame::none())
61        .show(&egui_ctx, |ui| {
62            // Use the title that has been loaded from the asset
63            ui.heading(&meta.title);
64        });
65}