Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ local added = world.has_component(entity, _type)
assert(added ~= nil, 'Component not added')

local component = world.get_component(entity, _type)
assert(component._1 == "Default", 'Component did not have default value, got: ' .. component._1)
assert(component[1] == "Default", 'Component did not have default value, got: ' .. component[1])
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ let added = world.has_component.call(entity, _type);
assert(type_of(added) != "()", "Component not added");

let component = world.get_component.call(entity, _type);
assert(component["_0"] == "Default", "Component did not have default value, got: " + component["_0"]);
assert(component[0] == "Default", "Component did not have default value, got: " + component[0]);
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ local added = world.has_component(entity, _type)
assert(added ~= nil, 'Component not added')

local component = world.get_component(entity, _type)
assert(component._1 == "Default", 'Component did not have default value, got: ' .. component._1)
assert(component[1] == "Default", 'Component did not have default value, got: ' .. component[1])
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ let added = world.has_component.call(entity, _type);
assert(type_of(added) != "()", "Component not added");

let component = world.get_component.call(entity, _type);
assert(component["_0"] == "Default", "Component did not have default value, got: " + component["_0"])
assert(component[0] == "Default", "Component did not have default value, got: " + component[0])
18 changes: 12 additions & 6 deletions assets/tests/construct/construct_enum.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@ local constructed = construct(type, {
foo = 123
})

assert(constructed:variant_name() == "Struct", "Value was constructed incorrectly, expected constructed.variant to be Struct but got " .. constructed:variant_name())
assert(constructed.foo == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " .. constructed.foo)
assert(constructed:variant_name() == "Struct",
"Value was constructed incorrectly, expected constructed.variant to be Struct but got " .. constructed:variant_name())
assert(constructed.foo == 123,
"Value was constructed incorrectly, expected constructed.foo to be 123 but got " .. constructed.foo)


-- TupleStruct Variant
local constructed = construct(type, {
variant = "TupleStruct",
_1 = 123
["1"] = 123
})

assert(constructed:variant_name() == "TupleStruct", "Value was constructed incorrectly, expected constructed.variant to be TupleStruct but got " .. constructed:variant_name())
assert(constructed._1 == 123, "Value was constructed incorrectly, expected constructed._1 to be 123 but got " .. constructed._1)
assert(constructed:variant_name() == "TupleStruct",
"Value was constructed incorrectly, expected constructed.variant to be TupleStruct but got " ..
constructed:variant_name())
assert(constructed[1] == 123,
"Value was constructed incorrectly, expected constructed._1 to be 123 but got " .. constructed[1])

-- Unit Variant
local constructed = construct(type, {
variant = "Unit"
})

assert(constructed:variant_name() == "Unit", "Value was constructed incorrectly, expected constructed.variant to be Unit but got " .. constructed:variant_name())
assert(constructed:variant_name() == "Unit",
"Value was constructed incorrectly, expected constructed.variant to be Unit but got " .. constructed:variant_name())
6 changes: 3 additions & 3 deletions assets/tests/construct/construct_tuple_struct.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local type = world.get_type_by_name("SimpleTupleStruct")
local constructed = construct(type, {
_1 = 123
["1"] = 123
})

assert(constructed._1 == 123,
"Value was constructed incorrectly, expected constructed.foo to be 123 but got " .. constructed._1)
assert(constructed[1] == 123,
"Value was constructed incorrectly, expected constructed.foo to be 123 but got " .. constructed[1])
4 changes: 2 additions & 2 deletions assets/tests/construct/simple_enum.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ assert(constructed.variant_name.call() == "Struct", "Value was constructed incor
assert(constructed.foo == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " + constructed.foo);

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

assert(constructed.variant_name.call() == "TupleStruct", "Value was constructed incorrectly, expected constructed.variant to be TupleStruct but got " + constructed.variant_name.call());
assert(constructed["_0"] == 123, "Value was constructed incorrectly, expected constructed._0 to be 123 but got " + constructed["_0"]);
assert(constructed[0] == 123, "Value was constructed incorrectly, expected constructed[0] to be 123 but got " + constructed[0]);

// Unit Variant
constructed = construct.call(type, #{ variant: "Unit" });
Expand Down
4 changes: 2 additions & 2 deletions assets/tests/construct/simple_tuple_struct.rhai
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let type = world.get_type_by_name.call("SimpleTupleStruct");
let constructed = construct.call(type, #{ "_0": 123 });
let constructed = construct.call(type, #{ "0": 123 });

assert(constructed["_0"] == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " + constructed["_0"]);
assert(constructed[0] == 123, "Value was constructed incorrectly, expected constructed.foo to be 123 but got " + constructed[0]);
14 changes: 8 additions & 6 deletions assets/tests/display/print_value_by_default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ local expected_vec3_debug = [[
ReflectAllocationId(*anything*),
),
},
reflect_path: ParsedPath(
[],
),
reflect_path: ReferencePath {
one_indexed: false,
path: [],
},
}
]]
-- normalize allocation ids before comparison so tests don't fail on runtime-generated ids
Expand All @@ -49,9 +50,10 @@ ReflectReference {
),
),
},
reflect_path: ParsedPath(
[],
),
reflect_path: ReferencePath {
one_indexed: false,
path: [],
},
}
]]

Expand Down
2 changes: 1 addition & 1 deletion assets/tests/get_component/component_no_component_data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ local entity = world._get_entity_with_test_component("CompWithDefault")
local retrieved = world.get_component(entity, component)

assert(retrieved ~= nil, "Component was not found")
assert(retrieved._1 == "Initial Value", "Component data was not retrieved correctly, retrieved._1 was: " .. retrieved._1)
assert(retrieved[1] == "Initial Value", "Component data was not retrieved correctly, retrieved._1 was: " .. retrieved[1])
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ let entity = world._get_entity_with_test_component.call("CompWithDefault");
let retrieved = world.get_component.call(entity, component);

assert(type_of(retrieved) != "()", "Component was not found");
assert(retrieved["_0"] == "Initial Value", "Component data was not retrieved correctly, retrieved._0 was: " + retrieved["_0"]);
assert(retrieved[0] == "Initial Value", "Component data was not retrieved correctly, retrieved._0 was: " + retrieved[0]);
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ local resource = world.get_type_by_name("ResourceWithDefault")

local retrieved = world.get_resource(resource)
assert(retrieved ~= nil, "Resource should exist")
assert(retrieved._1 == "Initial Value", "Resource should have default value but got: " .. retrieved._1)
assert(retrieved[1] == "Initial Value", "Resource should have default value but got: " .. retrieved[1])
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ let resource = world.get_type_by_name.call("ResourceWithDefault");

let retrieved = world.get_resource.call(resource);
assert(type_of(retrieved) != "()", "Resource should exist");
assert(retrieved["_0"] == "Initial Value", "Resource should have default value but got: " + retrieved["_0"]);
assert(retrieved[0] == "Initial Value", "Resource should have default value but got: " + retrieved[0]);
6 changes: 3 additions & 3 deletions assets/tests/query/query_can_access_components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ world.insert_component(entity_a, componentC, construct(componentC, {
local query_result = world.query():component(componentA):component(componentA):component(componentC):build()

assert(#query_result == 1, "Expected 1 result, got " .. #query_result)
for i,result in pairs(query_result) do
for i, result in pairs(query_result) do
assert(result:entity():index() == entity_a:index(), "Expected entity_a, got " .. result:entity():index())
components = result:components()
assert(#components == 3, "Expected 3 components, got " .. #components)
A = components[1]
B = components[2]
C = components[3]
assert(A._1 == "Default", "Expected 'Default', got: " .. A._1)
assert(B._1 == "Default", "Expected 'Default', got: " .. B._1)
assert(A[1] == "Default", "Expected 'Default', got: " .. A[1])
assert(B[1] == "Default", "Expected 'Default', got: " .. B[1])
assert(C.strings[1] == "asd", "Expected 'asd', got: " .. C.strings[1])
end
4 changes: 2 additions & 2 deletions assets/tests/query/query_can_access_components.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for (result, i) in query_result {
let A = components[0];
let B = components[1];
let C = components[2];
assert(A["_0"] == "Default", "Expected 'Default', got: " + A["_0"]);
assert(B["_0"] == "Default", "Expected 'Default', got: " + B["_0"]);
assert(A[0] == "Default", "Expected 'Default', got: " + A[0]);
assert(B[0] == "Default", "Expected 'Default', got: " + B[0]);
assert(C.strings[0] == "asd", "Expected 'asd', got: " + C.strings[0]);
}
20 changes: 15 additions & 5 deletions assets/tests/set/set_primitives_works.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Resource = world.get_type_by_name("TestResourceWithVariousFields")
local SimpleType = types.SimpleType
local resource = world.get_resource(Resource)

resource.string = "Hello, World!"
Expand All @@ -7,28 +8,37 @@ resource.int = 42
resource.float = 3.0
resource.vec_usize = { 1, 2 }
resource.string_map = { foo = "hello", zoo = "world" }
resource.string_set = { "foo", "zoo" }

assert(resource.string == "Hello, World!", "Expected 'Hello, World!', got " .. resource.string)
assert(resource.bool == true, "Expected true, got " .. tostring(resource.bool))
assert(resource.int == 42, "Expected 42, got " .. resource.int)
assert(resource.float == 3.0, "Expected 3.14, got " .. resource.float)
assert(resource.vec_usize[1] == 1, "Expected 1, got " .. resource.vec_usize[1])
assert(resource.string_map:len() == 2, "Expected 2, got " .. resource.string_map:len())
-- assert(resource.string_map["foo"] == "hello", "Expected 'hello', got " .. resource.string_map["foo"])
-- assert(resource.string_map["zoo"] == "world", "Expected 'world', got " .. resource.string_map["zoo"])
assert(resource.string_map["foo"] == "hello", "Expected 'hello', got " .. resource.string_map["foo"])
assert(resource.string_map["zoo"] == "world", "Expected 'world', got " .. resource.string_map["zoo"])
assert(resource.string_set["foo"] ~= nil, "Expected something, got " .. resource.string_set["foo"])
local key_simple_type = construct(SimpleType, {
inner = "foo"
})
assert(resource.simple_type_map[key_simple_type],
"Expected 'bar', got " .. tostring(resource.simple_type_map[key_simple_type]))

resource.string = "Goodbye, World!"
resource.bool = false
resource.int = 24
resource.float = 1.0
resource.vec_usize = { 3, 4 }
resource.string_map = { foo = "goodbye", zoo = "world" }
resource.simple_type_map[key_simple_type] = "bye"

assert(resource.string == "Goodbye, World!", "Expected 'Goodbye, World!', got " .. resource.string)
assert(resource.bool == false, "Expected false, got " .. tostring(resource.bool))
assert(resource.int == 24, "Expected 24, got " .. resource.int)
assert(resource.float == 1.0, "Expected 1.41, got " .. resource.float)
assert(resource.string_map:len() == 2, "Expected 2, got " .. resource.string_map:len())
-- assert(resource.string_map["foo"] == "goodbye", "Expected 'goodbye', got " .. resource.string_map["foo"])
-- assert(resource.string_map["zoo"] == "world", "Expected 'world', got " .. resource.string_map["zoo"])

assert(resource.string_map["foo"] == "goodbye", "Expected 'goodbye', got " .. resource.string_map["foo"])
assert(resource.string_map["zoo"] == "world", "Expected 'world', got " .. resource.string_map["zoo"])
assert(resource.simple_type_map[key_simple_type],
"Expected 'bye', got " .. tostring(resource.simple_type_map[key_simple_type]))
20 changes: 18 additions & 2 deletions crates/bevy_mod_scripting_asset/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,28 @@ pub enum Language {
/// The Rune scripting language
Rune,
/// An external scripting language
External(Cow<'static, str>),
External {
/// The identifier of the language
name: Cow<'static, str>,
/// If this language is one indexed
one_indexed: bool,
},
/// Set if none of the asset path to language mappers match
#[default]
Unknown,
}

impl Language {
/// Returns true if the language is one-indexed and requires correction when converting
pub fn one_indexed(&self) -> bool {
match &self {
Language::Lua => true,
Language::External { one_indexed, .. } => *one_indexed,
_ => false,
}
}
}

impl std::fmt::Display for Language {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Cow::<'static, str>::from(self).fmt(f)
Expand All @@ -31,7 +47,7 @@ impl From<&Language> for Cow<'static, str> {
Language::Rhai => Cow::Borrowed("Rhai"),
Language::Lua => Cow::Borrowed("Lua"),
Language::Rune => Cow::Borrowed("Rune"),
Language::External(cow) => cow.clone(),
Language::External { name, .. } => name.clone(),
Language::Unknown => Cow::Borrowed("Unknown"),
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_mod_scripting_bindings/src/conversions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Conversions from untyped reflected values to concrete values
mod primitive;

pub use primitive::*;
Loading
Loading