Skip to content

Commit

Permalink
Add parameter documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Kamieniecki <artur.kamieniecki@robotec.ai>
  • Loading branch information
arturkamieniecki committed Mar 8, 2024
1 parent c68ade6 commit 3a77baf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,18 @@ namespace EditorPythonBindings
AZStd::string BusDefinition(const AZStd::string busName, const AZ::BehaviorEBus* behaviorEBus);

//! Creates a string with class or global method definition and documentation.
//! @param defineTooltip if true, the tooltip will be included in the definition
AZStd::string MethodDefinition(
const AZStd::string methodName,
const AZ::BehaviorMethod& behaviorMethod,
const AZ::BehaviorClass* behaviorClass = nullptr,
bool defineTooltip = false);
bool defineTooltip = false,
bool defineDebugDescription = false);

//! Creates a string with class definition and documentation.
//! @param defineProperties if true, the properties will be included in the definition
//! @param defineMethods if true, the methods will be included in the definition
//! @param defineTooltip if true, the tooltip will be included in the definition
AZStd::string ClassDefinition(
const AZ::BehaviorClass* behaviorClass,
const AZStd::string className,
Expand Down
35 changes: 33 additions & 2 deletions Gems/EditorPythonBindings/Code/Source/PythonUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,10 @@ namespace EditorPythonBindings

// record the event names the behavior can send, their parameters and return type
AZStd::string comment = behaviorEBus->m_toolTip;
if (comment.empty())
{
comment = Internal::ReadStringAttribute(behaviorEBus->m_attributes, AZ::Script::Attributes::ToolTip);
}

if (!behaviorEBus->m_events.empty())
{
Expand Down Expand Up @@ -1104,7 +1108,8 @@ namespace EditorPythonBindings
const AZStd::string methodName,
const AZ::BehaviorMethod& behaviorMethod,
const AZ::BehaviorClass* behaviorClass,
bool defineTooltip)
bool defineTooltip,
bool defineDebugDescription)
{
AZStd::string buffer;
AZStd::vector<AZStd::string> pythonArgs;
Expand Down Expand Up @@ -1160,14 +1165,30 @@ namespace EditorPythonBindings
AzFramework::StringFunc::Join(buffer, pythonArgs.begin(), pythonArgs.end(), ",");
AzFramework::StringFunc::Append(buffer, ") -> None:\n");

AZStd::string methodTooltipAndDebugDescription = "";

if (defineDebugDescription && behaviorMethod.m_debugDescription != nullptr)
{
AZStd::string debugDescription(behaviorMethod.m_debugDescription);
if (!debugDescription.empty())
{
methodTooltipAndDebugDescription += debugDescription;
methodTooltipAndDebugDescription += "\n";
}
}
if (defineTooltip)
{
AZStd::string methodTooltip = Internal::ReadStringAttribute(behaviorMethod.m_attributes, AZ::Script::Attributes::ToolTip);
if (!methodTooltip.empty())
{
Internal::AddCommentBlock(indentLevel + 1, methodTooltip, buffer);
methodTooltipAndDebugDescription += methodTooltip;
methodTooltipAndDebugDescription += "\n";
}
}
if (!methodTooltipAndDebugDescription.empty())
{
Internal::AddCommentBlock(indentLevel + 1, methodTooltipAndDebugDescription, buffer);
}

Internal::Indent(indentLevel + 1, buffer);
AzFramework::StringFunc::Append(buffer, "pass\n\n");
Expand Down Expand Up @@ -1205,6 +1226,16 @@ namespace EditorPythonBindings
{
body = "";
}
if (defineTooltip)
{
AZStd::string classTooltip =
Internal::ReadStringAttribute(behaviorClass->m_attributes, AZ::Script::Attributes::ToolTip);
if (!classTooltip.empty())
{
Internal::AddCommentBlock(1, classTooltip, body);
}
}

Internal::Indent(1, body);
AzFramework::StringFunc::Append(body, "pass\n\n");
AzFramework::StringFunc::Append(buffer, body.c_str());
Expand Down

0 comments on commit 3a77baf

Please sign in to comment.