MassBuilderSaveTool/src/UESaveFile/UESaveFile.h

98 lines
2.9 KiB
C++

#pragma once
// MassBuilderSaveTool
// Copyright (C) 2021-2022 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 <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/Reference.h>
#include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Magnum.h>
#include "Types/UnrealPropertyBase.h"
#include "PropertySerialiser.h"
using namespace Corrade;
using namespace Magnum;
class UESaveFile {
public:
explicit UESaveFile(Containers::String filepath);
auto valid() const -> bool;
auto lastError() const -> Containers::StringView;
auto reloadData() -> bool;
auto saveType() -> Containers::StringView;
template<typename T>
std::enable_if_t<std::is_base_of<UnrealPropertyBase, T>::value, T*>
at(Containers::StringView name) {
for(auto& prop : _properties) {
if(prop->name == name) {
return static_cast<T*>(prop.get());
}
}
return nullptr;
}
void appendProperty(UnrealPropertyBase::ptr prop);
auto props() -> Containers::ArrayView<UnrealPropertyBase::ptr>;
auto saveToFile() -> bool;
private:
void loadData();
bool _valid{false};
Containers::String _lastError;
Containers::String _filepath;
bool _noReloadAfterSave = false;
Containers::StaticArray<4, char> _magicBytes{'G', 'V', 'A', 'S'};
UnsignedInt _saveVersion = 0;
UnsignedInt _packageVersion = 0;
struct {
UnsignedShort major = 0;
UnsignedShort minor = 0;
UnsignedShort patch = 0;
UnsignedInt build = 0;
Containers::String buildId;
} _engineVersion;
UnsignedInt _customFormatVersion = 0;
struct CustomFormatDataEntry {
Containers::StaticArray<16, char> id;
Int value = 0;
};
Containers::Array<CustomFormatDataEntry> _customFormatData;
Containers::String _saveType;
Containers::Array<UnrealPropertyBase::ptr> _properties;
Containers::Reference<PropertySerialiser> _propSerialiser;
};