UESaveFile: add a new API and change some stuff.

This commit is contained in:
Guillaume Jacquemin 2022-04-02 19:53:58 +02:00
parent 213269521d
commit 6b280b2668
2 changed files with 9 additions and 6 deletions

View file

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/Optional.h> #include <Corrade/Containers/Optional.h>
#include <Corrade/Utility/Format.h>
#include <Corrade/Utility/Path.h> #include <Corrade/Utility/Path.h>
#include "BinaryReader.h" #include "BinaryReader.h"
@ -52,6 +52,10 @@ auto UESaveFile::reloadData() -> bool {
return valid(); return valid();
} }
auto UESaveFile::saveType() -> Containers::StringView {
return _saveType;
}
void UESaveFile::appendProperty(UnrealPropertyBase::ptr prop) { void UESaveFile::appendProperty(UnrealPropertyBase::ptr prop) {
auto none_prop = std::move(_properties.back()); auto none_prop = std::move(_properties.back());
_properties.back() = std::move(prop); _properties.back() = std::move(prop);
@ -62,9 +66,6 @@ auto UESaveFile::props() -> Containers::ArrayView<UnrealPropertyBase::ptr> {
return _properties; return _properties;
} }
#include <string>
#include <Corrade/Containers/StringStl.h>
auto UESaveFile::saveToFile() -> bool { auto UESaveFile::saveToFile() -> bool {
BinaryWriter writer{_filepath + ".tmp"_s}; BinaryWriter writer{_filepath + ".tmp"_s};
@ -192,7 +193,7 @@ void UESaveFile::loadData() {
return; return;
} }
arrayReserve(_customFormatData, custom_format_data_size); _customFormatData = Containers::Array<CustomFormatDataEntry>{custom_format_data_size};
for(UnsignedInt i = 0; i < custom_format_data_size; i++) { for(UnsignedInt i = 0; i < custom_format_data_size; i++) {
CustomFormatDataEntry entry; CustomFormatDataEntry entry;

View file

@ -16,7 +16,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/GrowableArray.h> #include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/Reference.h> #include <Corrade/Containers/Reference.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>
@ -41,6 +41,8 @@ class UESaveFile {
auto reloadData() -> bool; auto reloadData() -> bool;
auto saveType() -> Containers::StringView;
template<typename T> template<typename T>
std::enable_if_t<std::is_base_of<UnrealPropertyBase, T>::value, T*> std::enable_if_t<std::is_base_of<UnrealPropertyBase, T>::value, T*>
at(Containers::StringView name) { at(Containers::StringView name) {