Skip to content

Commit ab3d48c

Browse files
authored
feat: Replace ParsedPath with custom ReferencePath, support Map and Set references with arbitrary types (#491)
1 parent 8b596c8 commit ab3d48c

36 files changed

+1221
-248
lines changed

assets/tests/add_default_component/component_with_default_and_component_data_adds_default.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ local added = world.has_component(entity, _type)
66
assert(added ~= nil, 'Component not added')
77

88
local component = world.get_component(entity, _type)
9-
assert(component._1 == "Default", 'Component did not have default value, got: ' .. component._1)
9+
assert(component[1] == "Default", 'Component did not have default value, got: ' .. component[1])

assets/tests/add_default_component/component_with_default_and_component_data_adds_default.rhai

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ let added = world.has_component.call(entity, _type);
66
assert(type_of(added) != "()", "Component not added");
77

88
let component = world.get_component.call(entity, _type);
9-
assert(component["_0"] == "Default", "Component did not have default value, got: " + component["_0"]);
9+
assert(component[0] == "Default", "Component did not have default value, got: " + component[0]);

assets/tests/add_default_component/component_with_from_world_and_component_data_adds_default.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ local added = world.has_component(entity, _type)
66
assert(added ~= nil, 'Component not added')
77

88
local component = world.get_component(entity, _type)
9-
assert(component._1 == "Default", 'Component did not have default value, got: ' .. component._1)
9+
assert(component[1] == "Default", 'Component did not have default value, got: ' .. component[1])

assets/tests/add_default_component/component_with_from_world_and_component_data_adds_default.rhai

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ let added = world.has_component.call(entity, _type);
66
assert(type_of(added) != "()", "Component not added");
77

88
let component = world.get_component.call(entity, _type);
9-
assert(component["_0"] == "Default", "Component did not have default value, got: " + component["_0"])
9+
assert(component[0] == "Default", "Component did not have default value, got: " + component[0])

assets/tests/construct/construct_enum.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,28 @@ local constructed = construct(type, {
66
foo = 123
77
})
88

9-
assert(constructed:variant_name() == "Struct", "Value was constructed incorrectly, expected constructed.variant to be Struct but got " .. constructed:variant_name())
10-
assert(constructed.foo == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " .. constructed.foo)
9+
assert(constructed:variant_name() == "Struct",
10+
"Value was constructed incorrectly, expected constructed.variant to be Struct but got " .. constructed:variant_name())
11+
assert(constructed.foo == 123,
12+
"Value was constructed incorrectly, expected constructed.foo to be 123 but got " .. constructed.foo)
1113

1214

1315
-- TupleStruct Variant
1416
local constructed = construct(type, {
1517
variant = "TupleStruct",
16-
_1 = 123
18+
["1"] = 123
1719
})
1820

19-
assert(constructed:variant_name() == "TupleStruct", "Value was constructed incorrectly, expected constructed.variant to be TupleStruct but got " .. constructed:variant_name())
20-
assert(constructed._1 == 123, "Value was constructed incorrectly, expected constructed._1 to be 123 but got " .. constructed._1)
21+
assert(constructed:variant_name() == "TupleStruct",
22+
"Value was constructed incorrectly, expected constructed.variant to be TupleStruct but got " ..
23+
constructed:variant_name())
24+
assert(constructed[1] == 123,
25+
"Value was constructed incorrectly, expected constructed._1 to be 123 but got " .. constructed[1])
2126

2227
-- Unit Variant
2328
local constructed = construct(type, {
2429
variant = "Unit"
2530
})
2631

27-
assert(constructed:variant_name() == "Unit", "Value was constructed incorrectly, expected constructed.variant to be Unit but got " .. constructed:variant_name())
32+
assert(constructed:variant_name() == "Unit",
33+
"Value was constructed incorrectly, expected constructed.variant to be Unit but got " .. constructed:variant_name())
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local type = world.get_type_by_name("SimpleTupleStruct")
22
local constructed = construct(type, {
3-
_1 = 123
3+
["1"] = 123
44
})
55

6-
assert(constructed._1 == 123,
7-
"Value was constructed incorrectly, expected constructed.foo to be 123 but got " .. constructed._1)
6+
assert(constructed[1] == 123,
7+
"Value was constructed incorrectly, expected constructed.foo to be 123 but got " .. constructed[1])

assets/tests/construct/simple_enum.rhai

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ assert(constructed.variant_name.call() == "Struct", "Value was constructed incor
77
assert(constructed.foo == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " + constructed.foo);
88

99
// TupleStruct Variant
10-
constructed = construct.call(type, #{ variant: "TupleStruct", "_0": 123 });
10+
constructed = construct.call(type, #{ variant: "TupleStruct", "0": 123 });
1111

1212
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"]);
13+
assert(constructed[0] == 123, "Value was constructed incorrectly, expected constructed[0] to be 123 but got " + constructed[0]);
1414

1515
// Unit Variant
1616
constructed = construct.call(type, #{ variant: "Unit" });
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
let type = world.get_type_by_name.call("SimpleTupleStruct");
2-
let constructed = construct.call(type, #{ "_0": 123 });
2+
let constructed = construct.call(type, #{ "0": 123 });
33

4-
assert(constructed["_0"] == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " + constructed["_0"]);
4+
assert(constructed[0] == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " + constructed[0]);

assets/tests/display/print_value_by_default.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ local expected_vec3_debug = [[
2020
ReflectAllocationId(*anything*),
2121
),
2222
},
23-
reflect_path: ParsedPath(
24-
[],
25-
),
23+
reflect_path: ReferencePath {
24+
one_indexed: false,
25+
path: [],
26+
},
2627
}
2728
]]
2829
-- normalize allocation ids before comparison so tests don't fail on runtime-generated ids
@@ -49,9 +50,10 @@ ReflectReference {
4950
),
5051
),
5152
},
52-
reflect_path: ParsedPath(
53-
[],
54-
),
53+
reflect_path: ReferencePath {
54+
one_indexed: false,
55+
path: [],
56+
},
5557
}
5658
]]
5759

assets/tests/get_component/component_no_component_data.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ local entity = world._get_entity_with_test_component("CompWithDefault")
33
local retrieved = world.get_component(entity, component)
44

55
assert(retrieved ~= nil, "Component was not found")
6-
assert(retrieved._1 == "Initial Value", "Component data was not retrieved correctly, retrieved._1 was: " .. retrieved._1)
6+
assert(retrieved[1] == "Initial Value", "Component data was not retrieved correctly, retrieved._1 was: " .. retrieved[1])

0 commit comments

Comments
 (0)