|
|
@@ -156,34 +156,91 @@ void AEEditorCommon::Stop()
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-bool AEEditorCommon::ReadPreferences(String& path, JSONValue& prefs, const String& propertyName)
|
|
|
+void AEEditorCommon::CreateDefaultPreferences(String& path, JSONValue& prefs)
|
|
|
{
|
|
|
- if (!path.EndsWith(".json"))
|
|
|
- path.Append(".json");
|
|
|
+ // Note there is some duplication here with the editor's
|
|
|
+ // TypeScript preference code, this is due to the preferences for
|
|
|
+ // the editor window needing to be available at window creation time
|
|
|
+ // It could be better to split this all out to a native, scriptable
|
|
|
+ // preferences object
|
|
|
|
|
|
- SharedPtr<File> file(new File(context_, path, FILE_READ));
|
|
|
+ LOGINFOF("Creating default Atomic Editor preferences: %s", path.CString());
|
|
|
|
|
|
SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
|
|
|
|
|
|
- if (!jsonFile->BeginLoad(*file))
|
|
|
- return false;
|
|
|
+ JSONValue& root = jsonFile->GetRoot();
|
|
|
+
|
|
|
+ root.Clear();
|
|
|
+ root["recentProjects"] = JSONArray();
|
|
|
+
|
|
|
+ JSONValue editorWindow;
|
|
|
+ editorWindow["x"] = 0;
|
|
|
+ editorWindow["y"] = 0;
|
|
|
+ editorWindow["width"] = 0;
|
|
|
+ editorWindow["height"] = 0;
|
|
|
+ editorWindow["monitor"] = 0;
|
|
|
+ editorWindow["maximized"] = true;
|
|
|
+
|
|
|
+ JSONValue playerWindow;
|
|
|
+ playerWindow["x"] = 0;
|
|
|
+ playerWindow["y"] = 0;
|
|
|
+ playerWindow["width"] = 0;
|
|
|
+ playerWindow["height"] = 0;
|
|
|
+ playerWindow["monitor"] = 0;
|
|
|
+ playerWindow["maximized"] = true;
|
|
|
+
|
|
|
+ root["editorWindow"] = editorWindow;
|
|
|
+ root["playerWindow"] = playerWindow;
|
|
|
+
|
|
|
+ SharedPtr<File> file(new File(context_, path, FILE_WRITE));
|
|
|
+
|
|
|
+ jsonFile->Save(*file, " ");
|
|
|
+
|
|
|
+ prefs = root;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+bool AEEditorCommon::ReadPreferences()
|
|
|
+{
|
|
|
+ FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
+ String path = fileSystem->GetAppPreferencesDir("AtomicEditor", "Preferences");
|
|
|
+ path += "prefs.json";
|
|
|
|
|
|
- JSONValue root = jsonFile->GetRoot();
|
|
|
+ JSONValue prefs;
|
|
|
|
|
|
- if (propertyName.Length() > 0)
|
|
|
+ if (!fileSystem->FileExists(path))
|
|
|
+ {
|
|
|
+ CreateDefaultPreferences(path, prefs);
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- if (root.Contains(propertyName))
|
|
|
+ SharedPtr<File> file(new File(context_, path, FILE_READ));
|
|
|
+ SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
|
|
|
+
|
|
|
+ if (!jsonFile->BeginLoad(*file))
|
|
|
{
|
|
|
- prefs = root.Get(propertyName);
|
|
|
+ file->Close();
|
|
|
+ CreateDefaultPreferences(path, prefs);
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ prefs = jsonFile->GetRoot();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ if (!prefs.IsObject() || !prefs["editorWindow"].IsObject())
|
|
|
{
|
|
|
- prefs = root;
|
|
|
+ CreateDefaultPreferences(path, prefs);
|
|
|
}
|
|
|
|
|
|
- file->Close();
|
|
|
+ JSONValue& editorWindow = prefs["editorWindow"];
|
|
|
+
|
|
|
+ engineParameters_["WindowPositionX"] = editorWindow["x"].GetUInt();
|
|
|
+ engineParameters_["WindowPositionY"] = editorWindow["y"].GetUInt();
|
|
|
+ engineParameters_["WindowWidth"] = editorWindow["width"].GetUInt();
|
|
|
+ engineParameters_["WindowHeight"] = editorWindow["height"].GetUInt();
|
|
|
+ engineParameters_["WindowMaximized"] = editorWindow["maximized"].GetBool();
|
|
|
|
|
|
return true;
|
|
|
}
|