void savePrefab(const Path& path) override { auto& selected_entities = m_editor.getSelectedEntities(); if (selected_entities.size() != 1) return; Entity entity = selected_entities[0]; u64 prefab = getPrefab(entity); if (prefab != 0) entity = getPrefabRoot(entity); FS::OsFile file; if (!file.open(path.c_str(), FS::Mode::CREATE_AND_WRITE)) { g_log_error.log("Editor") << "Failed to create " << path.c_str(); return; } Array<Entity> entities(m_editor.getAllocator()); gatherHierarchy(entity, true, entities); OutputBlob blob(m_editor.getAllocator()); SaveEntityGUIDMap entity_map(entities); TextSerializer serializer(blob, entity_map); serializePrefab(m_universe, entities[0], path, serializer); file.write(blob.getData(), blob.getPos()); file.close(); if (prefab == 0) { m_editor.beginCommandGroup(crc32("save_prefab")); Transform tr = m_universe->getTransform(entity); m_editor.destroyEntities(&entities[0], entities.size()); auto* resource_manager = m_editor.getEngine().getResourceManager().get(PrefabResource::TYPE); auto* res = (PrefabResource*)resource_manager->load(path); FS::FileSystem& fs = m_editor.getEngine().getFileSystem(); while (fs.hasWork()) fs.updateAsyncTransactions(); instantiatePrefab(*res, tr.pos, tr.rot, tr.scale); m_editor.endCommandGroup(); } }
static void logErrorToFile(const char*, const char* message) { if (!g_is_error_file_opened) return; g_error_file.write(message, stringLength(message)); g_error_file.flush(); }