From 33e61ad35ba191fd8490e02fe151476256e0bb54 Mon Sep 17 00:00:00 2001 From: mbalfour Date: Wed, 14 Apr 2021 16:03:27 -0500 Subject: [PATCH 1/3] Added SetEntityName and exposed Get/SetEntityName to the behavior context for use from scripts. (cherry picked from commit 4f2e0b74727cfe99c74ed588769a540f24d7aa46) --- .../AzCore/Component/ComponentApplication.cpp | 24 +++++++++++++++++++ .../AzCore/Component/ComponentApplication.h | 1 + .../Component/ComponentApplicationBus.h | 8 ++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp index a3af2648cf..a3986f72dd 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp @@ -341,6 +341,16 @@ namespace AZ ; } } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->EBus("ComponentApplicationBus") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Category, "Components") + + ->Event("GetEntityName", &ComponentApplicationBus::Events::GetEntityName) + ->Event("SetEntityName", &ComponentApplicationBus::Events::SetEntityName); + } } //========================================================================= @@ -1050,6 +1060,20 @@ namespace AZ return AZStd::string(); } + //========================================================================= + // SetEntityName + //========================================================================= + bool ComponentApplication::SetEntityName(const EntityId& id, const AZStd::string& name) + { + Entity* entity = FindEntity(id); + if (entity) + { + entity->SetName(name); + return true; + } + return false; + } + //========================================================================= // EnumerateEntities //========================================================================= diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h index ef5c813573..a66409eaf3 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h @@ -209,6 +209,7 @@ namespace AZ bool DeleteEntity(const EntityId& id) override; Entity* FindEntity(const EntityId& id) override; AZStd::string GetEntityName(const EntityId& id) override; + bool SetEntityName(const EntityId& id, const AZStd::string& name) override; void EnumerateEntities(const ComponentApplicationRequests::EntityCallback& callback) override; ComponentApplication* GetApplication() override { return this; } /// Returns the serialize context that has been registered with the app, if there is one. diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h index d0f161aa39..a3602c303e 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h @@ -130,7 +130,13 @@ namespace AZ //! @param entity A reference to the entity whose name you are seeking. //! @return The name of the entity with the specified entity ID. //! If no entity is found for the specified ID, it returns an empty string. - virtual AZStd::string GetEntityName(const EntityId& id) { (void)id; return AZStd::string(); }; + virtual AZStd::string GetEntityName(const EntityId& id) { (void)id; return AZStd::string(); } + + //! Sets the name of the entity that has the specified entity ID. + //! Entity names are not enforced to be unique. + //! @param entityId A reference to the entity whose name you want to change. + //! @return True if the name was changed successfully, false if it wasn't. + virtual bool SetEntityName([[maybe_unused]] const EntityId& id, [[maybe_unused]] const AZStd::string& name) { return false; } //! The type that AZ::ComponentApplicationRequests::EnumerateEntities uses to //! pass entity callbacks to the application for enumeration. From e8459898a7f887008fe2375673e3cddb39f1d40c Mon Sep 17 00:00:00 2001 From: mbalfour Date: Wed, 14 Apr 2021 16:04:44 -0500 Subject: [PATCH 2/3] Exposed Quaternion::CreateFromEulerAnglesDegrees and Transform::Transform(Vector3, Quaternion, Vector3) to the behavior context to improve usability of these classes from scripts. (cherry picked from commit 8156beb21181f9ff20972c8ea8be5e3dc61f1700) --- Code/Framework/AzCore/AzCore/Math/Quaternion.cpp | 3 ++- Code/Framework/AzCore/AzCore/Math/Transform.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp b/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp index ca09f8b453..143fe59ca7 100644 --- a/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp +++ b/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp @@ -258,7 +258,8 @@ namespace AZ Method("CreateFromMatrix3x3", &Quaternion::CreateFromMatrix3x3)-> Method("CreateFromMatrix4x4", &Quaternion::CreateFromMatrix4x4)-> Method("CreateFromAxisAngle", &Quaternion::CreateFromAxisAngle)-> - Method("CreateShortestArc", &Quaternion::CreateShortestArc) + Method("CreateShortestArc", &Quaternion::CreateShortestArc)-> + Method("CreateFromEulerAnglesDegrees", &Quaternion::CreateFromEulerAnglesDegrees) ; } } diff --git a/Code/Framework/AzCore/AzCore/Math/Transform.cpp b/Code/Framework/AzCore/AzCore/Math/Transform.cpp index 77d8658d0f..bb3f764492 100644 --- a/Code/Framework/AzCore/AzCore/Math/Transform.cpp +++ b/Code/Framework/AzCore/AzCore/Math/Transform.cpp @@ -250,6 +250,7 @@ namespace AZ Attribute(Script::Attributes::ExcludeFrom, Script::Attributes::ExcludeFlags::All)-> Attribute(Script::Attributes::Storage, Script::Attributes::StorageType::Value)-> Attribute(Script::Attributes::GenericConstructorOverride, &Internal::TransformDefaultConstructor)-> + Constructor()-> Method("GetBasis", &Transform::GetBasis)-> Method("GetBasisX", &Transform::GetBasisX)-> Method("GetBasisY", &Transform::GetBasisY)-> From d9fe89ba56a1c7d344538951909f086386ba5947 Mon Sep 17 00:00:00 2001 From: mbalfour Date: Tue, 20 Apr 2021 13:37:10 -0500 Subject: [PATCH 3/3] Addressed feedback - made string& into a string_view. --- Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp | 2 +- Code/Framework/AzCore/AzCore/Component/ComponentApplication.h | 2 +- .../Framework/AzCore/AzCore/Component/ComponentApplicationBus.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp index a3986f72dd..c55f565615 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp @@ -1063,7 +1063,7 @@ namespace AZ //========================================================================= // SetEntityName //========================================================================= - bool ComponentApplication::SetEntityName(const EntityId& id, const AZStd::string& name) + bool ComponentApplication::SetEntityName(const EntityId& id, const AZStd::string_view name) { Entity* entity = FindEntity(id); if (entity) diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h index a66409eaf3..3ebcf39d95 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h @@ -209,7 +209,7 @@ namespace AZ bool DeleteEntity(const EntityId& id) override; Entity* FindEntity(const EntityId& id) override; AZStd::string GetEntityName(const EntityId& id) override; - bool SetEntityName(const EntityId& id, const AZStd::string& name) override; + bool SetEntityName(const EntityId& id, const AZStd::string_view name) override; void EnumerateEntities(const ComponentApplicationRequests::EntityCallback& callback) override; ComponentApplication* GetApplication() override { return this; } /// Returns the serialize context that has been registered with the app, if there is one. diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h index a3602c303e..3582e6ebb8 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplicationBus.h @@ -136,7 +136,7 @@ namespace AZ //! Entity names are not enforced to be unique. //! @param entityId A reference to the entity whose name you want to change. //! @return True if the name was changed successfully, false if it wasn't. - virtual bool SetEntityName([[maybe_unused]] const EntityId& id, [[maybe_unused]] const AZStd::string& name) { return false; } + virtual bool SetEntityName([[maybe_unused]] const EntityId& id, [[maybe_unused]] const AZStd::string_view name) { return false; } //! The type that AZ::ComponentApplicationRequests::EnumerateEntities uses to //! pass entity callbacks to the application for enumeration.