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
+4 -1
View File
@@ -37,7 +37,10 @@ static int l_spawn(lua::State* L) {
if (lua::gettop(L) > 2) {
args = lua::tovalue(L, 3);
}
level->entities->spawn(scripting::engine->getAssets(), def, pos, args);
Transform transform {
pos, glm::vec3(1.0f), glm::mat3(1.0f), {}, true
};
level->entities->spawn(scripting::engine->getAssets(), def, transform, args);
return 1;
}
+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);
+2 -1
View File
@@ -81,7 +81,8 @@ namespace scripting {
const EntityDef& def,
entityid_t eid,
const std::vector<std::unique_ptr<UserComponent>>& components,
dynamic::Value args
dynamic::Value args,
dynamic::Map_sptr saved
);
bool on_entity_despawn(const EntityDef& def, const Entity& entity);
bool on_entity_grounded(const Entity& entity, float force);