add entity on_save event and SAVED_DATA variable

This commit is contained in:
MihailRis
2024-07-05 18:35:46 +03:00
parent e301dbe164
commit 08cc78289d
6 changed files with 36 additions and 4 deletions
+12 -1
View File
@@ -112,6 +112,10 @@ void Entities::despawn(entityid_t id) {
}
}
void Entities::onSave(const Entity& entity) {
scripting::on_entity_save(entity);
}
dynamic::Value Entities::serialize(const Entity& entity) {
auto root = dynamic::create_map();
auto& eid = entity.getID();
@@ -140,7 +144,6 @@ dynamic::Value Entities::serialize(const Entity& entity) {
if (rig.config->getName() != def.rigName) {
root->put("rig", rig.config->getName());
}
if (def.save.rig.pose || def.save.rig.textures) {
auto& rigmap = root->putMap("rig");
if (def.save.rig.textures) {
@@ -156,6 +159,14 @@ dynamic::Value Entities::serialize(const Entity& entity) {
}
}
}
auto& scripts = entity.getScripting();
if (!scripts.components.empty()) {
auto& compsMap = root->putMap("comps");
for (auto& comp : scripts.components) {
auto data = scripting::get_component_value(comp->env, "SAVED_DATA");
compsMap.put(comp->name, data);
}
}
return root;
}