Skip to content

Commit f71612c

Browse files
shanecelismakspll
andauthored
feat: Use the Handles, Luke! (#427)
Co-authored-by: makspll <[email protected]>
1 parent 67c5a5d commit f71612c

File tree

93 files changed

+4800
-2538
lines changed

Some content is hidden

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

93 files changed

+4800
-2538
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_mod_scripting"
3-
version = "0.13.0"
3+
version = "0.14.0-alpha.1"
44
authors = ["Maksymilian Mozolewski <[email protected]>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
@@ -76,18 +76,18 @@ profile_with_tracy = ["bevy/trace_tracy"]
7676
[dependencies]
7777
bevy = { workspace = true }
7878
bevy_mod_scripting_core = { workspace = true }
79-
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.13.0", optional = true }
80-
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.13.0", optional = true }
79+
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.14.0-alpha.1", optional = true }
80+
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.14.0-alpha.1", optional = true }
8181
# bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.9.0-alpha.2", optional = true }
8282
bevy_mod_scripting_functions = { workspace = true }
8383
bevy_mod_scripting_derive = { workspace = true }
8484

8585
[workspace.dependencies]
8686
profiling = { version = "1.0" }
8787
bevy = { version = "0.15.3", default-features = false }
88-
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.13.0" }
89-
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.13.0", default-features = false }
90-
bevy_mod_scripting_derive = { path = "crates/bevy_mod_scripting_derive", version = "0.13.0" }
88+
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.14.0-alpha.1" }
89+
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.14.0-alpha.1", default-features = false }
90+
bevy_mod_scripting_derive = { path = "crates/bevy_mod_scripting_derive", version = "0.14.0-alpha.1" }
9191

9292
# test utilities
9393
script_integration_test_harness = { path = "crates/testing_crates/script_integration_test_harness" }

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: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
21
function on_test()
32
local post_update_schedule = world.get_schedule_by_name("PostUpdate")
4-
3+
54
local test_system = post_update_schedule:get_system_by_name("on_test_post_update")
6-
5+
6+
local script_attachment = ScriptAttachment.new_entity_script(entity, script_asset)
7+
78
local system_a = world.add_system(
89
post_update_schedule,
9-
system_builder("custom_system_a", script_id)
10-
:after(test_system)
10+
system_builder("custom_system_a", script_attachment)
11+
:after(test_system)
1112
)
12-
13+
1314
local system_b = world.add_system(
1415
post_update_schedule,
15-
system_builder("custom_system_b", script_id)
16-
:after(test_system)
17-
)
16+
system_builder("custom_system_b", script_attachment)
17+
:after(test_system)
18+
)
1819

1920
-- generate a schedule graph and verify it's what we expect
2021
local dot_graph = post_update_schedule:render_dot()
2122

2223
local expected_dot_graph = [[
2324
digraph {
2425
node_0 [label="bevy_mod_scripting_core::bindings::allocator::garbage_collector"];
25-
node_1 [label="on_test_post_update"];
26-
node_2 [label="script_integration_test_harness::dummy_before_post_update_system"];
27-
node_3 [label="script_integration_test_harness::dummy_post_update_system"];
26+
node_1 [label="script_integration_test_harness::dummy_before_post_update_system"];
27+
node_2 [label="script_integration_test_harness::dummy_post_update_system"];
28+
node_3 [label="on_test_post_update"];
2829
node_4 [label="custom_system_a"];
2930
node_5 [label="custom_system_b"];
3031
node_6 [label="SystemSet GarbageCollection"];
@@ -33,11 +34,10 @@ digraph {
3334
node_0 -> node_6 [color=red, label="child of", arrowhead=diamond];
3435
node_4 -> node_7 [color=red, label="child of", arrowhead=diamond];
3536
node_5 -> node_8 [color=red, label="child of", arrowhead=diamond];
36-
node_1 -> node_4 [color=blue, label="runs before", arrowhead=normal];
37-
node_1 -> node_5 [color=blue, label="runs before", arrowhead=normal];
38-
node_2 -> node_3 [color=blue, label="runs before", arrowhead=normal];
37+
node_1 -> node_2 [color=blue, label="runs before", arrowhead=normal];
38+
node_3 -> node_4 [color=blue, label="runs before", arrowhead=normal];
39+
node_3 -> node_5 [color=blue, label="runs before", arrowhead=normal];
3940
}
4041
]]
41-
4242
assert_str_eq(dot_graph, expected_dot_graph, "Expected the schedule graph to match the expected graph")
4343
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

@@ -21,9 +22,9 @@ fn on_test() {
2122
let expected_dot_graph = `
2223
digraph {
2324
node_0 [label="bevy_mod_scripting_core::bindings::allocator::garbage_collector"];
24-
node_1 [label="on_test_post_update"];
25-
node_2 [label="script_integration_test_harness::dummy_before_post_update_system"];
26-
node_3 [label="script_integration_test_harness::dummy_post_update_system"];
25+
node_1 [label="script_integration_test_harness::dummy_before_post_update_system"];
26+
node_2 [label="script_integration_test_harness::dummy_post_update_system"];
27+
node_3 [label="on_test_post_update"];
2728
node_4 [label="custom_system_a"];
2829
node_5 [label="custom_system_b"];
2930
node_6 [label="SystemSet GarbageCollection"];
@@ -32,9 +33,9 @@ digraph {
3233
node_0 -> node_6 [color=red, label="child of", arrowhead=diamond];
3334
node_4 -> node_7 [color=red, label="child of", arrowhead=diamond];
3435
node_5 -> node_8 [color=red, label="child of", arrowhead=diamond];
35-
node_1 -> node_4 [color=blue, label="runs before", arrowhead=normal];
36-
node_1 -> node_5 [color=blue, label="runs before", arrowhead=normal];
37-
node_2 -> node_3 [color=blue, label="runs before", arrowhead=normal];
36+
node_1 -> node_2 [color=blue, label="runs before", arrowhead=normal];
37+
node_3 -> node_4 [color=blue, label="runs before", arrowhead=normal];
38+
node_3 -> node_5 [color=blue, label="runs before", arrowhead=normal];
3839
}`;
3940

4041
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)