Merge pull request #6045 from aws-lumberyard-dev/scripting/fix_translation_reload

If the asset catalog gets reloaded, clear the translation to avoid du…
This commit is contained in:
Luis Sempé
2021-12-03 07:36:54 -08:00
committed by GitHub
421 changed files with 4132 additions and 3986 deletions
@@ -188,7 +188,7 @@ namespace ScriptCanvasEditorTools
}
}
AZ::Entity* TranslationGeneration::TranslateAZEvent(const AZ::BehaviorMethod& method)
AZ::Entity* TranslationGeneration::GetAZEventNode(const AZ::BehaviorMethod& method)
{
// Make sure the method returns an AZ::Event by reference or pointer
if (AZ::MethodReturnsAzEventByReferenceOrPointer(method))
@@ -248,6 +248,11 @@ namespace ScriptCanvasEditorTools
{
const AZ::BehaviorMethod* behaviorMethod = methodPair.second;
if (TranslateSingleAZEvent(behaviorMethod))
{
continue;
}
Method methodEntry;
AZStd::string cleanName = GraphCanvas::TranslationKey::Sanitize(methodPair.first);
@@ -363,20 +368,79 @@ namespace ScriptCanvasEditorTools
return true;
}
//! Generate the translation data for a specific AZ::Event
bool TranslationGeneration::TranslateSingleAZEvent(const AZ::BehaviorMethod* method)
{
AZ::Entity* node = GetAZEventNode(*method);
if (!node)
{
return false;
}
TranslationFormat translationRoot;
ScriptCanvas::Nodes::Core::AzEventHandler* nodeComponent = node->FindComponent<ScriptCanvas::Nodes::Core::AzEventHandler>();
nodeComponent->Init();
nodeComponent->Configure();
const ScriptCanvas::Nodes::Core::AzEventEntry& azEventEntry{ nodeComponent->GetEventEntry() };
Entry entry;
entry.m_key = azEventEntry.m_eventName;
entry.m_context = "AZEventHandler";
entry.m_details.m_name = azEventEntry.m_eventName;
SplitCamelCase(entry.m_details.m_name);
for (const ScriptCanvas::Slot& slot : nodeComponent->GetSlots())
{
Slot slotEntry;
if (slot.IsVisible())
{
slotEntry.m_key = slot.GetName();
if (slot.GetId() == azEventEntry.m_azEventInputSlotId)
{
slotEntry.m_details.m_name = azEventEntry.m_eventName;
}
else
{
slotEntry.m_details.m_name = slot.GetName();
}
entry.m_slots.push_back(slotEntry);
}
}
translationRoot.m_entries.push_back(entry);
// delete the node, don't need to keep it beyond this point
delete node;
AZStd::string filename = GraphCanvas::TranslationKey::Sanitize(entry.m_key);
AZStd::string targetFile = AZStd::string::format("AZEvents/%s", filename.c_str());
SaveJSONData(targetFile, translationRoot);
translationRoot.m_entries.clear();
return true;
}
void TranslationGeneration::TranslateAZEvents()
{
GraphCanvas::TranslationKey translationKey;
AZStd::vector<AZ::Entity*> nodes;
AZStd::vector<AZ::BehaviorMethod*> methods;
// Methods
for (const auto& behaviorMethod : m_behaviorContext->m_methods)
{
const auto& method = *behaviorMethod.second;
AZ::Entity* node = TranslateAZEvent(method);
if (node)
{
nodes.push_back(node);
}
const auto method = behaviorMethod.second;
methods.push_back(method);
}
// Methods in classes
@@ -384,66 +448,14 @@ namespace ScriptCanvasEditorTools
{
for (auto behaviorMethod : behaviorClass.second->m_methods)
{
const auto& method = *behaviorMethod.second;
AZ::Entity* node = TranslateAZEvent(method);
if (node)
{
nodes.push_back(node);
}
const auto method = behaviorMethod.second;
methods.push_back(method);
}
}
TranslationFormat translationRoot;
for (auto& node : nodes)
for (auto& method : methods)
{
ScriptCanvas::Nodes::Core::AzEventHandler* nodeComponent = node->FindComponent<ScriptCanvas::Nodes::Core::AzEventHandler>();
nodeComponent->Init();
nodeComponent->Configure();
const ScriptCanvas::Nodes::Core::AzEventEntry& azEventEntry{ nodeComponent->GetEventEntry() };
Entry entry;
entry.m_key = azEventEntry.m_eventName;
entry.m_context = "AZEventHandler";
entry.m_details.m_name = azEventEntry.m_eventName;
SplitCamelCase(entry.m_details.m_name);
for (const ScriptCanvas::Slot& slot : nodeComponent->GetSlots())
{
Slot slotEntry;
if (slot.IsVisible())
{
slotEntry.m_key = slot.GetName();
if (slot.GetId() == azEventEntry.m_azEventInputSlotId)
{
slotEntry.m_details.m_name = azEventEntry.m_eventName;
}
else
{
slotEntry.m_details.m_name = slot.GetName();
}
entry.m_slots.push_back(slotEntry);
}
}
translationRoot.m_entries.push_back(entry);
// delete the node, don't need to keep it beyond this point
delete node;
AZStd::string filename = GraphCanvas::TranslationKey::Sanitize(entry.m_key);
AZStd::string targetFile = AZStd::string::format("AZEvents/%s", filename.c_str());
SaveJSONData(targetFile, translationRoot);
translationRoot.m_entries.clear();
TranslateSingleAZEvent(method);
}
}
@@ -484,6 +496,7 @@ namespace ScriptCanvasEditorTools
{
TranslateNode(node);
}
}
void TranslationGeneration::TranslateNode(const AZ::TypeId& nodeTypeId)
@@ -558,8 +571,11 @@ namespace ScriptCanvasEditorTools
nodeComponent->Init();
nodeComponent->Configure();
int inputIndex = 0;
int outputIndex = 0;
int exeInputIndex = 0;
int exeOutputIndex = 0;
int dataInputIndex = 0;
int dataOutputIndex = 0;
const auto& allSlots = nodeComponent->GetAllSlots();
for (const auto& slot : allSlots)
@@ -570,16 +586,16 @@ namespace ScriptCanvasEditorTools
{
if (slot->GetDescriptor().IsInput())
{
slotEntry.m_key = AZStd::string::format("Input_%s", slot->GetName().c_str());
inputIndex++;
slotEntry.m_key = AZStd::string::format("Input_%s_%d", slot->GetName().c_str(), exeInputIndex);
exeInputIndex++;
slotEntry.m_details.m_name = slot->GetName();
slotEntry.m_details.m_tooltip = slot->GetToolTip();
}
else if (slot->GetDescriptor().IsOutput())
{
slotEntry.m_key = AZStd::string::format("Output_%s", slot->GetName().c_str());
outputIndex++;
slotEntry.m_key = AZStd::string::format("Output_%s_%d", slot->GetName().c_str(), exeOutputIndex);
exeOutputIndex++;
slotEntry.m_details.m_name = slot->GetName();
slotEntry.m_details.m_tooltip = slot->GetToolTip();
@@ -618,8 +634,8 @@ namespace ScriptCanvasEditorTools
if (slot->GetDescriptor().IsInput())
{
slotEntry.m_key = AZStd::string::format("DataInput_%s", slot->GetName().c_str());
inputIndex++;
slotEntry.m_key = AZStd::string::format("DataInput_%s_%d", slot->GetName().c_str(), dataInputIndex);
dataInputIndex++;
AZStd::string argumentKey = slotTypeKey;
AZStd::string argumentName = slot->GetName();
@@ -632,8 +648,8 @@ namespace ScriptCanvasEditorTools
}
else if (slot->GetDescriptor().IsOutput())
{
slotEntry.m_key = AZStd::string::format("DataOutput_%s", slot->GetName().c_str());
outputIndex++;
slotEntry.m_key = AZStd::string::format("DataOutput_%s_%d", slot->GetName().c_str(), dataOutputIndex);
dataOutputIndex++;
AZStd::string resultKey = slotTypeKey;
AZStd::string resultName = slot->GetName();
@@ -943,6 +959,7 @@ namespace ScriptCanvasEditorTools
AZStd::string methodName = "Get";
methodName.append(cleanName);
method.m_key = methodName;
method.m_context = "Getter";
method.m_details.m_name = methodName;
method.m_details.m_tooltip = behaviorProperty->m_getter->m_debugDescription ? behaviorProperty->m_getter->m_debugDescription : "";
@@ -953,7 +970,7 @@ namespace ScriptCanvasEditorTools
// We know this is a getter, so there will only be one parameter, we will use the method name as a best
// guess for the argument name
SplitCamelCase(cleanName);
method.m_arguments[1].m_details.m_name = cleanName;
method.m_results[0].m_details.m_name = cleanName;
entry->m_methods.push_back(method);
@@ -970,6 +987,7 @@ namespace ScriptCanvasEditorTools
methodName.append(cleanName);
method.m_key = methodName;
method.m_context = "Setter";
method.m_details.m_name = methodName;
method.m_details.m_tooltip = behaviorProperty->m_setter->m_debugDescription ? behaviorProperty->m_getter->m_debugDescription : "";
@@ -1345,7 +1363,7 @@ namespace ScriptCanvasEditorTools
scratchBuffer.Clear();
AzQtComponents::ShowFileOnDesktop(endPath.c_str());
// AzQtComponents::ShowFileOnDesktop(endPath.c_str());
}