Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,944 changes: 1,150 additions & 794 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ repository = "https://github.com/databasedav/jonmo"
documentation = "https://docs.rs/jonmo"

[dependencies]
bevy_app = { version = "0.18", default-features = false }
bevy_derive = { version = "0.18", default-features = false }
bevy_diagnostic = { version = "0.18", default-features = false }
bevy_ecs = { version = "0.18", default-features = false }
bevy_platform = { version = "0.18", default-features = false }
bevy_log = { version = "0.18", default-features = false, optional = true }
bevy_time = { version = "0.18", default-features = false, optional = true }
bevy_app = { version = "0.19", default-features = false }
bevy_derive = { version = "0.19", default-features = false }
bevy_diagnostic = { version = "0.19", default-features = false }
bevy_ecs = { version = "0.19", default-features = false }
bevy_platform = { version = "0.19", default-features = false }
bevy_log = { version = "0.19", default-features = false, optional = true }
bevy_time = { version = "0.19", default-features = false, optional = true }
enclose = "1.2"
dyn-clone = "1.0"
apply = "=0.3.0" # locked because last released in 2020
Expand Down Expand Up @@ -64,7 +64,7 @@ web = [
deployed_wasm_example = []

[dev-dependencies]
bevy = { version = "0.18", features = ["track_location"] }
bevy = { version = "0.19", features = ["track_location"] }
rand = "0.9"
test-log = { version = "0.2", default-features = false, features = ["trace"] }

Expand Down
6 changes: 3 additions & 3 deletions examples/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn ui(items: MutableVec<Data>, rows: MutableVec<()>) -> jonmo::Builder {
Text::new("source"),
TextColor(Color::WHITE),
TextFont::from_font_size(30.),
TextLayout::new_with_justify(Justify::Center),
TextLayout::justify(Justify::Center),
)))
.child(button("+", -2.).observe(
|_: On<Pointer<Click>>, datas: Res<Datas>, mut mutable_vec_datas: Query<&mut MutableVecData<_>>| {
Expand Down Expand Up @@ -210,7 +210,7 @@ fn text_node(text: &'static str) -> jonmo::Builder {
},
Text::new(text),
TextColor(Color::WHITE),
TextLayout::new_with_justify(Justify::Center),
TextLayout::justify(Justify::Center),
))
}

Expand Down Expand Up @@ -510,7 +510,7 @@ fn item(index: impl Signal<Item = Option<usize>>, Data { number, color, shape }:
Node::default(),
Text::new(number.to_string()),
TextColor(Color::BLACK),
TextLayout::new_with_justify(Justify::Center),
TextLayout::justify(Justify::Center),
))
}

Expand Down
2 changes: 1 addition & 1 deletion examples/letters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn text_node() -> jonmo::Builder {
..default()
},
TextColor(Color::WHITE),
TextLayout::new_with_justify(Justify::Center),
TextLayout::justify(Justify::Center),
))
}

Expand Down
6 changes: 3 additions & 3 deletions examples/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn ui_root(colors: impl SignalVec<Item = Color>) -> jonmo::Builder {
Node::default(),
Text::new("+"),
TextColor(Color::WHITE),
TextLayout::new_with_justify(Justify::Center),
TextLayout::justify(Justify::Center),
))),
)
}
Expand Down Expand Up @@ -202,7 +202,7 @@ fn item(index: impl Signal<Item = Option<usize>> + Clone, color: Color) -> jonmo
// Start with a `Text` component with no sections. We'll add them as children.
Text::new(""),
TextColor(Color::BLACK), // Default color, can be overridden by children.
TextLayout::new_with_justify(Justify::Center),
TextLayout::justify(Justify::Center),
))
// Child 1: A static text span.
.child((TextColor(Color::BLACK), TextSpan::new("item ")))
Expand Down Expand Up @@ -281,7 +281,7 @@ fn item(index: impl Signal<Item = Option<usize>> + Clone, color: Color) -> jonmo
Node::default(),
Text::new("x"),
TextColor(Color::WHITE),
TextLayout::new_with_justify(Justify::Center),
TextLayout::justify(Justify::Center),
))),
)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn item(number: i32) -> jonmo::Builder {
},
Text(number.to_string()),
TextColor(Color::BLACK),
TextLayout::new_with_justify(Justify::Center),
TextLayout::justify(Justify::Center),
Lifetime::default(),
)))
}
Expand Down
2 changes: 1 addition & 1 deletion examples/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ cfg_if::cfg_if! {

fn toggle_overlay(
input: Res<ButtonInput<KeyCode>>,
mut options: ResMut<UiDebugOptions>,
mut options: ResMut<GlobalUiDebugOptions>,
) {
if input.just_pressed(OVERLAY_TOGGLE_KEY) {
options.toggle();
Expand Down
7 changes: 6 additions & 1 deletion src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,12 @@ fn rebuild_levels(world: &mut World, state: &mut SignalGraphState) {
state.signal_schedules.clear();

let mut all_signals_state = SystemState::<Query<Entity, With<SystemRunner>>>::new(world);
let all_signals: HashSet<SignalSystem> = all_signals_state.get(world).iter().map(SignalSystem).collect();
let all_signals: HashSet<SignalSystem> = all_signals_state
.get(world)
.expect("query params are always valid")
.iter()
.map(SignalSystem)
.collect();

let result = compute_signal_levels(
world,
Expand Down
71 changes: 38 additions & 33 deletions src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,9 +2118,9 @@ pub trait SignalExt: Signal {

// Synchronously send the initial `Replace` diff.
let mut upstreams = SystemState::<Query<&Upstream>>::new(world);
let upstreams = upstreams.get(world);
let upstreams = upstreams.get(world).expect("query params are always valid");
let upstreams = UpstreamIter::new(&upstreams, new_signal).collect::<Vec<_>>();
for signal in [new_signal].into_iter().chain(upstreams.into_iter()) {
for signal in [new_signal].into_iter().chain(upstreams) {
let entity = *signal;
if world.get::<super::signal_vec::VecReplayTrigger>(entity).is_some() {
world.entity_mut(entity).insert(ReplayOnce);
Expand Down Expand Up @@ -2248,9 +2248,9 @@ pub trait SignalExt: Signal {

// Synchronously send the initial `Replace` diff.
let mut upstreams = SystemState::<Query<&Upstream>>::new(world);
let upstreams = upstreams.get(world);
let upstreams = upstreams.get(world).expect("query params are always valid");
let upstreams = UpstreamIter::new(&upstreams, new_signal).collect::<Vec<_>>();
for signal in [new_signal].into_iter().chain(upstreams.into_iter()) {
for signal in [new_signal].into_iter().chain(upstreams) {
let entity = *signal;
if world.get::<super::signal_map::MapReplayTrigger>(entity).is_some() {
world.entity_mut(entity).insert(ReplayOnce);
Expand Down Expand Up @@ -3473,10 +3473,12 @@ mod tests {
use core::time::Duration;
use test_log::test;

// Helper component and resource for testing Add Default
#[derive(Component, Clone, Debug, PartialEq, Reflect, Default, Resource)]
#[derive(Component, Clone, Debug, PartialEq, Reflect, Default)]
struct TestData(i32);

#[derive(Resource, Clone, Debug, PartialEq, Reflect, Default)]
struct TestResource(i32);

#[derive(Resource, Default, Debug)]
struct SignalOutput<T: Send + Sync + 'static + Clone + fmt::Debug>(Option<T>);

Expand Down Expand Up @@ -5464,26 +5466,26 @@ mod tests {
#[test]
fn test_builder_from_resource() {
let mut app = create_test_app();
app.init_resource::<SignalOutput<TestData>>();
app.init_resource::<SignalOutput<TestResource>>();

// Test resource exists
app.insert_resource(TestData(42));
let signal_with = signal::from_resource::<TestData>()
app.insert_resource(TestResource(42));
let signal_with = signal::from_resource::<TestResource>()
.map(capture_output)
.register(app.world_mut());
app.update();
assert_eq!(get_output::<TestData>(app.world()), Some(TestData(42)));
assert_eq!(get_output::<TestResource>(app.world()), Some(TestResource(42)));
signal_with.cleanup(app.world_mut());

// Test resource missing
app.world_mut().resource_mut::<SignalOutput<TestData>>().0 = None;
app.world_mut().remove_resource::<TestData>();
let signal_without = signal::from_resource::<TestData>()
app.world_mut().resource_mut::<SignalOutput<TestResource>>().0 = None;
app.world_mut().remove_resource::<TestResource>();
let signal_without = signal::from_resource::<TestResource>()
.map(capture_output)
.register(app.world_mut());
app.update();
assert_eq!(
get_output::<TestData>(app.world()),
get_output::<TestResource>(app.world()),
None,
"Should terminate when resource is missing"
);
Expand All @@ -5493,25 +5495,28 @@ mod tests {
#[test]
fn test_builder_from_resource_option() {
let mut app = create_test_app();
app.init_resource::<SignalOutput<Option<TestData>>>();
app.init_resource::<SignalOutput<Option<TestResource>>>();

// Test resource exists
app.insert_resource(TestData(42));
let signal_with = signal::from_resource_option::<TestData>()
app.insert_resource(TestResource(42));
let signal_with = signal::from_resource_option::<TestResource>()
.map(capture_output)
.register(app.world_mut());
app.update();
assert_eq!(get_output::<Option<TestData>>(app.world()), Some(Some(TestData(42))));
assert_eq!(
get_output::<Option<TestResource>>(app.world()),
Some(Some(TestResource(42)))
);
signal_with.cleanup(app.world_mut());

// Test resource missing
app.world_mut().remove_resource::<TestData>();
let signal_without = signal::from_resource_option::<TestData>()
app.world_mut().remove_resource::<TestResource>();
let signal_without = signal::from_resource_option::<TestResource>()
.map(capture_output)
.register(app.world_mut());
app.update();
assert_eq!(
get_output::<Option<TestData>>(app.world()),
get_output::<Option<TestResource>>(app.world()),
Some(None),
"Should output Some(None) when resource is missing"
);
Expand Down Expand Up @@ -5601,43 +5606,43 @@ mod tests {
#[test]
fn test_builder_from_resource_changed() {
let mut app = create_test_app();
app.init_resource::<SignalOutput<TestData>>();
app.init_resource::<SignalOutput<TestResource>>();

// Insert resource
app.insert_resource(TestData(42));
let signal = signal::from_resource_changed::<TestData>()
app.insert_resource(TestResource(42));
let signal = signal::from_resource_changed::<TestResource>()
.map(capture_output)
.register(app.world_mut());

// First update should emit because resource was just added (Changed)
app.update();
assert_eq!(get_output::<TestData>(app.world()), Some(TestData(42)));
assert_eq!(get_output::<TestResource>(app.world()), Some(TestResource(42)));

// Clear output and update again - should NOT emit because nothing changed
app.world_mut().resource_mut::<SignalOutput<TestData>>().0 = None;
app.world_mut().resource_mut::<SignalOutput<TestResource>>().0 = None;
app.update();
assert_eq!(
get_output::<TestData>(app.world()),
get_output::<TestResource>(app.world()),
None,
"Should terminate when resource has not changed"
);

// Mutate the resource and update - should emit
app.world_mut().resource_mut::<TestData>().0 = 100;
app.world_mut().resource_mut::<TestResource>().0 = 100;
app.update();
assert_eq!(get_output::<TestData>(app.world()), Some(TestData(100)));
assert_eq!(get_output::<TestResource>(app.world()), Some(TestResource(100)));

signal.cleanup(app.world_mut());

// Test resource missing
app.world_mut().resource_mut::<SignalOutput<TestData>>().0 = None;
app.world_mut().remove_resource::<TestData>();
let signal_without = signal::from_resource_changed::<TestData>()
app.world_mut().resource_mut::<SignalOutput<TestResource>>().0 = None;
app.world_mut().remove_resource::<TestResource>();
let signal_without = signal::from_resource_changed::<TestResource>()
.map(capture_output)
.register(app.world_mut());
app.update();
assert_eq!(
get_output::<TestData>(app.world()),
get_output::<TestResource>(app.world()),
None,
"Should terminate when resource is missing"
);
Expand Down