Embed font at compile-time

This commit is contained in:
Tobias Berger 2022-09-19 12:48:13 +02:00
parent 81df0cd02f
commit 8fa5393a41
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
4 changed files with 86 additions and 649146 deletions

649067
planet.ron

File diff suppressed because one or more lines are too long

View file

@ -1,14 +1,15 @@
#[cfg(feature = "render")]
use crate::TerrainCell;
#[cfg(all(feature = "debug", feature = "render"))]
use bevy::log::debug;
#[cfg(feature = "debug")]
use bevy::utils::default;
#[cfg(feature = "render")]
use bevy::{
use {
crate::TerrainCell,
bevy::{
asset::{Assets, HandleId},
render::render_resource::Extent3d,
render::{color::Color, texture::Image},
},
};
use {
crate::{Biome, World, WorldGenError},

View file

@ -47,9 +47,16 @@ use bevy::{
render::mesh::{shape::Icosphere, Mesh},
transform::components::Transform,
};
#[cfg(feature = "render")]
#[cfg(all(feature = "debug", feature = "render"))]
use bevy::{
asset::{AssetServer, Assets},
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
log::debug,
};
#[cfg(feature = "render")]
use {
bevy::text::Font,
bevy::{
asset::Assets,
core_pipeline::core_2d::{Camera2d, Camera2dBundle},
ecs::{
change_detection::ResMut,
@ -88,21 +95,14 @@ use bevy::{
},
window::{CursorIcon, WindowDescriptor, Windows},
winit::WinitSettings,
};
#[cfg(all(feature = "debug", feature = "render"))]
use bevy::{
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
log::debug,
};
#[cfg(feature = "render")]
use components::{
},
components::{
markers::{InfoPanel, ToolbarButton},
third_party::PanCam,
},
resources::CursorMapPosition,
ui_helpers::{toolbar_button, toolbar_button_text},
};
#[cfg(feature = "render")]
use resources::CursorMapPosition;
#[cfg(feature = "render")]
use ui_helpers::{toolbar_button, toolbar_button_text};
use {
bevy::{
app::App,
@ -337,12 +337,16 @@ fn update_info_panel(
#[cfg(feature = "render")]
fn generate_graphics(
mut commands: Commands<'_, '_>,
mut world_manager: ResMut<'_, WorldManager>,
mut images: ResMut<'_, Assets<Image>>,
mut fonts: ResMut<'_, Assets<Font>>,
#[cfg(feature = "planet_view")] mut materials: ResMut<'_, Assets<StandardMaterial>>,
#[cfg(feature = "planet_view")] mut meshes: ResMut<'_, Assets<Mesh>>,
mut world_manager: ResMut<'_, WorldManager>,
asset_server: Res<'_, AssetServer>,
) {
let julia_mono_handle = fonts.add(
Font::try_from_bytes(include_bytes!("../assets/JuliaMono.ttf").to_vec())
.expect("Failed to create JuliaMono font!"),
);
let world = world_manager.world();
let custom_sprite_size = Vec2 {
x: (WORLD_SCALE * world.width as i32) as f32,
@ -417,6 +421,7 @@ fn generate_graphics(
},
..default()
});
_ = commands
.spawn_bundle(NodeBundle {
style: Style {
@ -444,7 +449,7 @@ fn generate_graphics(
text: Text::from_section(
"Info Panel",
bevy::text::TextStyle {
font: asset_server.load("JuliaMono.ttf"),
font: julia_mono_handle.clone(),
font_size: 15.0,
color: Color::WHITE,
},
@ -471,8 +476,10 @@ fn generate_graphics(
_ = button_box
.spawn_bundle(toolbar_button())
.with_children(|button| {
_ = button
.spawn_bundle(toolbar_button_text(&asset_server, button_type));
_ = button.spawn_bundle(toolbar_button_text(
julia_mono_handle.clone(),
button_type,
));
})
.insert(button_type)
});

View file

@ -1,11 +1,10 @@
#[cfg(feature = "render")]
use crate::{components::markers::ToolbarButton, NORMAL_BUTTON};
#[cfg(feature = "render")]
use bevy::{
asset::AssetServer,
ecs::system::Res,
use {
crate::{components::markers::ToolbarButton, NORMAL_BUTTON},
bevy::{
asset::Handle,
render::color::Color,
text::{Text, TextStyle},
text::{Font, Text, TextStyle},
ui::{
entity::{ButtonBundle, TextBundle},
widget::Button,
@ -14,6 +13,7 @@ use bevy::{
Style,
},
utils::default,
},
};
#[cfg(feature = "render")]
@ -31,15 +31,12 @@ pub(crate) fn toolbar_button() -> ButtonBundle {
}
#[cfg(feature = "render")]
pub(crate) fn toolbar_button_text(
asset_server: &Res<'_, AssetServer>,
which: ToolbarButton,
) -> TextBundle {
pub(crate) fn toolbar_button_text(font: Handle<Font>, which: ToolbarButton) -> TextBundle {
TextBundle {
text: Text::from_section(
which,
TextStyle {
font: asset_server.load("JuliaMono.ttf"),
font,
font_size: 20.0,
color: Color::WHITE,
},