Potato Engine
Toggle main menu visibility
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
7
struct
Vector2
;
8
15
struct
PersistentLevel
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
48
private
:
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
60
private
:
61
std::filesystem::path saveFileAbsPath;
62
};
63
64
65
template
<
typename
Type>
66
Type
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
81
template
<
typename
Type>
82
void
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
}
PersistentLevel::WriteData
void WriteData(std::string key, Type value)
Write save data to a key.
Definition
PersistentLevel.hpp:82
PersistentLevel::GetData
Type GetData(std::string key) const
Get save data from a key.
Definition
PersistentLevel.hpp:66
PersistentLevel::PersistentLevel
PersistentLevel(const std::string &saveFileName)
Construct level object.
Definition
PersistentLevel.cpp:17
PersistentLevel::LoadStaticActors
bool LoadStaticActors()
Loads all static actors into the world.
Definition
PersistentLevel.cpp:23
Vector2
Standard 2-dimensional vector.
Definition
Vector2.hpp:11
Core
Datastore
PersistentLevel.hpp
Generated by
1.17.0