mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 19:11:50 +00:00
add entity on_save event and SAVED_DATA variable
This commit is contained in:
parent
e301dbe164
commit
08cc78289d
6 changed files with 36 additions and 4 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ public:
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
void onSave(const Entity& entity);
|
||||
std::vector<Entity> getAllInside(AABB aabb);
|
||||
void despawn(entityid_t id);
|
||||
dynamic::Value serialize(const Entity& entity);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue