forked from AtomicGameEngine/AtomicGameEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectSettings.cpp
More file actions
185 lines (143 loc) · 4.59 KB
/
ProjectSettings.cpp
File metadata and controls
185 lines (143 loc) · 4.59 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <Atomic/IO/Log.h>
#include <Atomic/IO/File.h>
#include <Atomic/IO/FileSystem.h>
#include <Atomic/Resource/JSONFile.h>
#include "ProjectSettings.h"
namespace ToolCore
{
ProjectSettings::ProjectSettings(Context* context) : Object(context),
desktopSettings_(new DesktopProjectSettings()),
androidSettings_(new AndroidProjectSettings())
{
SetDefault();
}
ProjectSettings::~ProjectSettings()
{
}
void ProjectSettings::SetDefault()
{
name_ = "AtomicProject";
platforms_.Clear();
platforms_.Push("desktop");
}
bool ProjectSettings::GetSupportsDesktop() const
{
return platforms_.Contains("desktop");
}
bool ProjectSettings::GetSupportsAndroid() const
{
return platforms_.Contains("android");
}
bool ProjectSettings::GetSupportsIOS() const
{
return platforms_.Contains("ios");
}
bool ProjectSettings::GetSupportsWeb() const
{
return platforms_.Contains("web");
}
bool ProjectSettings::GetSupportsLinux() const
{
return platforms_.Contains("linux");
}
bool ProjectSettings::GetSupportsPlatform(const String& platform) const
{
return platforms_.Contains(platform);
}
void ProjectSettings::AddSupportedPlatform(const String& platform)
{
if (!ValidPlatform(platform))
{
ATOMIC_LOGERRORF("ProjectPlatformSettings::AddSupportedPlatform - Attempting to add invalid platform: %s", platform.CString());
return;
}
if (platforms_.Contains(platform))
return;
platforms_.Push(platform);
}
bool ProjectSettings::ValidPlatform(const String& platform) const
{
if (platform == "desktop")
return true;
if (platform == "android")
return true;
if (platform == "ios")
return true;
if (platform == "linux")
return true;
if (platform == "web")
return true;
return false;
}
bool ProjectSettings::Load(const String& path)
{
FileSystem* fileSystem = GetSubsystem<FileSystem>();
if (!fileSystem->FileExists(path))
{
ATOMIC_LOGERRORF("No platform settings specified, using default: %s", path.CString());
SetDefault();
return true;
}
SharedPtr<File> file(new File(context_, path));
if (!file->IsOpen())
{
ATOMIC_LOGERRORF("Unable to open platform settings: %s", path.CString());
return false;
}
SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
bool result = jsonFile->Load(*file);
file->Close();
if (!result)
{
ATOMIC_LOGERRORF("Unable to load platform settings: %s", path.CString());
return false;
}
JSONValue& root = jsonFile->GetRoot();
if (!root.IsObject())
{
ATOMIC_LOGERRORF("No root object in platform settings: %s", path.CString());
return false;
}
JSONArray platforms = root["platforms"].GetArray();
platforms_.Clear();
if (!platforms.Size())
{
ATOMIC_LOGERRORF("No platforms array defined in platform settings: %s, using default", path.CString());
SetDefault();
}
else
{
for (unsigned i = 0; i < platforms.Size(); i++)
{
const String& platform = platforms[i].GetString();
if (!ValidPlatform(platform))
{
ATOMIC_LOGERRORF("Unknown platform %s in platform settings: %s, skipping", platform.CString(), path.CString());
continue;
}
platforms_.Push(platform);
}
}
if (!platforms_.Size())
{
ATOMIC_LOGERRORF("No valid platforms defined in platform settings: %s, using default", path.CString());
SetDefault();
}
name_ = root["name"].GetString();
if (!name_.Length())
name_ = "AtomicProject";
desktopSettings_->Read(root);
androidSettings_->Read(root);
return true;
}
void ProjectSettings::Save(const String& path)
{
SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
JSONValue& root = jsonFile->GetRoot();
SharedPtr<File> file(new File(context_, path, FILE_WRITE));
desktopSettings_->Write(root);
androidSettings_->Write(root);
jsonFile->Save(*file, String(" "));
file->Close();
}
}