Skip to content
Snippets Groups Projects
Commit 9f148a36 authored by StarArawn's avatar StarArawn
Browse files

Added query_world function that behaves a bit like a system.

parent 347f5b35
No related branches found
No related tags found
No related merge requests found
...@@ -1841,6 +1841,7 @@ name = "kayak_core" ...@@ -1841,6 +1841,7 @@ name = "kayak_core"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"as-any", "as-any",
"bevy",
"derivative", "derivative",
"flo_binding", "flo_binding",
"kayak_render_macros", "kayak_render_macros",
......
...@@ -9,7 +9,12 @@ members = ["bevy_kayak_ui", "kayak_core", "kayak_render_macros", "kayak_font"] ...@@ -9,7 +9,12 @@ members = ["bevy_kayak_ui", "kayak_core", "kayak_render_macros", "kayak_font"]
[features] [features]
default = ["bevy_renderer"] default = ["bevy_renderer"]
bevy_renderer = ["bevy_kayak_ui", "kayak_font", "bevy"] bevy_renderer = [
"bevy_kayak_ui",
"kayak_font",
"kayak_core/bevy_renderer",
"bevy",
]
[dependencies] [dependencies]
bevy = { git = "https://github.com/bevyengine/bevy", rev = "9a16a4d01830297987db40b45f03382ed3acad62", optional = true } bevy = { git = "https://github.com/bevyengine/bevy", rev = "9a16a4d01830297987db40b45f03382ed3acad62", optional = true }
......
...@@ -12,17 +12,8 @@ struct GlobalCount(pub u32); ...@@ -12,17 +12,8 @@ struct GlobalCount(pub u32);
#[widget] #[widget]
fn Counter(context: &mut KayakContext) { fn Counter(context: &mut KayakContext) {
let global_count = { let global_count = context
if let Ok(world) = context.get_global_state::<World>() { .query_world::<Res<Binding<GlobalCount>>, _, _>(move |global_count| global_count.clone());
if let Some(global_count) = world.get_resource::<Binding<GlobalCount>>() {
global_count.clone()
} else {
return;
}
} else {
return;
}
};
context.bind(&global_count); context.bind(&global_count);
......
...@@ -7,10 +7,12 @@ edition = "2021" ...@@ -7,10 +7,12 @@ edition = "2021"
[features] [features]
default = [] default = []
bevy_renderer = ["bevy"]
[dependencies] [dependencies]
as-any = "0.2" as-any = "0.2"
derivative = "2.2" derivative = "2.2"
bevy = { git = "https://github.com/bevyengine/bevy", rev = "9a16a4d01830297987db40b45f03382ed3acad62", optional = true }
flo_binding = { git = "https://github.com/StarArawn/flo_binding.git", rev = "c78431a56df5ec082b7e1c271871e6c0ac75e81e" } flo_binding = { git = "https://github.com/StarArawn/flo_binding.git", rev = "c78431a56df5ec082b7e1c271871e6c0ac75e81e" }
kayak_render_macros = { path = "../kayak_render_macros" } kayak_render_macros = { path = "../kayak_render_macros" }
morphorm = { git = "https://github.com/geom3trik/morphorm", rev = "1243152d4cebea46fd3e5098df26402c73acae91" } morphorm = { git = "https://github.com/geom3trik/morphorm", rev = "1243152d4cebea46fd3e5098df26402c73acae91" }
......
...@@ -528,4 +528,20 @@ impl KayakContext { ...@@ -528,4 +528,20 @@ impl KayakContext {
self.get_all_parents(*parent, parents); self.get_all_parents(*parent, parents);
} }
} }
#[cfg(feature = "bevy_renderer")]
pub fn query_world<T: bevy::ecs::system::SystemParam, F, R>(&mut self, mut f: F) -> R
where
F: FnMut(<T::Fetch as bevy::ecs::system::SystemParamFetch<'_, '_>>::Item) -> R,
{
let mut world = self.get_global_state::<bevy::prelude::World>().unwrap();
let mut system_state = bevy::ecs::system::SystemState::<T>::new(&mut world);
let r = {
let test = system_state.get_mut(&mut world);
f(test)
};
system_state.apply(&mut world);
r
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment