Switched back to using ids instead of names, added uuids to entities and started work on serialization

This commit is contained in:
2019-02-05 22:23:38 +00:00
parent 92f8fdd510
commit a6e5deb502
8 changed files with 259 additions and 40 deletions

View File

@@ -6,25 +6,25 @@ namespace ecs::lua {
ecs.new_usertype<Entity>("Entity",
"add_component", [] (Entity* thiz, std::string name, Component* component) {
return thiz->add_component(name, component);
return thiz->add_component(ComponentID::get_id({name})[0], component);
},
"has_components", [] (Entity* thiz, sol::variadic_args args) {
std::vector<std::string> names;
for (std::string name : args) {
names.push_back(name);
}
return thiz->has_components(names);
return thiz->has_components(ComponentID::get_id(names));
},
"get_component", [&lua] (Entity* thiz, std::string name) -> sol::object {
// Convert to the correct component type
auto f1 = lua["_internal_to_" + name];
if (f1.valid()) {
return f1(thiz->get_component(name));
return f1(thiz->get_component(ComponentID::get_id({name})[0]));
}
// If the type of the component unknown we assume it a lua object and convert it to the wrapper
auto f2 = lua["_internal_to_LuaWrapper"];
return f2(thiz->get_component(name));
return f2(thiz->get_component(ComponentID::get_id({name})[0]));
}
);
@@ -39,7 +39,7 @@ namespace ecs::lua {
for (std::string name : args) {
names.push_back(name);
}
return thiz->view(names);
return thiz->view(ComponentID::get_id(names));
}
);