Skip to content

Commit 48c7242

Browse files
makspllshanecelisalexparlett
authored
feat!: Use the Handles, Luke! (#427) (#444)
Co-authored-by: Shane Celis <[email protected]> Co-authored-by: Alex Parlett <[email protected]>
1 parent c433e18 commit 48c7242

File tree

89 files changed

+4874
-2547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+4874
-2547
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ bevy_mod_scripting_derive = { workspace = true }
8282

8383
[workspace.dependencies]
8484
profiling = { version = "1.0" }
85+
8586
bevy = { version = "0.16.0", default-features = false }
8687
bevy_math = { version = "0.16.0" }
8788
bevy_reflect = { version = "0.16.0" }

assets/reload.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- reload.lua
2+
--
3+
-- An example of the script reload feature. Exercise with this command:
4+
-- ```sh
5+
-- cargo run --features lua54,bevy/file_watcher,bevy/multi_threaded --example run-script -- reload.lua
6+
-- ```
7+
function on_script_loaded()
8+
world.info("Hello world")
9+
end
10+
11+
function on_script_unloaded()
12+
world.info("Goodbye world")
13+
return "house"
14+
end
15+
16+
function on_script_reloaded(value)
17+
if value then
18+
world.info("I'm back. Thanks for the "..value.." keys!")
19+
else
20+
world.info('I have not saved any state before unloading')
21+
end
22+
end
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1-
21
function on_test()
3-
local post_update_schedule = world.get_schedule_by_name("PostUpdate")
4-
5-
local test_system = post_update_schedule:get_system_by_name("on_test_post_update")
6-
7-
local system_a = world.add_system(
8-
post_update_schedule,
9-
system_builder("custom_system_a", script_id)
10-
:after(test_system)
11-
)
12-
13-
local system_b = world.add_system(
14-
post_update_schedule,
15-
system_builder("custom_system_b", script_id)
16-
:after(test_system)
17-
)
2+
local post_update_schedule = world.get_schedule_by_name("PostUpdate")
3+
4+
local test_system = post_update_schedule:get_system_by_name("on_test_post_update")
5+
6+
local script_attachment = ScriptAttachment.new_entity_script(entity, script_asset)
187

19-
-- generate a schedule graph and verify it's what we expect
20-
local dot_graph = post_update_schedule:render_dot()
8+
local system_a = world.add_system(
9+
post_update_schedule,
10+
system_builder("custom_system_a", script_attachment)
11+
:after(test_system)
12+
)
2113

22-
local expected_dot_graph = [[
14+
local system_b = world.add_system(
15+
post_update_schedule,
16+
system_builder("custom_system_b", script_attachment)
17+
:after(test_system)
18+
)
19+
20+
-- generate a schedule graph and verify it's what we expect
21+
local dot_graph = post_update_schedule:render_dot()
22+
23+
local expected_dot_graph = [[
2324
digraph {
2425
node_0 [label="bevy_asset::assets::Assets<bevy_asset::folder::LoadedFolder>::asset_events"];
2526
node_1 [label="bevy_asset::assets::Assets<bevy_asset::assets::LoadedUntypedAsset>::asset_events"];
2627
node_2 [label="bevy_asset::assets::Assets<()>::asset_events"];
2728
node_3 [label="bevy_asset::assets::Assets<bevy_mod_scripting_core::asset::ScriptAsset>::asset_events"];
2829
node_4 [label="bevy_mod_scripting_core::bindings::allocator::garbage_collector"];
29-
node_5 [label="on_test_post_update"];
30-
node_6 [label="script_integration_test_harness::dummy_before_post_update_system"];
31-
node_7 [label="script_integration_test_harness::dummy_post_update_system"];
30+
node_5 [label="script_integration_test_harness::dummy_before_post_update_system"];
31+
node_6 [label="script_integration_test_harness::dummy_post_update_system"];
32+
node_7 [label="on_test_post_update"];
3233
node_8 [label="custom_system_a"];
3334
node_9 [label="custom_system_b"];
3435
node_10 [label="SystemSet AssetEvents"];
@@ -42,11 +43,10 @@ digraph {
4243
node_4 -> node_11 [color=red, label="child of", arrowhead=diamond];
4344
node_8 -> node_12 [color=red, label="child of", arrowhead=diamond];
4445
node_9 -> node_13 [color=red, label="child of", arrowhead=diamond];
45-
node_5 -> node_8 [color=blue, label="runs before", arrowhead=normal];
46-
node_5 -> node_9 [color=blue, label="runs before", arrowhead=normal];
47-
node_6 -> node_7 [color=blue, label="runs before", arrowhead=normal];
46+
node_5 -> node_6 [color=blue, label="runs before", arrowhead=normal];
47+
node_7 -> node_8 [color=blue, label="runs before", arrowhead=normal];
48+
node_7 -> node_9 [color=blue, label="runs before", arrowhead=normal];
4849
}
4950
]]
50-
51-
assert_str_eq(dot_graph, expected_dot_graph, "Expected the schedule graph to match the expected graph")
51+
assert_str_eq(dot_graph, expected_dot_graph, "Expected the schedule graph to match the expected graph")
5252
end

assets/tests/add_system/added_systems_run_in_parallel.rhai

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
fn on_test() {
22
let post_update_schedule = world.get_schedule_by_name.call("PostUpdate");
33

4+
let script_attachment = ScriptAttachment.new_entity_script.call(entity, script_asset);
45
let test_system = post_update_schedule.get_system_by_name.call("on_test_post_update");
56

67
let system_a = world.add_system.call(
78
post_update_schedule,
8-
system_builder.call("custom_system_a", script_id)
9+
system_builder.call("custom_system_a", script_attachment)
910
.after.call(test_system)
1011
);
1112

1213
let system_b = world.add_system.call(
1314
post_update_schedule,
14-
system_builder.call("custom_system_b", script_id)
15+
system_builder.call("custom_system_b", script_attachment)
1516
.after.call(test_system)
1617
);
1718

@@ -25,9 +26,9 @@ digraph {
2526
node_2 [label="bevy_asset::assets::Assets<()>::asset_events"];
2627
node_3 [label="bevy_asset::assets::Assets<bevy_mod_scripting_core::asset::ScriptAsset>::asset_events"];
2728
node_4 [label="bevy_mod_scripting_core::bindings::allocator::garbage_collector"];
28-
node_5 [label="on_test_post_update"];
29-
node_6 [label="script_integration_test_harness::dummy_before_post_update_system"];
30-
node_7 [label="script_integration_test_harness::dummy_post_update_system"];
29+
node_5 [label="script_integration_test_harness::dummy_before_post_update_system"];
30+
node_6 [label="script_integration_test_harness::dummy_post_update_system"];
31+
node_7 [label="on_test_post_update"];
3132
node_8 [label="custom_system_a"];
3233
node_9 [label="custom_system_b"];
3334
node_10 [label="SystemSet AssetEvents"];
@@ -41,9 +42,9 @@ digraph {
4142
node_4 -> node_11 [color=red, label="child of", arrowhead=diamond];
4243
node_8 -> node_12 [color=red, label="child of", arrowhead=diamond];
4344
node_9 -> node_13 [color=red, label="child of", arrowhead=diamond];
44-
node_5 -> node_8 [color=blue, label="runs before", arrowhead=normal];
45-
node_5 -> node_9 [color=blue, label="runs before", arrowhead=normal];
46-
node_6 -> node_7 [color=blue, label="runs before", arrowhead=normal];
45+
node_5 -> node_6 [color=blue, label="runs before", arrowhead=normal];
46+
node_7 -> node_8 [color=blue, label="runs before", arrowhead=normal];
47+
node_7 -> node_9 [color=blue, label="runs before", arrowhead=normal];
4748
}`;
4849

4950
assert_str_eq.call(dot_graph, expected_dot_graph, "Expected the schedule graph to match the expected graph");
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
-- add two systems, one before and one after the existing `on_test_post_update` callback, then assert all systems have run
22
-- in the `on_test_last` callback
33

4-
local runs = {}
4+
local runs = {}
55

66
-- runs on `Update`
77
function on_test()
88
local post_update_schedule = world.get_schedule_by_name("PostUpdate")
9-
9+
1010
local test_system = post_update_schedule:get_system_by_name("on_test_post_update")
11-
11+
local script_attachment = ScriptAttachment.new_entity_script(entity, script_asset)
12+
1213
local system_after = world.add_system(
1314
post_update_schedule,
14-
system_builder("custom_system_after", script_id)
15-
:after(test_system)
15+
system_builder("custom_system_after", script_attachment)
16+
:after(test_system)
1617
)
17-
18+
1819
local system_before = world.add_system(
1920
post_update_schedule,
20-
system_builder("custom_system_before", script_id)
21-
:before(test_system)
22-
)
21+
system_builder("custom_system_before", script_attachment)
22+
:before(test_system)
23+
)
2324

2425
local script_system_between = world.add_system(
2526
post_update_schedule,
26-
system_builder("custom_system_between", script_id)
27-
:after(test_system)
28-
:before(system_after)
27+
system_builder("custom_system_between", script_attachment)
28+
:after(test_system)
29+
:before(system_after)
2930
)
3031
end
3132

32-
3333
function custom_system_before()
3434
print("custom_system_before")
3535
runs[#runs + 1] = "custom_system_before"
3636
end
3737

38-
-- runs on post_update
38+
-- runs on post_update
3939
function on_test_post_update()
4040
print("on_test_post_update")
4141
runs[#runs + 1] = "on_test_post_update"
@@ -53,9 +53,10 @@ end
5353

5454
-- runs in the `Last` bevy schedule
5555
function on_test_last()
56-
assert(#runs == 4, "Expected 4 runs, got: " .. #runs)
56+
local string_table = table.concat(runs, ", ")
57+
assert(#runs == 4, "Expected 4 runs, got: " .. tostring(string_table))
5758
assert(runs[1] == "custom_system_before", "Expected custom_system_before to run first, got: " .. runs[1])
5859
assert(runs[2] == "on_test_post_update", "Expected on_test_post_update to run second, got: " .. runs[2])
5960
assert(runs[3] == "custom_system_between", "Expected custom_system_between to run third, got: " .. runs[3])
6061
assert(runs[4] == "custom_system_after", "Expected custom_system_after to run second, got: " .. runs[4])
61-
end
62+
end

assets/tests/add_system/adds_system_in_correct_order.rhai

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ let runs = [];
33
fn on_test() {
44
let post_update_schedule = world.get_schedule_by_name.call("PostUpdate");
55
let test_system = post_update_schedule.get_system_by_name.call("on_test_post_update");
6+
let script_attachment = ScriptAttachment.new_entity_script.call(entity, script_asset);
67

7-
let builder_after = system_builder.call("custom_system_after", script_id)
8+
let builder_after = system_builder.call("custom_system_after", script_attachment)
89
.after.call(test_system);
910
let system_after = world.add_system.call(post_update_schedule, builder_after);
1011

11-
let builder_before = system_builder.call("custom_system_before", script_id)
12+
let builder_before = system_builder.call("custom_system_before", script_attachment)
1213
.before.call(test_system);
1314
let system_before = world.add_system.call(post_update_schedule, builder_before);
1415

15-
let builder_between = system_builder.call("custom_system_between", script_id)
16+
let builder_between = system_builder.call("custom_system_between", script_attachment)
1617
.after.call(test_system)
1718
.before.call(system_after);
1819

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
21
runs = {}
32

43
function on_test()
54
local post_update_schedule = world.get_schedule_by_name("PostUpdate")
6-
5+
local script_attachment = ScriptAttachment.new_entity_script(entity, script_asset)
76
world.add_system(
87
post_update_schedule,
9-
system_builder("my_exclusive_system", script_id):exclusive()
8+
system_builder("my_exclusive_system", script_attachment):exclusive()
109
)
1110

1211
return true
@@ -21,12 +20,11 @@ function my_exclusive_system()
2120
assert(res ~= nil, "Expected to get resource but got nil")
2221
end
2322

24-
2523
function on_test_post_update()
2624
return true
2725
end
2826

2927
function on_test_last()
3028
assert(#runs == 1, "Expected 1 runs, got: " .. #runs)
3129
return true
32-
end
30+
end
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ let runs = [];
22

33
fn on_test() {
44
let post_update_schedule = world.get_schedule_by_name.call("PostUpdate");
5-
5+
let script_attachment = ScriptAttachment.new_entity_script.call(entity, script_asset);
6+
67
world.add_system.call(
78
post_update_schedule,
8-
system_builder.call("my_exclusive_system", script_id).exclusive.call()
9+
system_builder.call("my_exclusive_system", script_attachment).exclusive.call()
910
);
1011

1112
return true;
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
21
runs = {}
32

43
function on_test()
54
local post_update_schedule = world.get_schedule_by_name("PostUpdate")
6-
5+
local script_attachment = ScriptAttachment.new_entity_script(entity, script_asset)
6+
77
world.add_system(
88
post_update_schedule,
9-
system_builder("my_non_exclusive_system", script_id)
9+
system_builder("my_non_exclusive_system", script_attachment)
1010
)
1111

1212
return true
@@ -23,12 +23,11 @@ function my_non_exclusive_system()
2323
end, ".*annot claim access to.*")
2424
end
2525

26-
2726
function on_test_post_update()
2827
return true
2928
end
3029

3130
function on_test_last()
3231
assert(#runs == 1, "Expected 1 runs, got: " .. #runs)
3332
return true
34-
end
33+
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ let runs = [];
22

33
fn on_test() {
44
let post_update_schedule = world.get_schedule_by_name.call("PostUpdate");
5-
world.add_system.call(post_update_schedule, system_builder.call("my_non_exclusive_system", script_id));
5+
let script_attachment = ScriptAttachment.new_entity_script.call(entity, script_asset);
6+
world.add_system.call(post_update_schedule, system_builder.call("my_non_exclusive_system", script_attachment));
67
return true;
78
}
89

0 commit comments

Comments
 (0)