Merge pull request #300 from Areloch/sortedSettings

Adds sorting to the settings class so when it saves out to file
This commit is contained in:
Brian Roberts 2020-08-23 16:26:59 -05:00 committed by GitHub
commit 20479cd818
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 20 deletions

View file

@ -151,7 +151,8 @@ void Settings::buildGroupString(String &name, const UTF8 *settingName)
if(i == 0) if(i == 0)
{ {
name.insert(pos, mGroupStack[i]); name.insert(pos, mGroupStack[i]);
} else }
else
{ {
name.insert(pos, "/"); name.insert(pos, "/");
name.insert(pos+1, mGroupStack[i]); name.insert(pos+1, mGroupStack[i]);
@ -162,9 +163,12 @@ void Settings::buildGroupString(String &name, const UTF8 *settingName)
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 }
else
{
name = settingName; name = settingName;
} }
}
void Settings::clearAllFields() void Settings::clearAllFields()
{ {
@ -625,8 +629,12 @@ void SettingSaveNode::buildDocument(SimXMLDocument *document, bool skipWrite)
document->pushNewElement("Setting"); document->pushNewElement("Setting");
document->setAttribute("name", mName); 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 );

View file

@ -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