2
0
Эх сурвалжийг харах

Adds sorting to the settings class so when it saves out to file, it puts them in alphabetical order which keeps things consistent.

Areloch 5 жил өмнө
parent
commit
3f676e0966

+ 33 - 19
Engine/source/util/settings.cpp

@@ -142,28 +142,32 @@ void Settings::buildGroupString(String &name, const UTF8 *settingName)
    if(mGroupStack.size() > 0)
    if(mGroupStack.size() > 0)
    {
    {
       for(S32 i=0; i < mGroupStack.size(); i++)
       for(S32 i=0; i < mGroupStack.size(); i++)
-	  {
-		 S32 pos = 0;
-		 if(name.size() > 0)
-			pos = name.size()-1;
+      {
+         S32 pos = 0;
+         if(name.size() > 0)
+            pos = name.size()-1;
 
 
          // tack on the "/" in front if this isn't the first
          // tack on the "/" in front if this isn't the first
-		 if(i == 0)
-		 {
-	        name.insert(pos, mGroupStack[i]);
-		 } else
-		 {
-			name.insert(pos, "/");
+         if(i == 0)
+         {
+            name.insert(pos, mGroupStack[i]);
+         }
+         else
+         {
+            name.insert(pos, "/");
             name.insert(pos+1, mGroupStack[i]);
             name.insert(pos+1, mGroupStack[i]);
-		 }
-	  }
+         }
+      }
 
 
 	  // tack on a final "/"
 	  // tack on a final "/"
 	  name.insert(name.size()-1, "/");
 	  name.insert(name.size()-1, "/");
 	  if(dStrlen(settingName) > 0)
 	  if(dStrlen(settingName) > 0)
 	     name.insert(name.size()-1, settingName);
 	     name.insert(name.size()-1, settingName);
-   } else
-	  name = settingName;
+   }
+   else
+   {
+      name = settingName;
+   }
 }
 }
 
 
 void Settings::clearAllFields()
 void Settings::clearAllFields()
@@ -238,8 +242,8 @@ bool Settings::write()
       SimFieldDictionary::Entry* fieldEntry = *itr;
       SimFieldDictionary::Entry* fieldEntry = *itr;
 
 
       String check(fieldEntry->slotName);
       String check(fieldEntry->slotName);
-	  if(check.find("_default") != String::NPos || check.find("_type") != String::NPos)
-		 continue;
+	   if(check.find("_default") != String::NPos || check.find("_type") != String::NPos)
+		  continue;
 
 
 	  node->addValue(fieldEntry->slotName, fieldEntry->value);
 	  node->addValue(fieldEntry->slotName, fieldEntry->value);
    }
    }
@@ -622,11 +626,15 @@ void SettingSaveNode::buildDocument(SimXMLDocument *document, bool skipWrite)
 
 
    if(!mIsGroup && !skipWrite)
    if(!mIsGroup && !skipWrite)
    {
    {
-	  document->pushNewElement("Setting");
-	  document->setAttribute("name", mName);
+      document->pushNewElement("Setting");
+      document->setAttribute("name", mName);
       document->addText(mValue);
       document->addText(mValue);
-   } else
+   }
+   else
    {
    {
+      mSettingNodes.sort(_NodeCompare);
+      mGroupNodes.sort(_NodeCompare);
+
 	  for(S32 i=0; i<mSettingNodes.size(); i++)
 	  for(S32 i=0; i<mSettingNodes.size(); i++)
 	  {
 	  {
          SettingSaveNode *node = mSettingNodes[i];
          SettingSaveNode *node = mSettingNodes[i];
@@ -644,6 +652,12 @@ void SettingSaveNode::buildDocument(SimXMLDocument *document, bool skipWrite)
       document->popElement();
       document->popElement();
 }
 }
 
 
+S32 QSORT_CALLBACK SettingSaveNode::_NodeCompare(SettingSaveNode* const* a, SettingSaveNode* const* b)
+{
+   S32 result = dStrnatcasecmp((*a)->mName.c_str(), (*b)->mName.c_str());
+   return result;
+}
+
 DefineEngineMethod(Settings, setValue, void, (const char * settingName, const char * value), (""), "settingObj.setValue(settingName, value);")
 DefineEngineMethod(Settings, setValue, void, (const char * settingName, const char * value), (""), "settingObj.setValue(settingName, value);")
 {
 {
    StringTableEntry fieldName = StringTable->insert( settingName );
    StringTableEntry fieldName = StringTable->insert( settingName );

+ 5 - 1
Engine/source/util/settings.h

@@ -66,6 +66,8 @@ public:
 	//S32 buildSearchList(const char* pattern, bool deepSearch = false, bool defaultsSearch = false);
 	//S32 buildSearchList(const char* pattern, bool deepSearch = false, bool defaultsSearch = false);
 	const char* findFirstValue(const char* pattern, bool deepSearch = false, bool includeDefaults = false);
 	const char* findFirstValue(const char* pattern, bool deepSearch = false, bool includeDefaults = false);
 	const char* findNextValue();
 	const char* findNextValue();
+
+   
 };
 };
 
 
 class SettingSaveNode
 class SettingSaveNode
@@ -105,6 +107,8 @@ public:
    void buildDocument(SimXMLDocument *document, bool skipWrite = false);
    void buildDocument(SimXMLDocument *document, bool skipWrite = false);
 
 
    void clear();
    void clear();
+
+   static S32 _NodeCompare(SettingSaveNode* const* a, SettingSaveNode* const* b);
 };
 };
 
 
-#endif
+#endif