diff --git a/Cargo.lock b/Cargo.lock index 0632cf242..494441dee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -726,6 +726,21 @@ dependencies = [ "wgpu-types", ] +[[package]] +name = "bevy_common_assets" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f631ce2863f3b6f1af3fa24143363b9fbd21c44218caad495a17b83e6968256" +dependencies = [ + "anyhow", + "bevy", + "serde", + "serde_json", + "serde_yaml", + "thiserror", + "toml 0.8.14", +] + [[package]] name = "bevy_core" version = "0.14.0" @@ -4773,6 +4788,7 @@ version = "0.19.0" dependencies = [ "bevy", "bevy-inspector-egui", + "bevy_common_assets", "bevy_egui", "bevy_nannou", "find_folder", @@ -4788,10 +4804,10 @@ dependencies = [ "pennereq", "rusttype", "serde", - "serde_derive", "serde_json", + "serde_yaml", "tokio 1.38.0", - "toml 0.5.11", + "toml 0.8.14", "walkdir", "web-sys", ] @@ -6962,6 +6978,19 @@ dependencies = [ "url 1.7.2", ] +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap 2.2.6", + "itoa 1.0.11", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "set_version" version = "0.1.0" @@ -7927,6 +7956,12 @@ dependencies = [ "void", ] +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + [[package]] name = "url" version = "1.7.2" diff --git a/Cargo.toml b/Cargo.toml index 7ffd5a00e..466feb01c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,4 +26,9 @@ resolver = "2" bevy = "0.14.0" bevy_egui = "0.28.0" bevy-inspector-egui = "0.25.0" -rayon = "1.10" \ No newline at end of file +rayon = "1.10" +bevy_common_assets = "0.11.0" +serde = "1" +serde_json = "1" +toml = "0.8" +serde_yaml = "0.9" \ No newline at end of file diff --git a/nannou/Cargo.toml b/nannou/Cargo.toml index 52cbb31b3..2f2656170 100644 --- a/nannou/Cargo.toml +++ b/nannou/Cargo.toml @@ -14,23 +14,23 @@ edition = "2018" bevy = { workspace = true } bevy-inspector-egui = { workspace = true, optional = true } bevy_egui = { workspace = true, optional = true } - +bevy_common_assets = { workspace = true, optional = true } bevy_nannou = { version = "0.1.0", path = "../bevy_nannou" } futures = "0.3" find_folder = "0.3" getrandom = "0.2.3" instant = "0.1.9" lyon = "1.0" -nannou_core = { version ="0.19.0", path = "../nannou_core", features = ["std", "serde"] } +nannou_core = { version ="0.19.0", path = "../nannou_core", features = ["std"] } noise = "0.7" notosans = { version = "0.1", optional = true } num_cpus = "1" pennereq = "0.3" rusttype = { version = "0.8", features = ["gpu_cache"] } -serde = "1" -serde_derive = "1" -serde_json = "1" -toml = "0.5" +serde = { workspace = true, features = ["derive"], optional = true} +serde_json = { workspace = true, optional = true } +toml = { workspace = true, optional = true } +serde_yaml = { workspace = true, optional = true } walkdir = "2" web-sys = { version = "0.3.64", optional = true } @@ -47,4 +47,5 @@ egui = ["bevy_egui", "bevy-inspector-egui"] nightly = ["bevy_nannou/nightly"] hot_reload = ["bevy/file_watcher"] isf = ["bevy_nannou/isf"] -video = ["bevy_nannou/video"] \ No newline at end of file +video = ["bevy_nannou/video"] +serde = ["dep:serde", "toml", "serde_json", "serde_yaml", "nannou_core/serde", "bevy_common_assets/json", "bevy_common_assets/toml", "bevy_common_assets/yaml"] \ No newline at end of file diff --git a/nannou/src/app.rs b/nannou/src/app.rs index c88c1563e..e43370377 100644 --- a/nannou/src/app.rs +++ b/nannou/src/app.rs @@ -309,6 +309,19 @@ where self } + #[cfg(feature = "serde")] + pub fn init_config(mut self) -> Self + where + for<'de> T: serde::Deserialize<'de> + Asset, + { + self.app.add_plugins(( + bevy_common_assets::json::JsonAssetPlugin::::new(&[".json"]), + bevy_common_assets::toml::TomlAssetPlugin::::new(&[".toml"]), + bevy_common_assets::yaml::YamlAssetPlugin::::new(&[".yaml", ".yml"]), + )); + self + } + pub fn add_plugin

(mut self, plugin: P) -> Self where P: Plugin, @@ -571,7 +584,7 @@ impl<'w> App<'w> { #[cfg(feature = "egui")] /// Get the egui context for the provided window. pub fn egui_for_window(&self, window: Entity) -> RefMut { - let world = self.resource_world_mut(); + let world = self.component_world_mut(); RefMut::map(world, |world| { world .get_mut::(window) @@ -614,12 +627,18 @@ impl<'w> App<'w> { keyboard_input.clone() } - /// Get the [`Time`] resource. + /// Get the elapsed seconds since startup. pub fn time(&self) -> f32 { let time = self.resource::