Skip to content

Commit a9d3ca1

Browse files
committed
make ordering work with rust systems
1 parent e7f003f commit a9d3ca1

File tree

14 files changed

+470
-432
lines changed

14 files changed

+470
-432
lines changed

assets/tests/add_system/added_system_can_be_queried.lua

Lines changed: 0 additions & 9 deletions
This file was deleted.

assets/tests/add_system/adds_system.lua

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- add two systems, one before and one after the existing `on_test_post_update` callback, then assert all systems have run
2+
-- in the `on_test_last` callback
3+
4+
local runs = {}
5+
6+
-- runs on `Update`
7+
function on_test()
8+
local post_update_schedule = world.get_schedule_by_name("PostUpdate")
9+
10+
local test_system = post_update_schedule:get_system_by_name("on_test_post_update")
11+
12+
local system_after = world.add_system(
13+
post_update_schedule,
14+
system_builder("custom_system_after", script_id)
15+
:after(test_system)
16+
)
17+
18+
local system_before = world.add_system(
19+
post_update_schedule,
20+
system_builder("custom_system_before", script_id)
21+
:before(test_system)
22+
)
23+
end
24+
25+
26+
function custom_system_before()
27+
print("custom_system_before")
28+
runs[#runs + 1] = "custom_system_before"
29+
end
30+
31+
-- runs on post_update
32+
function on_test_post_update()
33+
print("on_test_post_update")
34+
runs[#runs + 1] = "on_test_post_update"
35+
end
36+
37+
function custom_system_after()
38+
print("custom_system_after")
39+
runs[#runs + 1] = "custom_system_after"
40+
end
41+
42+
-- runs in the `Last` bevy schedule
43+
function on_test_last()
44+
assert(#runs == 3, "Expected 3 runs, got: " .. #runs)
45+
assert(runs[1] == "custom_system_before", "Expected custom_system_before to run first, got: " .. runs[1])
46+
assert(runs[2] == "on_test_post_update", "Expected on_test_post_update to run second, got: " .. runs[2])
47+
assert(runs[3] == "custom_system_after", "Expected custom_system_after to run third, got: " .. runs[3])
48+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
let runs = [];
2+
3+
fn on_test() {
4+
let post_update_schedule = world.get_schedule_by_name.call("PostUpdate");
5+
let test_system = post_update_schedule.get_system_by_name.call("on_test_post_update");
6+
7+
let builder_after = system_builder.call("custom_system_after", script_id).after.call(test_system);
8+
let system_after = world.add_system.call(post_update_schedule, builder_after);
9+
10+
let builder_before = system_builder.call("custom_system_before", script_id).before.call(test_system);
11+
let system_before = world.add_system.call(post_update_schedule, builder_before);
12+
}
13+
14+
fn custom_system_before() {
15+
print("custom_system_before");
16+
runs.push("custom_system_before");
17+
}
18+
19+
fn on_test_post_update() {
20+
print("on_test_post_update");
21+
runs.push("on_test_post_update");
22+
}
23+
24+
fn custom_system_after() {
25+
print("custom_system_after");
26+
runs.push("custom_system_after");
27+
}
28+
29+
fn on_test_last() {
30+
assert(runs.len() == 3, "Expected 3 runs, got: " + runs.len().to_string());
31+
assert(runs[0] == "custom_system_before", "Expected custom_system_before to run first, got: " + runs[0]);
32+
assert(runs[1] == "on_test_post_update", "Expected on_test_post_update to run second, got: " + runs[1]);
33+
assert(runs[2] == "custom_system_after", "Expected custom_system_after to run third, got: " + runs[2]);
34+
}

assets/tests/rhai_tests.rs

Lines changed: 0 additions & 144 deletions
This file was deleted.
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
local schedule = world.get_schedule_by_name("Startup")
2-
local systems = schedule:systems()
1+
function on_test()
2+
local startup_schedule = world.get_schedule_by_name("Startup")
33

4-
-- contains event_handler system
5-
assert(#systems == 1, "Schedule does not contain all systems")
64

7-
assert(schedule:get_system_by_name("dummy_startup_system"):identifier() == "dummy_startup_system", "System identifier was wrong")
5+
local expected_systems = {
6+
"dummy_startup_system",
7+
}
8+
9+
for i, system in ipairs(expected_systems) do
10+
local found_system = startup_schedule:get_system_by_name(system)
11+
assert(found_system ~= nil, "Expected system not found: " .. system)
12+
end
13+
end
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
let schedule = world.get_schedule_by_name.call("Startup");
2-
let systems = schedule.systems.call();
1+
fn on_test() {
2+
let startup_schedule = world.get_schedule_by_name.call("Startup");
33

4-
assert(systems.len() == 1, "Schedule does not contain all systems");
5-
assert(schedule.get_system_by_name.call("dummy_startup_system").identifier.call() == "dummy_startup_system", "System identifier was wrong");
4+
5+
let expected_systems = [
6+
"dummy_startup_system"
7+
];
8+
9+
for system in expected_systems {
10+
let found_system = startup_schedule.get_system_by_name.call(system);
11+
assert(type_of(found_system) != "()", "Expected system not found: " + system);
12+
}
13+
}

crates/bevy_mod_scripting_core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ derivative = "2.2"
4141
profiling = { workspace = true }
4242
bevy_mod_scripting_derive = { workspace = true }
4343
fixedbitset = "0.5"
44+
petgraph = "0.6"
4445

4546
[dev-dependencies]
4647
test_utils = { workspace = true }

0 commit comments

Comments
 (0)