Skip to content

Commit

Permalink
[buttonmapper] Fix merging features with duplicate driver primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
garbear committed Aug 19, 2016
1 parent b15053e commit 9bf8e0d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/buttonmapper/ButtonMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,30 @@ void CButtonMapper::MergeFeatures(FeatureVector& features, const FeatureVector&
{
for (const ADDON::JoystickFeature& newFeature : newFeatures)
{
const bool bFound = std::find_if(features.begin(), features.end(),
[newFeature](const ADDON::JoystickFeature& feature)
// Check for duplicate feature name
bool bFound = std::find_if(features.begin(), features.end(),
[&newFeature](const ADDON::JoystickFeature& feature)
{
return feature.Name() == newFeature.Name();
}) != features.end();

// Check for duplicate driver primitives
if (!bFound)
{
const auto& newPrimitives = newFeature.Primitives();

bFound = std::find_if(features.begin(), features.end(),
[&newPrimitives](const ADDON::JoystickFeature& feature)
{
for (const auto& primitive : feature.Primitives())
{
if (std::find(newPrimitives.begin(), newPrimitives.end(), primitive) != newPrimitives.end())
return true; // Found primitive
}
return false; // Didn't find primitive
}) != features.end();
}

if (!bFound)
features.push_back(newFeature);
}
Expand Down

0 comments on commit 9bf8e0d

Please sign in to comment.