Potato Engine
Loading...
Searching...
No Matches
PersistentLevel.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include <fstream>
5#include <filesystem>
6
7struct Vector2;
8
16{
21 PersistentLevel(const std::string& saveFileName);
22 ~PersistentLevel() = default;
23
28 bool LoadStaticActors();
29
36 template <typename Type>
37 Type GetData(std::string key) const;
38
45 template <typename Type>
46 void WriteData(std::string key, Type value);
47
48private:
49 int GetIntData( std::string key ) const;
50 float GetFloatData( std::string key ) const;
51 std::string GetStringData( std::string key ) const;
52 Vector2 GetVector2Data( std::string key ) const;
53
54
55 void WriteIntData( std::string key, int value );
56 void WriteFloatData( std::string key, float value );
57 void WriteStringData( std::string key, std::string value );
58 void WriteVector2Data( std::string key, const Vector2& value );
59
60private:
61 std::filesystem::path saveFileAbsPath;
62};
63
64
65template <typename Type>
66Type PersistentLevel::GetData(std::string key) const {
67 if constexpr (std::is_same_v<Type, int>) {
68 return GetIntData(key);
69 }
70 else if constexpr (std::is_same_v<Type, float>) {
71 return GetFloatData(key);
72 }
73 else if constexpr (std::is_same_v<Type, std::string>) {
74 return GetStringData(key);
75 }
76 else if constexpr (std::is_same_v<Type, Vector2>) {
77 return GetVector2Data(key);
78 }
79}
80
81template <typename Type>
82void PersistentLevel::WriteData(std::string key, Type value) {
83 if constexpr (std::is_same_v<Type, int>) {
84 WriteIntData(key, value);
85 }
86 else if constexpr (std::is_same_v<Type, float>) {
87 WriteFloatData(key, value);
88 }
89 else if constexpr (std::is_same_v<Type, std::string>) {
90 WriteStringData(key, value);
91 }
92 else if constexpr (std::is_same_v<Type, Vector2>) {
93 WriteVector2Data(key, value);
94 }
95}
void WriteData(std::string key, Type value)
Write save data to a key.
Type GetData(std::string key) const
Get save data from a key.
PersistentLevel(const std::string &saveFileName)
Construct level object.
bool LoadStaticActors()
Loads all static actors into the world.
Standard 2-dimensional vector.
Definition Vector2.hpp:11