From 3f676e09661dae1d016e5b88c0a1f3db7eba3643 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 23 Aug 2020 14:29:17 -0500 Subject: [PATCH] Adds sorting to the settings class so when it saves out to file, it puts them in alphabetical order which keeps things consistent. --- Engine/source/util/settings.cpp | 52 +++++++++++++++++++++------------ Engine/source/util/settings.h | 6 +++- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/Engine/source/util/settings.cpp b/Engine/source/util/settings.cpp index 299898e8d..6dc23e9a7 100644 --- a/Engine/source/util/settings.cpp +++ b/Engine/source/util/settings.cpp @@ -142,28 +142,32 @@ void Settings::buildGroupString(String &name, const UTF8 *settingName) if(mGroupStack.size() > 0) { 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 - 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]); - } - } + } + } // tack on a final "/" name.insert(name.size()-1, "/"); if(dStrlen(settingName) > 0) name.insert(name.size()-1, settingName); - } else - name = settingName; + } + else + { + name = settingName; + } } void Settings::clearAllFields() @@ -238,8 +242,8 @@ bool Settings::write() SimFieldDictionary::Entry* fieldEntry = *itr; 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); } @@ -622,11 +626,15 @@ void SettingSaveNode::buildDocument(SimXMLDocument *document, bool skipWrite) if(!mIsGroup && !skipWrite) { - document->pushNewElement("Setting"); - document->setAttribute("name", mName); + document->pushNewElement("Setting"); + document->setAttribute("name", mName); document->addText(mValue); - } else + } + else { + mSettingNodes.sort(_NodeCompare); + mGroupNodes.sort(_NodeCompare); + for(S32 i=0; ipopElement(); } +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);") { StringTableEntry fieldName = StringTable->insert( settingName ); diff --git a/Engine/source/util/settings.h b/Engine/source/util/settings.h index 10fe2305c..6db4c81bb 100644 --- a/Engine/source/util/settings.h +++ b/Engine/source/util/settings.h @@ -66,6 +66,8 @@ public: //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* findNextValue(); + + }; class SettingSaveNode @@ -105,6 +107,8 @@ public: void buildDocument(SimXMLDocument *document, bool skipWrite = false); void clear(); + + static S32 _NodeCompare(SettingSaveNode* const* a, SettingSaveNode* const* b); }; -#endif \ No newline at end of file +#endif