Repository: 4ian/GDevelop
File: Core/GDCore/IDE/InstructionValidator.cpp (C++)

Code before:
  }
  return true;
}

gd::String InstructionValidator::GetRootVariableName(const gd::String &name) {
  auto dotPosition = name.find('.');
  auto squareBracketPosition = name.find('[');
  if (dotPosition == gd::String::npos &&
      squareBracketPosition == gd::String::npos) {
    return name;
  }
  return name.substr(0, dotPosition < squareBracketPosition
                            ? dotPosition
                            : squareBracketPosition);
};

bool InstructionValidator::HasRequiredBehaviors(
    const gd::Instruction &instruction,
    const gd::InstructionMetadata &instructionMetadata,
    std::size_t objectParameterIndex,
    const gd::ObjectsContainersList &objectsContainersList) {
  auto &objectOrGroupName =
      instruction.GetParameter(objectParameterIndex).GetPlainString();
  for (size_t index = objectParameterIndex + 1;
       index < instructionMetadata.GetParametersCount(); index++) {
    auto &behaviorParameter = instructionMetadata.GetParameter(index);

    auto &parameterType = behaviorParameter.GetValueTypeMetadata();
    if (parameterType.IsObject()) {
      return true;
    }
    if (!parameterType.IsBehavior()) {
      continue;
    }
    auto &behaviorType = behaviorParameter.GetExtraInfo();
    if (behaviorType.empty()) {
      continue;
    }
    if (index >= instruction.GetParametersCount()) {
      return false;
    }
    auto &behaviorName = instruction.GetParameter(index).GetPlainString();
    if (objectsContainersList.GetTypeOfBehaviorInObjectOrGroup(
            objectOrGroupName, behaviorName,
            /** searchInGroups = */ true) != behaviorType) {
      return false;
    }
  }
  return true;
};


Review comment (suggestion):
Here and below, try to const everything:

```suggestion
    const auto &behaviorParameter = instructionMetadata.GetParameter(index);
```

Code after:
    const auto &resourceName =
        instruction.GetParameter(parameterIndex).GetPlainString();
    return projectScopedContainers.GetResourcesContainersList()
        .HasResourceNamed(resourceName);
  }
  return true;
}

gd::String InstructionValidator::GetRootVariableName(const gd::String &name) {
  const auto dotPosition = name.find('.');
  const auto squareBracketPosition = name.find('[');
  if (dotPosition == gd::String::npos &&
      squareBracketPosition == gd::String::npos) {
    return name;
  }
  return name.substr(0, dotPosition < squareBracketPosition
                            ? dotPosition
                            : squareBracketPosition);
};

bool InstructionValidator::HasRequiredBehaviors(
    const gd::Instruction &instruction,
    const gd::InstructionMetadata &instructionMetadata,
    std::size_t objectParameterIndex,
    const gd::ObjectsContainersList &objectsContainersList) {
  if (objectParameterIndex >= instruction.GetParametersCount()) {
    return false;
  }
  const auto &objectOrGroupName =
      instruction.GetParameter(objectParameterIndex).GetPlainString();
  for (size_t index = objectParameterIndex + 1;
       index < instructionMetadata.GetParametersCount(); index++) {
    const auto &behaviorParameter = instructionMetadata.GetParameter(index);

    const auto &parameterType = behaviorParameter.GetValueTypeMetadata();
    if (parameterType.IsObject()) {
      return true;
    }
    if (!parameterType.IsBehavior()) {
      continue;
    }
    const auto &behaviorType = behaviorParameter.GetExtraInfo();
    if (behaviorType.empty()) {
      continue;
    }
    if (index >= instruction.GetParametersCount()) {
      return false;
    }
    const auto &behaviorName = instruction.GetParameter(index).GetPlainString();
    if (objectsContainersList.GetTypeOfBehaviorInObjectOrGroup(
            objectOrGroupName, behaviorName,