{lyn8865} Adding DataTypes::ScriptProcessorFallbackLogic (#6396)

* {lyn8865} Adding DataTypes::ScriptProcessorFallbackLogic

- Give the user an option how to handle fallback logic for script rules

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* the new code found an error in a Python script... it seems to work!

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>

* fixing up the regression test

Signed-off-by: Jackson <23512001+jackalbe@users.noreply.github.com>

* dump version number

Signed-off-by: Allen Jackson <23512001+jackalbe@users.noreply.github.com>
This commit is contained in:
Allen Jackson
2022-01-05 16:08:58 -06:00
committed by GitHub
parent 8a271cabb3
commit 6c3d5c434e
8 changed files with 126 additions and 9 deletions
@@ -173,10 +173,13 @@ namespace AZ::SceneAPI::Behaviors
UnloadPython();
}
bool ScriptProcessorRuleBehavior::LoadPython(const AZ::SceneAPI::Containers::Scene& scene, AZStd::string& scriptPath)
bool ScriptProcessorRuleBehavior::LoadPython(const AZ::SceneAPI::Containers::Scene& scene, AZStd::string& scriptPath, Events::ProcessingResult& fallbackResult)
{
using namespace AZ::SceneAPI;
fallbackResult = Events::ProcessingResult::Failure;
int scriptDiscoveryAttempts = 0;
const AZ::SceneAPI::Containers::SceneManifest& manifest = scene.GetManifest();
const Containers::SceneManifest& manifest = scene.GetManifest();
auto view = Containers::MakeDerivedFilterView<DataTypes::IScriptProcessorRule>(manifest.GetValueStorage());
for (const auto& scriptItem : view)
{
@@ -188,6 +191,8 @@ namespace AZ::SceneAPI::Behaviors
}
++scriptDiscoveryAttempts;
fallbackResult = (scriptItem.GetScriptProcessorFallbackLogic() == DataTypes::ScriptProcessorFallbackLogic::ContinueBuild) ?
Events::ProcessingResult::Ignored : Events::ProcessingResult::Failure;
// check for file exist via absolute path
if (!IO::FileIOBase::GetInstance()->Exists(scriptFilename.c_str()))
@@ -301,7 +306,8 @@ namespace AZ::SceneAPI::Behaviors
}
};
if (LoadPython(context.GetScene(), scriptPath))
[[maybe_unused]] Events::ProcessingResult fallbackResult;
if (LoadPython(context.GetScene(), scriptPath, fallbackResult))
{
EditorPythonConsoleNotificationHandler logger;
m_editorPythonEventsInterface->ExecuteWithLock(executeCallback);
@@ -333,8 +339,9 @@ namespace AZ::SceneAPI::Behaviors
return Events::ProcessingResult::Ignored;
}
Events::ProcessingResult fallbackResult;
AZStd::string scriptPath;
if (LoadPython(scene, scriptPath))
if (LoadPython(scene, scriptPath, fallbackResult))
{
AZStd::string manifestUpdate;
auto executeCallback = [&scene, &manifestUpdate, &scriptPath]()
@@ -349,6 +356,12 @@ namespace AZ::SceneAPI::Behaviors
EditorPythonConsoleNotificationHandler logger;
m_editorPythonEventsInterface->ExecuteWithLock(executeCallback);
// if the returned scene manifest is empty then ignore the script update
if (manifestUpdate.empty())
{
return Events::ProcessingResult::Ignored;
}
EntityUtilityBus::Broadcast(&EntityUtilityBus::Events::ResetEntityContext);
AZ::Interface<Prefab::PrefabSystemComponentInterface>::Get()->RemoveAllTemplates();
@@ -364,6 +377,11 @@ namespace AZ::SceneAPI::Behaviors
}
return Events::ProcessingResult::Success;
}
else
{
// if the manifest was not updated by the script, then return back the fallback result
return fallbackResult;
}
}
return Events::ProcessingResult::Ignored;
}