Repository: 4ian/GDevelop
File: Core/GDCore/Extensions/Metadata/ParameterMetadataTools.cpp (C++)

Code before:
  std::set<gd::String> objectNamesInContainer =
      outputObjectsContainer.GetAllObjectNames();
  for (const auto& objectName : objectNamesInContainer) {
    if (allObjectNames.find(objectName) == allObjectNames.end()) {
      outputObjectsContainer.RemoveObject(objectName);
    }
  }

  // Remove behaviors of objects that are not in the parameters anymore.
  for (const auto& objectName : allObjectNames) {
    if (!outputObjectsContainer.HasObjectNamed(objectName)) {
      // Should not happen.
      continue;
    }

    auto& object = outputObjectsContainer.GetObject(objectName);
    for (const auto& behaviorName : object.GetAllBehaviorNames()) {
      const auto& allBehaviorNames = allObjectBehaviorNames[objectName];
      if (allBehaviorNames.find(behaviorName) == allBehaviorNames.end()) {
        object.RemoveBehavior(behaviorName);
      }
    }
  }
}

void ParameterMetadataTools::ForEachParameterMatchingSearch(
    const std::vector<const ParameterMetadataContainer*>&
        parametersVectorsList,
    const gd::String& search,
    std::function<void(const gd::ParameterMetadata&)> cb) {
  for (auto it = parametersVectorsList.rbegin();
       it != parametersVectorsList.rend();
       ++it) {
    const ParameterMetadataContainer* parametersVector = *it;

    for (const auto &parameterMetadata :
         parametersVector->GetInternalVector()) {
      if (parameterMetadata->GetName().FindCaseInsensitive(search) !=
          gd::String::npos)
        cb(*parameterMetadata);
    }
  }
}

bool ParameterMetadataTools::Has(
      const std::vector<const ParameterMetadataContainer*>& parametersVectorsList,
      const gd::String& parameterName) {
  for (auto it = parametersVectorsList.rbegin();
       it != parametersVectorsList.rend();
       ++it) {
    const ParameterMetadataContainer* parametersVector = *it;

Review comment (suggestion):
Actually, I think it's legit to add behavior parameters to require capabilities on an object without any specified type.

Code after:
    }
  }

  // Remove objects that are not in the parameters anymore.
  std::set<gd::String> objectNamesInContainer =
      outputObjectsContainer.GetAllObjectNames();
  for (const auto& objectName : objectNamesInContainer) {
    if (allObjectNames.find(objectName) == allObjectNames.end()) {
      outputObjectsContainer.RemoveObject(objectName);
    }
  }

  // Remove behaviors of objects that are not in the parameters anymore.
  for (const auto& objectName : allObjectNames) {
    if (!outputObjectsContainer.HasObjectNamed(objectName)) {
      // Should not happen.
      continue;
    }

    auto& object = outputObjectsContainer.GetObject(objectName);
    const auto& allBehaviorNames = allObjectNonDefaultBehaviorNames[objectName];
    for (const auto& behaviorName : object.GetAllBehaviorNames()) {
      if (object.GetBehavior(behaviorName).IsDefaultBehavior()) {
        // Default behaviors are already ensured to be all present
        // (and no more than required by the object type).
        continue;
      }

      if (allBehaviorNames.find(behaviorName) == allBehaviorNames.end()) {
        object.RemoveBehavior(behaviorName);
      }
    }
  }
}

void ParameterMetadataTools::ForEachParameterMatchingSearch(
    const std::vector<const ParameterMetadataContainer*>&
        parametersVectorsList,
    const gd::String& search,
    std::function<void(const gd::ParameterMetadata&)> cb) {
  for (auto it = parametersVectorsList.rbegin();
       it != parametersVectorsList.rend();
       ++it) {
    const ParameterMetadataContainer* parametersVector = *it;

    for (const auto &parameterMetadata :
         parametersVector->GetInternalVector()) {
      if (parameterMetadata->GetName().FindCaseInsensitive(search) !=
          gd::String::npos)
        cb(*parameterMetadata);
    }