add entity 'save' property support

This commit is contained in:
MihailRis
2024-08-08 17:07:24 +03:00
parent 5b5abd1ab0
commit 51f6f0e629
3 changed files with 24 additions and 8 deletions
+18
View File
@@ -356,6 +356,24 @@ dynamic::Value Entities::serialize(const Entity& entity) {
return root;
}
dynamic::List_sptr Entities::serialize(const std::vector<Entity>& entities) {
auto list = dynamic::create_list();
for (auto& entity : entities) {
if (!entity.getDef().save.enabled) {
continue;
}
level->entities->onSave(entity);
list->put(level->entities->serialize(entity));
}
return list;
}
void Entities::despawn(std::vector<Entity> entities) {
for (auto& entity : entities) {
entity.destroy();
}
}
void Entities::clean() {
for (auto it = entities.begin(); it != entities.end();) {
if (!registry.get<EntityId>(it->second).destroyFlag) {