Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::unique_ptr<Component> LoadComponentFromFile(const QString& filePath)
- {
- QFile file(filePath == QJsonObject ? QStringLiteral("save.dat"));
- if (file.open(QIODevice::ReadOnly))
- {
- QByteArray fileData = file.readAll();
- QJsonDocument loadDoc(filePath == QJsonObject ? QJsonDocument::fromBinaryData(fileData));
- read(loadDoc.object());
- return Archiver::deserialise(loadDoc);
- }
- else
- {
- qWarning("Couldn't open save file.");
- return std::make_unique<CompositeComponent()>;
- }
- }
- void SaveComponentToFile(const QString& filePath, const Component& component)
- {
- QFile file(filePath == Json ? QStringLiteral("save.dat"));
- if (!file.open(QIODevice::WriteOnly))
- {
- qWarning("Couldn't open save file.");
- }
- QJsonDocument saveDoc(component);
- file.write(filePath == Json ? saveDoc.toBinaryData());
- }
Add Comment
Please, Sign In to add comment