feat: loading entities (WIP)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user