2021-09-22 17:37:50 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// MassBuilderSaveTool
|
|
|
|
// Copyright (C) 2021 Guillaume Jacquemin
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <Corrade/Containers/Array.h>
|
|
|
|
#include <Corrade/Containers/GrowableArray.h>
|
|
|
|
#include <Corrade/Containers/StaticArray.h>
|
|
|
|
|
|
|
|
#include <Magnum/Magnum.h>
|
|
|
|
|
|
|
|
#include "Types/UnrealPropertyBase.h"
|
|
|
|
|
|
|
|
#include "PropertySerialiser.h"
|
|
|
|
|
|
|
|
using namespace Corrade;
|
|
|
|
using namespace Magnum;
|
|
|
|
|
|
|
|
class UESaveFile {
|
|
|
|
public:
|
|
|
|
explicit UESaveFile(std::string filepath);
|
|
|
|
|
|
|
|
auto valid() const -> bool;
|
|
|
|
auto lastError() const -> std::string const&;
|
|
|
|
|
|
|
|
auto reloadData() -> bool;
|
|
|
|
|
2021-09-22 18:23:16 +02:00
|
|
|
template<typename T>
|
|
|
|
std::enable_if_t<std::is_base_of<UnrealPropertyBase, T>::value, T*>
|
|
|
|
at(const std::string& name) {
|
|
|
|
for(auto& prop : _properties) {
|
|
|
|
if(prop->name == name) {
|
|
|
|
return static_cast<T*>(prop.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-09-22 17:37:50 +02:00
|
|
|
|
|
|
|
auto props() -> Containers::ArrayView<UnrealPropertyBase::ptr>;
|
|
|
|
|
|
|
|
auto saveToFile() -> bool;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void loadData();
|
|
|
|
|
|
|
|
bool _valid{false};
|
|
|
|
std::string _lastError;
|
|
|
|
|
|
|
|
std::string _filepath;
|
|
|
|
|
2021-09-22 19:46:41 +02:00
|
|
|
bool _noReloadAfterSave = false;
|
|
|
|
|
2021-09-22 18:22:48 +02:00
|
|
|
Containers::StaticArray<4, char> _magicBytes{'G', 'V', 'A', 'S'};
|
2021-09-22 17:37:50 +02:00
|
|
|
|
|
|
|
UnsignedInt _saveVersion = 0;
|
|
|
|
UnsignedInt _packageVersion = 0;
|
|
|
|
struct {
|
|
|
|
UnsignedShort major = 0;
|
|
|
|
UnsignedShort minor = 0;
|
|
|
|
UnsignedShort patch = 0;
|
|
|
|
UnsignedInt build = 0;
|
|
|
|
std::string buildId;
|
|
|
|
} _engineVersion;
|
|
|
|
|
|
|
|
UnsignedInt _customFormatVersion = 0;
|
|
|
|
struct CustomFormatDataEntry {
|
|
|
|
Containers::StaticArray<16, char> id;
|
|
|
|
Int value = 0;
|
|
|
|
};
|
|
|
|
Containers::Array<CustomFormatDataEntry> _customFormatData;
|
|
|
|
|
|
|
|
std::string _saveType;
|
|
|
|
|
|
|
|
Containers::Array<UnrealPropertyBase::ptr> _properties;
|
|
|
|
|
|
|
|
PropertySerialiser _propSerialiser;
|
|
|
|
};
|