-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProjectSetting.cpp
More file actions
59 lines (56 loc) · 1.58 KB
/
Copy pathProjectSetting.cpp
File metadata and controls
59 lines (56 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "ProjectSetting.h"
#include "AssetDatabase.h"
#include "Core/Util.h"
#include "Core/Logger.h"
#include "Core/FileSystem.h"
#include "Game/GameManager.h"
#include <fstream>
#include <optional>
namespace sh::editor
{
ProjectSetting::ProjectSetting() :
version(0),
startingWorldUUID(core::UUID::GenerateEmptyUUID()),
lastWorldUUID(core::UUID::GenerateEmptyUUID())
{
}
ProjectSetting::~ProjectSetting()
{
}
SH_EDITOR_API auto ProjectSetting::Serialize() const -> core::Json
{
core::Json json;
json["version"] = version;
json["startingWorld"] = startingWorldUUID.ToString();
json["lastWorld"] = lastWorldUUID.ToString();
return json;
}
SH_EDITOR_API void ProjectSetting::Deserialize(const core::Json& json)
{
if (json.contains("version"))
version = json["version"];
if (json.contains("startingWorld"))
startingWorldUUID = core::UUID{ json["startingWorld"].get_ref<const std::string&>() };
if (json.contains("lastWorld"))
lastWorldUUID = core::UUID{ json["lastWorld"].get_ref<const std::string&>() };
}
SH_EDITOR_API void ProjectSetting::Save(const std::filesystem::path& path)
{
SH_INFO_FORMAT("Save project setting: {}", path.u8string());
if (!core::FileSystem::SaveText(Serialize(), path))
SH_ERROR_FORMAT("Save error! {}", path.u8string());
}
SH_EDITOR_API void ProjectSetting::Load(const std::filesystem::path& path)
{
auto stringOpt = core::FileSystem::LoadText(path);
if (stringOpt.has_value())
{
if (stringOpt.value().empty())
Save(path);
else
Deserialize(core::Json::parse(stringOpt.value()));
}
else
Save(path);
}
}