ImageComparisonSettings.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <ImageComparisonSettings.h>
  9. #include <AzCore/Settings/SettingsRegistry.h>
  10. namespace AZ::ScriptAutomation
  11. {
  12. void ImageComparisonSettings::GetToleranceLevelsFromSettingsRegistry()
  13. {
  14. auto settingsRegistry = AZ::SettingsRegistry::Get();
  15. if (settingsRegistry)
  16. {
  17. const char* imageComparisonSettingsPath = "/O3DE/ScriptAutomation/ImageComparisonSettings";
  18. m_ready = settingsRegistry->GetObject(m_config, imageComparisonSettingsPath);
  19. }
  20. }
  21. ImageComparisonToleranceLevel* ImageComparisonSettings::FindToleranceLevel(const AZStd::string& name)
  22. {
  23. if (!IsReady())
  24. {
  25. GetToleranceLevelsFromSettingsRegistry();
  26. }
  27. AZ_Assert(IsReady(), "Failed to get image comparison tolerance levels from the settings registry");
  28. size_t foundIndex = m_config.m_toleranceLevels.size();
  29. for (size_t i = 0; i < m_config.m_toleranceLevels.size(); ++i)
  30. {
  31. if (m_config.m_toleranceLevels[i].m_name == name)
  32. {
  33. foundIndex = i;
  34. break;
  35. }
  36. }
  37. if (foundIndex == m_config.m_toleranceLevels.size())
  38. {
  39. return nullptr;
  40. }
  41. return &m_config.m_toleranceLevels[foundIndex];
  42. }
  43. } // namespace AZ::ScriptAutomation