alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
990 stars 426 forks source link

Add KeyValues.Merge #2184

Open Fyren opened 5 months ago

Fyren commented 5 months ago

AI in Discord brought up that Import/CopySubkeys doesn't do what you want if you want to merge together KVs. Although it does copy the foreign data in, it also replaces the existing data when it does so. To get around this, his workaround was to manually iterate, create, and import:

if (!hKVSource.GotoFirstSubKey(false)) {
    return;
}

char sSectionName[256];
do {
    hKVSource.GetSectionName(sSectionName, sizeof(sSectionName));
    hKVDestination.JumpToKey(sSectionName, true);
    hKVDestination.Import(hKVSource);
    hKVDestination.GoBack();
} while (hKVSource.GotoNextKey(false));

With this PR, you should be able to just do hKVDestination.Merge(hKVSource).