diff --git a/assets/scratch/BOUNCY GUM.ttf b/assets/scratch/BOUNCY GUM.ttf new file mode 100644 index 0000000..08cd35e Binary files /dev/null and b/assets/scratch/BOUNCY GUM.ttf differ diff --git a/assets/scratch/Death Spirit.ttf b/assets/scratch/Death Spirit.ttf new file mode 100644 index 0000000..df0f1ef Binary files /dev/null and b/assets/scratch/Death Spirit.ttf differ diff --git a/assets/scratch/JMH Typewriter-Black.otf b/assets/scratch/JMH Typewriter-Black.otf new file mode 100644 index 0000000..1eb4171 Binary files /dev/null and b/assets/scratch/JMH Typewriter-Black.otf differ diff --git a/assets/scratch/JMH Typewriter-Bold.otf b/assets/scratch/JMH Typewriter-Bold.otf new file mode 100644 index 0000000..e791089 Binary files /dev/null and b/assets/scratch/JMH Typewriter-Bold.otf differ diff --git a/assets/scratch/JMH Typewriter-Thin.otf b/assets/scratch/JMH Typewriter-Thin.otf new file mode 100644 index 0000000..4393a2f Binary files /dev/null and b/assets/scratch/JMH Typewriter-Thin.otf differ diff --git a/assets/scratch/JMH Typewriter.otf b/assets/scratch/JMH Typewriter.otf new file mode 100644 index 0000000..5ee4685 Binary files /dev/null and b/assets/scratch/JMH Typewriter.otf differ diff --git a/assets/scratch/a.monologue.txt b/assets/scratch/a.monologue.txt new file mode 100644 index 0000000..1e7b6d2 --- /dev/null +++ b/assets/scratch/a.monologue.txt @@ -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. + diff --git a/assets/scratch/b.monologue.txt b/assets/scratch/b.monologue.txt new file mode 100644 index 0000000..3fdb30d --- /dev/null +++ b/assets/scratch/b.monologue.txt @@ -0,0 +1 @@ +This is a placeholder monologue diff --git a/assets/scratch/foo/bar/baz/inspect.glb b/assets/scratch/foo/bar/baz/inspect.glb deleted file mode 100644 index b96f116..0000000 --- a/assets/scratch/foo/bar/baz/inspect.glb +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:976d82ec5c0039852a3f7e5991a60536b0c4050f7910bd55ca01e6b73fbdc8c9 -size 1244020 diff --git a/assets/scratch/materials.glb b/assets/scratch/materials.glb deleted file mode 100644 index e4262d9..0000000 --- a/assets/scratch/materials.glb +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8743ab5b1932c7546856cbfb8fd4afda6caaa35fdc4e728a06b86a9b563f6311 -size 265020 diff --git a/bin/editor.rs b/bin/editor.rs index 26b7c8a..248efa4 100644 --- a/bin/editor.rs +++ b/bin/editor.rs @@ -62,6 +62,7 @@ fn main() { )) .init_resource::() .insert_resource(AssetsDir::new("assets/scratch")) + .init_resource::() .add_event::() .add_asset::() .init_asset_loader::() @@ -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::), + clear_assets.run_if(ui::activated::), ), ) .add_systems( @@ -570,9 +572,13 @@ mod assets { let newpath = PathBuf::from(assets_dir.root.clone()).join(fname); IoTaskPool::get() .spawn(async move { - match copy(path, newpath) { - Ok(_) => info!("Created assets directory"), - Err(e) => warn!("Error creating assets directory {:?}", e), + 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(); @@ -580,7 +586,6 @@ mod assets { } 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,9 +616,13 @@ mod assets { info!("copying folder {:?} to {:?}", path.clone(), newpath); IoTaskPool::get() .spawn(async move { - match copy_dir(path.clone(), newpath) { - Ok(_) => info!("Created assets directory"), - Err(e) => warn!("Error creating assets directory {:?}", e), + 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(); @@ -621,17 +630,13 @@ mod assets { } pub fn reload_assets( - mut events: EventReader, server: Res, mut registry: ResMut, assets_dir: Res, ) { - // 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"); - } + registry.0 = server + .load_folder(assets_dir.root.clone()) + .expect("Reload assets folder"); } pub fn get_asset_name(server: &AssetServer, handle: Handle) -> String { @@ -1076,6 +1081,11 @@ mod fonts { #[derive(Debug, Component, Default)] pub struct FontWidget; + #[derive(Debug, Resource, Default)] + pub struct FontInfo { + pub default: Option>, + } + pub fn fonts_ui( mut events: EventReader>, mut commands: Commands, @@ -1127,6 +1137,15 @@ mod fonts { } }); } + + pub fn set_active_font( + events: Query<&ui::TargetAsset, Added>, + mut font: ResMut, + ) { + events + .iter() + .for_each(|ui::TargetAsset { handle }| font.default = Some(handle.clone())); + } } use monologues::*; @@ -1250,6 +1269,7 @@ mod monologues { monologues: Res>, container: Query>, mut commands: Commands, + font: Res, ) { added .iter() @@ -1286,15 +1306,21 @@ mod monologues { }, ui::Sorting(0), )); + 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(), - TextStyle { - color: Color::BLACK.into(), - font_size: 16.0, - ..default() - }, - ), + TextBundle::from_section(monologue.text.clone(), style), handle.clone(), )); }); @@ -1304,16 +1330,19 @@ mod monologues { // TODO: Sync Handle and TextStyle components to automagically generate and sync text pub fn sync_monologue_font( - events: Query<&ui::TargetAsset, Added>, mut texts: Query<&mut Text, With>>, + font: Res, ) { - 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(), + }); }); - }); + } } } @@ -1448,7 +1477,6 @@ mod reset { pub struct ClearAssets; pub fn clear_assets( - events: Query, Added)>, asset_holders: Query< Entity, Or<( @@ -1469,16 +1497,14 @@ mod reset { mut registry: ResMut, mut commands: Commands, ) { - events.iter().for_each(|_| { - info!("Clearing assets"); + info!("Clearing assets"); - // Clear buttons holding asset references - asset_holders - .iter() - .for_each(|entity| commands.entity(entity).despawn_recursive()); + // Clear buttons holding asset references + asset_holders + .iter() + .for_each(|entity| commands.entity(entity).despawn_recursive()); - // Empty asset registry - registry.0.clear(); - }) + // Empty asset registry + registry.0.clear(); } } diff --git a/src/ui.rs b/src/ui.rs index 7d30120..5cfe4d6 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -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(events: Query, Added)>) -> bool { + events.iter().any(|_| true) + } + + pub fn event(mut events: EventReader) -> bool { + events.iter().len() > 0 + } } pub use scroll::*;