feat: loading entities (WIP)

This commit is contained in:
MihailRis
2024-07-05 22:51:03 +03:00
parent 08cc78289d
commit c8666910ce
16 changed files with 129 additions and 38 deletions
+11 -2
View File
@@ -276,7 +276,8 @@ void scripting::on_entity_spawn(
const EntityDef& def,
entityid_t eid,
const std::vector<std::unique_ptr<UserComponent>>& components,
dynamic::Value args
dynamic::Value args,
dynamic::Map_sptr saved
) {
auto L = lua::get_main_thread();
lua::requireglobal(L, STDCOMP);
@@ -296,7 +297,15 @@ void scripting::on_entity_spawn(
lua::pushvalue(L, args);
lua::setfield(L, "ARGS");
lua::createtable(L, 0, 0);
if (saved == nullptr) {
lua::createtable(L, 0, 0);
} else {
if (auto datamap = saved->map(component->name)) {
lua::pushvalue(L, datamap);
} else {
lua::createtable(L, 0, 0);
}
}
lua::setfield(L, "SAVED_DATA");
lua::setfenv(L);