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::{
asset::{Assets, HandleId},
render::render_resource::Extent3d,
render::{color::Color, texture::Image},
use {
crate::TerrainCell,
bevy::{
asset::{Assets, HandleId},
render::render_resource::Extent3d,
render::{color::Color, texture::Image},
},
};
use {
crate::{Biome, World, WorldGenError},

View file

@ -47,62 +47,62 @@ use bevy::{
render::mesh::{shape::Icosphere, Mesh},
transform::components::Transform,
};
#[cfg(feature = "render")]
use bevy::{
asset::{AssetServer, Assets},
core_pipeline::core_2d::{Camera2d, Camera2dBundle},
ecs::{
change_detection::ResMut,
query::{Changed, With},
system::{Commands, Query, Res},
},
hierarchy::BuildChildren,
prelude::Vec2,
render::{
camera::{Camera, RenderTarget},
color::Color,
render_resource::{
Extent3d,
TextureDescriptor,
TextureDimension,
TextureFormat,
TextureUsages,
},
texture::{Image, ImageSettings},
},
sprite::{Sprite, SpriteBundle},
text::Text,
transform::components::GlobalTransform,
ui::{
entity::{NodeBundle, TextBundle},
AlignSelf,
FocusPolicy,
Interaction,
JustifyContent,
PositionType,
Size,
Style,
UiColor,
UiRect,
Val,
},
window::{CursorIcon, WindowDescriptor, Windows},
winit::WinitSettings,
};
#[cfg(all(feature = "debug", feature = "render"))]
use bevy::{
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
log::debug,
};
#[cfg(feature = "render")]
use components::{
markers::{InfoPanel, ToolbarButton},
third_party::PanCam,
use {
bevy::text::Font,
bevy::{
asset::Assets,
core_pipeline::core_2d::{Camera2d, Camera2dBundle},
ecs::{
change_detection::ResMut,
query::{Changed, With},
system::{Commands, Query, Res},
},
hierarchy::BuildChildren,
prelude::Vec2,
render::{
camera::{Camera, RenderTarget},
color::Color,
render_resource::{
Extent3d,
TextureDescriptor,
TextureDimension,
TextureFormat,
TextureUsages,
},
texture::{Image, ImageSettings},
},
sprite::{Sprite, SpriteBundle},
text::Text,
transform::components::GlobalTransform,
ui::{
entity::{NodeBundle, TextBundle},
AlignSelf,
FocusPolicy,
Interaction,
JustifyContent,
PositionType,
Size,
Style,
UiColor,
UiRect,
Val,
},
window::{CursorIcon, WindowDescriptor, Windows},
winit::WinitSettings,
},
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,19 +1,19 @@
#[cfg(feature = "render")]
use crate::{components::markers::ToolbarButton, NORMAL_BUTTON};
#[cfg(feature = "render")]
use bevy::{
asset::AssetServer,
ecs::system::Res,
render::color::Color,
text::{Text, TextStyle},
ui::{
entity::{ButtonBundle, TextBundle},
widget::Button,
AlignItems,
JustifyContent,
Style,
use {
crate::{components::markers::ToolbarButton, NORMAL_BUTTON},
bevy::{
asset::Handle,
render::color::Color,
text::{Font, Text, TextStyle},
ui::{
entity::{ButtonBundle, TextBundle},
widget::Button,
AlignItems,
JustifyContent,
Style,
},
utils::default,
},
utils::default,
};
#[cfg(feature = "render")]
@ -31,17 +31,14 @@ 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,
color: Color::WHITE,
},
),
..default()