Browse Source

ReadPreferences function unification

rsredsq 10 years ago
parent
commit
b21798cf37

+ 17 - 2
Source/AtomicEditor/Application/AEEditorApp.cpp

@@ -92,7 +92,7 @@ void AEEditorApp::Setup()
 
 
 #ifdef ATOMIC_DEV_BUILD
 #ifdef ATOMIC_DEV_BUILD
     engineParameters_["ResourcePrefixPath"] = "";
     engineParameters_["ResourcePrefixPath"] = "";
-    String resourcePaths = env->GetCoreDataDir() + ";" +  env->GetEditorDataDir();
+    String resourcePaths = env->GetCoreDataDir() + ";" + env->GetEditorDataDir();
     // for dev builds, add the compile editor scripts from artifacts
     // for dev builds, add the compile editor scripts from artifacts
     resourcePaths += ";" + env->GetRootSourceDir() + "Artifacts/Build/Resources/EditorData/";
     resourcePaths += ";" + env->GetRootSourceDir() + "Artifacts/Build/Resources/EditorData/";
     engineParameters_["ResourcePaths"] = resourcePaths;
     engineParameters_["ResourcePaths"] = resourcePaths;
@@ -102,14 +102,29 @@ void AEEditorApp::Setup()
     engineParameters_["ResourcePrefixPath"] = "../Resources";
     engineParameters_["ResourcePrefixPath"] = "../Resources";
 
 
 #else
 #else
-	engineParameters_["ResourcePrefixPath"] = filesystem->GetProgramDir() + "Resources";
+    engineParameters_["ResourcePrefixPath"] = filesystem->GetProgramDir() + "Resources";
 #endif
 #endif
 
 
     engineParameters_["ResourcePaths"] = "CoreData;EditorData";
     engineParameters_["ResourcePaths"] = "CoreData;EditorData";
 
 
 #endif // ATOMIC_DEV_BUILD
 #endif // ATOMIC_DEV_BUILD
 
 
+    String prefsPath = filesystem->GetAppPreferencesDir("AtomicEditor", "Preferences");
+    prefsPath += "prefs.json";
 
 
+    JSONValue editorWindow;
+
+    if (ReadPreferences(prefsPath, &editorWindow, "editorWindow"))
+    {
+        if (editorWindow.IsObject())
+        {
+            engineParameters_["WindowPositionX"] = editorWindow.Get("x").GetUInt();
+            engineParameters_["WindowPositionY"] = editorWindow.Get("y").GetUInt();
+            engineParameters_["WindowWidth"] = editorWindow.Get("width").GetUInt();
+            engineParameters_["WindowHeight"] = editorWindow.Get("height").GetUInt();
+            engineParameters_["FullScreen"] = editorWindow.Get("fullscreen").GetBool();
+        }
+    }
 }
 }
 
 
 void AEEditorApp::Stop()
 void AEEditorApp::Stop()

+ 15 - 20
Source/AtomicEditor/Application/AEEditorCommon.cpp

@@ -20,7 +20,6 @@
 #include <ToolCore/ToolEnvironment.h>
 #include <ToolCore/ToolEnvironment.h>
 
 
 #include <Atomic/IO/File.h>
 #include <Atomic/IO/File.h>
-#include <Atomic/Resource/JSONFile.h>
 
 
 #ifdef ATOMIC_DOTNET
 #ifdef ATOMIC_DOTNET
 #include <AtomicNET/NETCore/NETHost.h>
 #include <AtomicNET/NETCore/NETHost.h>
@@ -130,8 +129,6 @@ void AEEditorCommon::Setup()
     ToolSystem* system = new ToolSystem(context_);
     ToolSystem* system = new ToolSystem(context_);
     context_->RegisterSubsystem(system);
     context_->RegisterSubsystem(system);
 
 
-    ReadPreferences();
-
 }
 }
 
 
 void AEEditorCommon::Stop()
 void AEEditorCommon::Stop()
@@ -156,15 +153,12 @@ void AEEditorCommon::Stop()
 }
 }
 
 
 
 
-bool AEEditorCommon::ReadPreferences()
+bool AEEditorCommon::ReadPreferences(String path, JSONValue* prefs, String object)
 {
 {
+    if (!path.EndsWith(".json"))
+        path += ".json";
 
 
-    FileSystem* fileSystem = GetSubsystem<FileSystem>();
-
-    String preferencesPath = fileSystem->GetAppPreferencesDir("AtomicEditor", "Preferences");
-    preferencesPath += "prefs.json";
-
-    SharedPtr<File> file(new File(context_, preferencesPath, FILE_READ));
+    SharedPtr<File> file(new File(context_, path, FILE_READ));
 
 
     SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
     SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
 
 
@@ -173,16 +167,17 @@ bool AEEditorCommon::ReadPreferences()
 
 
     JSONValue root = jsonFile->GetRoot();
     JSONValue root = jsonFile->GetRoot();
 
 
-    JSONValue editorWindow = root.Get("editorWindow");
-
-    if (!editorWindow.IsObject())
-        return false;
-
-    engineParameters_["WindowPositionX"] = editorWindow.Get("x").GetUInt();
-    engineParameters_["WindowPositionY"] = editorWindow.Get("y").GetUInt();
-    engineParameters_["WindowWidth"] = editorWindow.Get("width").GetUInt();
-    engineParameters_["WindowHeight"] = editorWindow.Get("height").GetUInt();
-    engineParameters_["FullScreen"] = editorWindow.Get("fullscreen").GetBool();
+    if (object.Length() > 0)
+    {
+        if (root.Contains(object)) 
+        {
+            *prefs = root.Get(object);
+        }
+    }
+    else
+    {
+        *prefs = root;
+    }
 
 
     file->Close();
     file->Close();
 
 

+ 3 - 2
Source/AtomicEditor/Application/AEEditorCommon.h

@@ -8,6 +8,7 @@
 #pragma once
 #pragma once
 
 
 #include <Atomic/Engine/Application.h>
 #include <Atomic/Engine/Application.h>
+#include <Atomic/Resource/JSONFile.h>
 
 
 using namespace Atomic;
 using namespace Atomic;
 
 
@@ -36,12 +37,12 @@ public:
 
 
 protected:
 protected:
 
 
+    bool ReadPreferences(String path, JSONValue* prefs, String object = "");
+    
     SharedPtr<JSVM> vm_;
     SharedPtr<JSVM> vm_;
 
 
 private:
 private:
 
 
-    bool ReadPreferences();
-
 };
 };
 
 
 }
 }