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
use bones_bevy_renderer::BonesBevyRenderer;
use bones_framework::prelude::*;
//
// NOTE: You must run this example from within the `demos/assets_minimal` folder. Also, be sure to
// look at the `demo/assets_minimal/assets` folder to see the asset files for this example.
//
/// Create our "root" asset type.
#[derive(HasSchema, Clone, Default)]
#[repr(C)]
// We must mark this as a metadata asset, and we set the type to "game".
//
// This means that any files with names like `game.yaml`, `game.yml`, `game.json`, `name.game.yaml`,
// etc. will be loaded as a `GameMeta` asset.
#[type_data(metadata_asset("game"))]
struct GameMeta {
title: String,
}
fn main() {
// Setup logging
setup_logs!();
// First create bones game.
let mut game = Game::new();
game
// We initialize the asset server.
.init_shared_resource::<AssetServer>();
// We must register all of our asset types before they can be loaded by the asset server. This
// may be done by calling schema() on each of our types, to register them with the schema
// registry.
GameMeta::register_schema();
// Create a new session for the game menu. Each session is it's own bones world with it's own
// plugins, systems, and entities.
let menu_session = game.sessions.create("menu");
menu_session
// Install the default bones_framework plugin for this session
.install_plugin(DefaultSessionPlugin)
// Add our menu system to the update stage
.add_system_to_stage(Update, menu_system);
BonesBevyRenderer::new(game).app().run();
}
/// System to render the home menu.
fn menu_system(
egui_ctx: Res<EguiCtx>,
// We can access our root asset by using the Root parameter.
meta: Root<GameMeta>,
) {
egui::CentralPanel::default()
.frame(egui::Frame::none())
.show(&egui_ctx, |ui| {
// Use the title that has been loaded from the asset
ui.heading(&meta.title);
});
}