Skip to content

Commit 249de81

Browse files
authored
feat: add WithWorldGuard and HandlerContext system parameters (#327)
1 parent 86eafe5 commit 249de81

File tree

310 files changed

+2763
-668
lines changed

Some content is hidden

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

310 files changed

+2763
-668
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let entity = Entity.from_raw.call(9999);
2+
// does not throw
3+
let out = entity.eq.call(entity);

assets/tests/data/add/vec3.rhai

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let a = Vec3.new_.call(1.0, 2.0, 3.0);
2+
let b = Vec3.new_.call(4.0, 5.0, 6.0);
3+
4+
assert((a + 1).x == 2.0, "Addition did not work");
5+
assert((a + 1).y == 3.0, "Addition did not work");
6+
assert((a + 1).z == 4.0, "Addition did not work");
7+
8+
assert((a + b).x == 5.0, "Addition did not work");
9+
assert((a + b).y == 7.0, "Addition did not work");
10+
assert((a + b).z == 9.0, "Addition did not work");
11+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let entity = world.spawn_.call();
2+
let type = world.get_type_by_name.call("TestComponent");
3+
4+
assert_throws(||{
5+
world.add_default_component.call(entity, type);
6+
},"Missing type data ReflectDefault or ReflectFromWorld for type: .*TestComponent.*");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let entity = world.spawn_.call();
2+
let _type = world.get_type_by_name.call("CompWithDefaultAndComponentData");
3+
world.add_default_component.call(entity, _type);
4+
5+
let added = world.has_component.call(entity, _type);
6+
assert(type_of(added) != "()", "Component not added");
7+
8+
let component = world.get_component.call(entity, _type);
9+
assert(component["_0"] == "Default", "Component did not have default value, got: " + component["_0"]);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let entity = world.spawn_.call();
2+
let _type = world.get_type_by_name.call("CompWithDefault");
3+
4+
assert_throws(||{
5+
world.add_default_component.call(entity, _type);
6+
}, "Missing type data ReflectComponent for type: .*CompWithDefault.*")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let entity = world.spawn_.call();
2+
let _type = world.get_type_by_name.call("CompWithFromWorldAndComponentData");
3+
world.add_default_component.call(entity, _type);
4+
5+
let added = world.has_component.call(entity, _type);
6+
assert(type_of(added) != "()", "Component not added");
7+
8+
let component = world.get_component.call(entity, _type);
9+
assert(component["_0"] == "Default", "Component did not have default value, got: " + component["_0"])
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let entity = world.spawn_.call();
2+
let _type = world.get_type_by_name.call("CompWithFromWorld");
3+
4+
assert_throws(||{
5+
world.add_default_component.call(entity, _type);
6+
}, "Missing type data ReflectComponent for type: .*CompWithFromWorld.*")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn on_test() {
2+
assert!(type_of(world) != "()", "World was not found");
3+
assert!(type_of(world.get_type_by_name.call("TestComponent")) != "()", "Could not find TestComponent type");
4+
Entity.from_raw.call(1);
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assert!(type_of(world) != "()", "World was not found");
2+
assert!(type_of(world.get_type_by_name.call("TestComponent")) != "()", "Could not find TestComponent type");
3+
let out = Entity.from_raw.call(1);

assets/tests/data/clear/vec.rhai

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let res_type = world.get_type_by_name.call("TestResourceWithVariousFields");
2+
let res = world.get_resource.call(res_type);
3+
4+
res.vec_usize.clear.call();
5+
6+
assert(res.vec_usize.len.call() == 0, "Clear did not work");
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let type = world.get_type_by_name.call("SimpleEnum");
2+
3+
// Struct Variant
4+
let constructed = construct.call(type, #{ variant: "Struct", foo: 123 });
5+
6+
assert(constructed.variant_name.call() == "Struct", "Value was constructed incorrectly, expected constructed.variant to be Struct but got " + constructed.variant_name.call());
7+
assert(constructed.foo == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " + constructed.foo);
8+
9+
// TupleStruct Variant
10+
constructed = construct.call(type, #{ variant: "TupleStruct", "_0": 123 });
11+
12+
assert(constructed.variant_name.call() == "TupleStruct", "Value was constructed incorrectly, expected constructed.variant to be TupleStruct but got " + constructed.variant_name.call());
13+
assert(constructed["_0"] == 123, "Value was constructed incorrectly, expected constructed._0 to be 123 but got " + constructed["_0"]);
14+
15+
// Unit Variant
16+
constructed = construct.call(type, #{ variant: "Unit" });
17+
18+
assert(constructed.variant_name.call() == "Unit", "Value was constructed incorrectly, expected constructed.variant to be Unit but got " + constructed.variant_name.call());
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let type = world.get_type_by_name.call("SimpleStruct");
2+
let constructed = construct.call(type, #{ foo: 123 });
3+
4+
assert(constructed.foo == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " + constructed.foo);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let type = world.get_type_by_name.call("SimpleTupleStruct");
2+
let constructed = construct.call(type, #{ "_0": 123 });
3+
4+
assert(constructed["_0"] == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " + constructed["_0"]);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let entity = world.spawn_.call();
2+
let child = world.spawn_.call();
3+
world.push_children.call(entity, [child]);
4+
world.despawn.call(entity);
5+
6+
assert(world.has_entity.call(entity) == false, "Parent should be despawned");
7+
assert(world.has_entity.call(child) == true, "Child should not be despawned");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assert_throws(||{
2+
world.despawn_recursive.call(Entity.from_raw.call(9999))
3+
}, "Missing or invalid entity");
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let entity = world.spawn_.call();
2+
let child = world.spawn_.call();
3+
world.push_children.call(entity, [child]);
4+
world.despawn_descendants.call(entity);
5+
6+
assert(world.has_entity.call(entity) == true, "Parent should not be despawned");
7+
assert(world.has_entity.call(child) == false, "Child should be despawned");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assert_throws(||{
2+
world.despawn_recursive.call(Entity.from_raw.call(9999));
3+
}, "Missing or invalid entity")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let entity = world.spawn_.call();
2+
let child = world.spawn_.call();
3+
world.push_children.call(entity, [child]);
4+
world.despawn_recursive.call(entity);
5+
6+
assert(world.has_entity.call(entity) == false, "Parent should be despawned");
7+
assert(world.has_entity.call(child) == false, "Child should be despawned");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assert_throws(||{
2+
world.despawn_recursive.call(Entity.from_raw.call(9999));
3+
}, "Missing or invalid entity")

assets/tests/div/vec3.rhai

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let a = Vec3.new_.call(2.0, 4.0, 6.0);
2+
let b = Vec3.new_.call(1.0, 2.0, 3.0);
3+
4+
assert((a / 2).x == 1.0, "Division did not work");
5+
assert((a / 2).y == 2.0, "Division did not work");
6+
assert((a / 2).z == 3.0, "Division did not work");
7+
8+
assert((a / b).x == 2.0, "Division did not work");
9+
assert((a / b).y == 2.0, "Division did not work");
10+
assert((a / b).z == 2.0, "Division did not work");

assets/tests/eq/vec3.rhai

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let a = Vec3.new_.call(2.0, -4.0, 6.0);
2+
let b = Vec3.new_.call(4.0, 5.0, 6.0);
3+
4+
5+
assert((a == b) == false, "Equality did not work");
6+
assert((a != b) == true, "Inequality did not work");
7+
assert((a == a) == true, "Equality did not work");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
let Resource = world.get_type_by_name.call("TestResource");
3+
let resource = world.get_resource.call(Resource);
4+
5+
let functions = resource.functions.call();
6+
assert(functions.len() > 0, "functions should not be empty");
7+
8+
let available_names = [];
9+
10+
for function_ref in functions {
11+
available_names.push(function_ref.name);
12+
}
13+
14+
assert("display_ref" in available_names, "functions should contain display_ref, but got: " + available_names);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let entity = world.spawn_.call();
2+
let child = world.spawn_.call();
3+
4+
world.push_children.call(entity, [child]);
5+
6+
let children = world.get_children.call(entity);
7+
8+
assert(children.len == 1, "Expected 1 child");
9+
assert(children[0].index.call() == child.index.call(), "Child is the wrong entity");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assert_throws(||{
2+
world.get_children.call(Entity.from_raw.call(9999));
3+
}, "Missing or invalid entity");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let entity = world.spawn_.call();
2+
let children = world.get_children.call(entity);
3+
4+
assert(children.len == 0);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let component = world.get_type_by_name.call("CompWithDefault");
2+
let entity = world._get_entity_with_test_component.call("CompWithDefault");
3+
let retrieved = world.get_component.call(entity, component);
4+
5+
assert(type_of(retrieved) != "()", "Component was not found");
6+
assert(retrieved["_0"] == "Initial Value", "Component data was not retrieved correctly, retrieved._0 was: " + retrieved["_0"]);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let component = world.get_type_by_name.call("TestComponent");
2+
let entity = world._get_entity_with_test_component.call("TestComponent");
3+
let retrieved = world.get_component.call(entity, component);
4+
5+
assert(type_of(retrieved) != "()", "Component was not found");
6+
assert(retrieved.strings[0] == "Initial", "Component data was not retrieved correctly, retrieved.strings[0] was: " + retrieved.strings[0]);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let component = world.get_type_by_name.call("TestComponent");
2+
let entity = world.spawn_.call();
3+
let retrieved = world.get_component.call(entity, component);
4+
5+
assert(type_of(retrieved) == "()", "Component found");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let entity = world.spawn_.call();
2+
let child = world.spawn_.call();
3+
4+
world.push_children.call(entity, [child]);
5+
6+
let parent = world.get_parent.call(child);
7+
8+
assert(type_of(parent) != "()", "Expected a parent");
9+
assert(parent.index.call() == entity.index.call(), "Parent is the wrong entity");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
assert_throws(||{
3+
world.get_parent.call(Entity.from_raw.call(9999));
4+
}, "Missing or invalid entity");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let entity = world.spawn_.call();
2+
let parent = world.get_parent.call(entity);
3+
4+
assert(type_of(parent) == "()", "Expected no parents");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let type = world._get_mock_resource_type.call();
2+
assert(type_of(world.get_resource.call(type)) == "()", "Resource should not exist");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let resource = world.get_type_by_name.call("ResourceWithDefault");
2+
3+
let retrieved = world.get_resource.call(resource);
4+
assert(type_of(retrieved) != "()", "Resource should exist");
5+
assert(retrieved["_0"] == "Initial Value", "Resource should have default value but got: " + retrieved["_0"]);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let resource = world.get_type_by_name.call("TestResource");
2+
3+
let retrieved = world.get_resource.call(resource);
4+
assert(type_of(retrieved) != "()", "Resource should exist");
5+
assert(retrieved.bytes[1] == 1, "Resource should have default value but got resource with #retrieved.bytes[1]: " + retrieved.bytes[1]);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let type = world.get_type_by_name.call("MissingType");
2+
3+
assert(type == (), "Unregistered type was found");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let type = world.get_type_by_name.call("TestComponent");
2+
3+
assert(type_of(type) != "()", "Registered type was not found");
4+
5+
let expected_type_name = "test_utils::test_data::TestComponent";
6+
let expected_short_name = "TestComponent";
7+
8+
let received_type_name = type.type_name.call(type);
9+
let received_short_name = type.short_name.call(type);
10+
11+
12+
// assert(type != (), 'Type not found')
13+
// assert(received.type_name == expected.type_name, 'type_name mismatch, expected: ' .. expected.type_name .. ', got: ' .. received.type_name)
14+
// assert(received.short_name == expected.short_name, 'short_name mismatch, expected: ' .. expected.short_name .. ', got: ' .. received.short_name)
15+
16+
assert(received_type_name == expected_type_name, "type_name mismatch, expected: " + expected_type_name + ", got: " + received_type_name);
17+
assert(received_short_name == expected_short_name, "short_name mismatch, expected: " + expected_short_name + ", got: " + received_short_name);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert(global_hello_world.call() == "hi!", "global_hello_world() == 'hi!'")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let entity = world.spawn_.call();
2+
let type = world._get_mock_component_type.call();
3+
4+
assert(world.has_component.call(entity, type) == false, "Entity should not have component");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let entity = world._get_entity_with_test_component.call("CompWithDefault");
2+
let component = world.get_type_by_name.call("CompWithDefault");
3+
assert(world.has_component.call(entity, component) == true, "Component was not found");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let entity = world._get_entity_with_test_component.call("TestComponent");
2+
let component = world.get_type_by_name.call("TestComponent");
3+
assert(world.has_component.call(entity, component) == true, "Component was not found");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let component = world.get_type_by_name.call("ResourceWithDefault");
2+
assert(world.has_resource.call(component) == true, "Resource was not found");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let component = world.get_type_by_name.call("TestResource");
2+
assert(world.has_resource.call(component) == true, "Resource was not found");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let type = world._get_mock_resource_type.call();
2+
assert(world.has_resource.call(type) == false, "Resource should not exist");
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let my_map = make_hashmap.call(#{
2+
key1: 2,
3+
key2: 3,
4+
});
5+
6+
assert(my_map["key1"] == 2, "map[\"key1\"] should be 2");
7+
assert(my_map["key2"] == 3, "map[\"key2\"] should be 3");

assets/tests/insert/vec.rhai

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let res_type = world.get_type_by_name.call("TestResourceWithVariousFields");
2+
let res = world.get_resource.call(res_type);
3+
4+
res.vec_usize.insert.call(2, 42);
5+
6+
assert(res.vec_usize[2] == 42, "insert did not work");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let entity = world.spawn_.call();
2+
3+
world.insert_children.call(entity,0 ,[]);
4+
5+
assert(world.get_children.call(entity).len == 0);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
let entity = world.spawn_.call();
2+
let child = world.spawn_.call();
3+
let child2 = world.spawn_.call();
4+
5+
world.insert_children.call(entity, 0, [child]);
6+
world.insert_children.call(entity, 0, [child2]);
7+
8+
assert(world.get_children.call(entity)[0].index.call() == child2.index.call());
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let entity = world.spawn_.call();
2+
let child = world.spawn_.call();
3+
let child2 = world.spawn_.call();
4+
world.insert_children.call(entity, 0, [child, child2]);
5+
6+
assert(world.get_children.call(entity).len == 2);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let fake_entity = Entity.from_raw.call(9999);
2+
3+
assert_throws(||{
4+
world.insert_children.call(fake_entity, 0, [fake_entity]);
5+
}, "Missing or invalid entity");
6+
7+
let entity = world.spawn_.call();
8+
assert_throws(||{
9+
world.insert_children.call(entity, 0, [fake_entity]);
10+
}, "Missing or invalid entity");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
let entity = world.spawn_.call();
2+
let type = world.get_type_by_name.call("TestComponent");
3+
let entity_with_component = world._get_entity_with_test_component.call("TestComponent");
4+
let existing_component = world.get_component.call(entity_with_component, type);
5+
6+
assert(world.has_component.call(entity, type) == false, "Expected entity to not have component before adding, test invalid");
7+
world.insert_component.call(entity, type, existing_component);
8+
assert(world.has_component.call(entity, type) == true, "Expected entity to have component after adding");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
let entity = world.spawn_.call();
2+
let _type = world.get_type_by_name.call("CompWithDefault");
3+
let entity_with_component = world._get_entity_with_test_component.call("CompWithDefault");
4+
let existing_component = world.get_component.call(entity_with_component, _type);
5+
6+
assert_throws(||{
7+
world.insert_component.call(entity, _type, existing_component);
8+
}, "Missing type data ReflectComponent for type: .*CompWithDefault.*");

0 commit comments

Comments
 (0)