Skip to content

Commit

Permalink
Embed assets in binary
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmauro committed Apr 18, 2024
1 parent 380f8c2 commit 1d442a2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bevy_egui = { version = "0.26.0", default-features = false, features = [
"default_fonts",
"render",
] }
bevy_embedded_assets = "0.10.2"
bevy_kira_audio = "0.19.0"
image = "0.25.0"
rand = "0.8.5"
Expand Down
16 changes: 8 additions & 8 deletions src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ use bevy_kira_audio::AudioSource;

#[derive(AssetCollection, Resource)]
pub struct AudioAssets {
#[asset(path = "audio/c.ogg")]
#[asset(path = "embedded://audio/c.ogg")]
pub c: Handle<AudioSource>,
#[asset(path = "audio/h.ogg")]
#[asset(path = "embedded://audio/h.ogg")]
pub h: Handle<AudioSource>,
#[asset(path = "audio/k.ogg")]
#[asset(path = "embedded://audio/k.ogg")]
pub k: Handle<AudioSource>,
#[asset(path = "audio/l.ogg")]
#[asset(path = "embedded://audio/l.ogg")]
pub l: Handle<AudioSource>,
#[asset(path = "audio/q.ogg")]
#[asset(path = "embedded://audio/q.ogg")]
pub q: Handle<AudioSource>,
#[asset(path = "audio/r.ogg")]
#[asset(path = "embedded://audio/r.ogg")]
pub r: Handle<AudioSource>,
#[asset(path = "audio/s.ogg")]
#[asset(path = "embedded://audio/s.ogg")]
pub s: Handle<AudioSource>,
#[asset(path = "audio/t.ogg")]
#[asset(path = "embedded://audio/t.ogg")]
pub t: Handle<AudioSource>,
}
12 changes: 7 additions & 5 deletions src/game/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ impl Plugin for UiPlugin {
}

pub fn setup(mut commands: Commands, settings: Res<GameSettings>, asset_server: Res<AssetServer>) {
let font = asset_server.load("embedded://fonts/FiraSans-Bold.ttf");

commands
.spawn((
NodeBundle {
Expand Down Expand Up @@ -56,7 +58,7 @@ pub fn setup(mut commands: Commands, settings: Res<GameSettings>, asset_server:
parent.spawn(TextBundle::from_section(
format!("{}-Back", settings.n),
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font: font.clone(),
font_size: 40.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
Expand All @@ -65,7 +67,7 @@ pub fn setup(mut commands: Commands, settings: Res<GameSettings>, asset_server:
TextBundle::from_section(
"11/24",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font: font.clone(),
font_size: 40.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
Expand Down Expand Up @@ -109,7 +111,7 @@ pub fn setup(mut commands: Commands, settings: Res<GameSettings>, asset_server:
parent.spawn(TextBundle::from_section(
"Position (A)",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font: font.clone(),
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
Expand Down Expand Up @@ -137,7 +139,7 @@ pub fn setup(mut commands: Commands, settings: Res<GameSettings>, asset_server:
parent.spawn(TextBundle::from_section(
"Sound (S)",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font: font.clone(),
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
Expand Down Expand Up @@ -165,7 +167,7 @@ pub fn setup(mut commands: Commands, settings: Res<GameSettings>, asset_server:
parent.spawn(TextBundle::from_section(
"Color (D)",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font: font.clone(),
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bevy_asset_loader::loading_state::{
config::ConfigureLoadingState, LoadingState, LoadingStateAppExt,
};
use bevy_egui::EguiPlugin;
use bevy_embedded_assets::EmbeddedAssetPlugin;
use bevy_kira_audio::AudioPlugin;
use nback::{
asset::AudioAssets, game::GamePlugin, menu::MenuPlugin, palette, splash::SplashPlugin,
Expand All @@ -18,6 +19,7 @@ fn main() {
.load_collection::<AudioAssets>(),
)
.insert_resource(ClearColor(palette::SLATE_800))
.add_plugins(EmbeddedAssetPlugin::default())
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(504., 896.).with_scale_factor_override(1.2),
Expand Down
2 changes: 1 addition & 1 deletion src/menu/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn menu_ui(
settings: Res<GameSettings>,
scores: ResMut<LatestGameScores>,
) {
let font = asset_server.load("fonts/FiraSans-Bold.ttf");
let font = asset_server.load("embedded://fonts/FiraSans-Bold.ttf");

commands
.spawn((
Expand Down
2 changes: 1 addition & 1 deletion src/splash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Plugin for SplashPlugin {
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let icon = asset_server.load("icon.png");
let icon = asset_server.load("embedded://icon.png");

commands
.spawn((
Expand Down

0 comments on commit 1d442a2

Please sign in to comment.