fixing fonts and font resource

main
Elijah Voigt 2 years ago
parent 5294f64946
commit a82126cc6b

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,10 @@
Voluptatem culpa quo quia alias minima amet. Consequatur fugit et vitae qui dolor. Aut ea dolorum dicta quas ex et recusandae et. Nostrum eos quia quis est consequuntur.
Ratione facilis aliquid et. Dolores expedita magni suscipit minima. Voluptatem in pariatur vitae laboriosam aliquam non ducimus. Laudantium illum provident et libero assumenda et sunt similique. Corporis tenetur repellat enim perferendis ut minus omnis.
Blanditiis vitae quae ut ipsum consequatur. Ratione dignissimos exercitationem autem accusamus. Qui molestiae ipsam pariatur quis amet quia voluptate sunt. In voluptate dolorum in quia. Sit ut non voluptatem qui placeat quis. Ducimus ipsa adipisci eligendi dolor id.
Ex totam nam laudantium quis. Omnis saepe mollitia eligendi unde rerum. Odit voluptatum repellat rem est iure neque saepe.
Nulla est consequatur sint amet nesciunt quam. Qui fuga excepturi veritatis quia. Saepe natus et enim eveniet voluptates velit quod sint. Dolores reprehenderit eligendi aut. Et voluptate ea aliquam.

@ -0,0 +1 @@
This is a placeholder monologue

BIN
assets/scratch/foo/bar/baz/inspect.glb (Stored with Git LFS)

Binary file not shown.

BIN
assets/scratch/materials.glb (Stored with Git LFS)

Binary file not shown.

@ -62,6 +62,7 @@ fn main() {
))
.init_resource::<AssetRegistry>()
.insert_resource(AssetsDir::new("assets/scratch"))
.init_resource::<FontInfo>()
.add_event::<ImportAsset>()
.add_asset::<Monologue>()
.init_asset_loader::<MonologueLoader>()
@ -86,13 +87,14 @@ fn main() {
Update,
(
gltf_ui,
fonts_ui,
texts_ui,
control_active_gltf,
show_preview_text,
sync_monologue_font,
),
)
.add_systems(Update, (fonts_ui, set_active_font))
.add_systems(Startup, reload_assets)
.add_systems(
Update,
(
@ -100,8 +102,8 @@ fn main() {
import_assets,
import_file,
import_folder,
reload_assets,
clear_assets,
reload_assets.run_if(ui::event::<ImportAsset>),
clear_assets.run_if(ui::activated::<ClearAssets>),
),
)
.add_systems(
@ -570,17 +572,20 @@ mod assets {
let newpath = PathBuf::from(assets_dir.root.clone()).join(fname);
IoTaskPool::get()
.spawn(async move {
if path == newpath {
info!("Skipping copying {:?} to itself {:?}", path, newpath);
} else {
match copy(path, newpath) {
Ok(_) => info!("Created assets directory"),
Err(e) => warn!("Error creating assets directory {:?}", e),
}
}
})
.detach();
});
}
fn copy_dir(from: PathBuf, to: PathBuf) -> std::io::Result<()> {
info!("Copy dir {:?} -> {:?}", from, to);
if let Ok(entries) = read_dir(from) {
for entry in entries.filter_map(|e| e.ok()) {
if entry.path().is_file() {
@ -611,28 +616,28 @@ mod assets {
info!("copying folder {:?} to {:?}", path.clone(), newpath);
IoTaskPool::get()
.spawn(async move {
if path.clone() == newpath {
info!("Skipping copying {:?} to itself {:?}", path, newpath);
} else {
match copy_dir(path.clone(), newpath) {
Ok(_) => info!("Created assets directory"),
Err(e) => warn!("Error creating assets directory {:?}", e),
}
}
})
.detach();
});
}
pub fn reload_assets(
mut events: EventReader<ImportAsset>,
server: Res<AssetServer>,
mut registry: ResMut<AssetRegistry>,
assets_dir: Res<AssetsDir>,
) {
// Reduce all import events in a frame to one "load_folder" action
if events.iter().len() > 0 {
registry.0 = server
.load_folder(assets_dir.root.clone())
.expect("Reload assets folder");
}
}
pub fn get_asset_name<T: Asset>(server: &AssetServer, handle: Handle<T>) -> String {
if let Some(asset_path) = server.get_handle_path(handle.clone()) {
@ -1076,6 +1081,11 @@ mod fonts {
#[derive(Debug, Component, Default)]
pub struct FontWidget;
#[derive(Debug, Resource, Default)]
pub struct FontInfo {
pub default: Option<Handle<Font>>,
}
pub fn fonts_ui(
mut events: EventReader<AssetEvent<Font>>,
mut commands: Commands,
@ -1127,6 +1137,15 @@ mod fonts {
}
});
}
pub fn set_active_font(
events: Query<&ui::TargetAsset<Font>, Added<ui::Active>>,
mut font: ResMut<FontInfo>,
) {
events
.iter()
.for_each(|ui::TargetAsset { handle }| font.default = Some(handle.clone()));
}
}
use monologues::*;
@ -1250,6 +1269,7 @@ mod monologues {
monologues: Res<Assets<Monologue>>,
container: Query<Entity, With<MonologueContainer>>,
mut commands: Commands,
font: Res<FontInfo>,
) {
added
.iter()
@ -1286,15 +1306,21 @@ mod monologues {
},
ui::Sorting(0),
));
parent.spawn((
TextBundle::from_section(
monologue.text.clone(),
TextStyle {
let style = match &font.default {
Some(handle) => TextStyle {
color: Color::BLACK.into(),
font_size: 16.0,
font: handle.clone(),
..default()
},
),
None => TextStyle {
color: Color::BLACK.into(),
font_size: 16.0,
..default()
},
};
parent.spawn((
TextBundle::from_section(monologue.text.clone(), style),
handle.clone(),
));
});
@ -1304,18 +1330,21 @@ mod monologues {
// TODO: Sync Handle<Monologue> and TextStyle components to automagically generate and sync text
pub fn sync_monologue_font(
events: Query<&ui::TargetAsset<Font>, Added<ui::Active>>,
mut texts: Query<&mut Text, With<Handle<Monologue>>>,
font: Res<FontInfo>,
) {
events.iter().for_each(|ui::TargetAsset { handle }| {
if font.is_changed() || font.is_added() {
texts.iter_mut().for_each(|mut text| {
text.sections.iter_mut().for_each(|section| {
section.style.font = handle.clone();
});
text.sections
.iter_mut()
.for_each(|section| match &font.default {
Some(handle) => section.style.font = handle.clone(),
None => section.style.font = Handle::default(),
});
});
}
}
}
use cameras::*;
mod cameras {
@ -1448,7 +1477,6 @@ mod reset {
pub struct ClearAssets;
pub fn clear_assets(
events: Query<Entity, (With<ClearAssets>, Added<ui::Active>)>,
asset_holders: Query<
Entity,
Or<(
@ -1469,7 +1497,6 @@ mod reset {
mut registry: ResMut<AssetRegistry>,
mut commands: Commands,
) {
events.iter().for_each(|_| {
info!("Clearing assets");
// Clear buttons holding asset references
@ -1479,6 +1506,5 @@ mod reset {
// Empty asset registry
registry.0.clear();
})
}
}

@ -252,14 +252,22 @@ mod title {
events.iter().for_each(|(title, note, children)| {
children.iter().for_each(|child| {
if let Ok(mut text) = texts.get_mut(*child) {
let style = match &title.font {
Some(handle) => TextStyle {
color: Color::BLACK,
font: handle.clone(),
..default()
},
None => TextStyle {
color: Color::BLACK,
..default()
},
};
*text = Text {
sections: vec![
TextSection {
value: title.text.clone(),
style: TextStyle {
color: Color::BLACK,
..default()
},
style: style,
},
TextSection {
value: note
@ -475,6 +483,15 @@ mod buttons {
});
});
}
/// run_if helper for simple button->trigger action
pub fn activated<T: Component>(events: Query<Entity, (With<T>, Added<Active>)>) -> bool {
events.iter().any(|_| true)
}
pub fn event<T: Event>(mut events: EventReader<T>) -> bool {
events.iter().len() > 0
}
}
pub use scroll::*;

Loading…
Cancel
Save