diff --git a/Templates/DefaultGem/Template/Code/Include/${Name}/${Name}Bus.h b/Templates/DefaultGem/Template/Code/Include/${Name}/${Name}Bus.h index 0e8ab29cc4..32f34e309e 100644 --- a/Templates/DefaultGem/Template/Code/Include/${Name}/${Name}Bus.h +++ b/Templates/DefaultGem/Template/Code/Include/${Name}/${Name}Bus.h @@ -15,22 +15,30 @@ #pragma once #include +#include -namespace ${Name} +namespace ${SanitizedCppName} { - class ${Name}Requests + class ${SanitizedCppName}Requests + { + public: + AZ_RTTI(${SanitizedCppName}Requests, "${Random_Uuid}"); + virtual ~${SanitizedCppName}Requests() = default; + // Put your public methods here + }; + + class ${SanitizedCppName}BusTraits : public AZ::EBusTraits { public: ////////////////////////////////////////////////////////////////////////// // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; + static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; + static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; ////////////////////////////////////////////////////////////////////////// - - // Put your public methods here }; - using ${Name}RequestBus = AZ::EBus<${Name}Requests>; + using ${SanitizedCppName}RequestBus = AZ::EBus<${SanitizedCppName}Requests, ${SanitizedCppName}BusTraits>; + using ${SanitizedCppName}Interface = AZ::Interface<${SanitizedCppName}Requests>; -} // namespace ${Name} +} // namespace ${SanitizedCppName} diff --git a/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.cpp b/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.cpp index 5884489904..fedc37da6b 100644 --- a/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.cpp +++ b/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.cpp @@ -15,24 +15,40 @@ #include #include <${Name}EditorSystemComponent.h> -namespace ${Name} +namespace ${SanitizedCppName} { - void ${Name}EditorSystemComponent::Reflect(AZ::ReflectContext* context) + void ${SanitizedCppName}EditorSystemComponent::Reflect(AZ::ReflectContext* context) { if (auto serializeContext = azrtti_cast(context)) { - serializeContext->Class<${Name}EditorSystemComponent, AZ::Component>()->Version(1); + serializeContext->Class<${SanitizedCppName}EditorSystemComponent, AZ::Component>()->Version(1); } } - void ${Name}EditorSystemComponent::Activate() + ${SanitizedCppName}EditorSystemComponent::${SanitizedCppName}EditorSystemComponent() + { + if (${SanitizedCppName}Interface::Get() == nullptr) + { + ${SanitizedCppName}Interface::Register(this); + } + } + + ${SanitizedCppName}EditorSystemComponent::~${SanitizedCppName}EditorSystemComponent() + { + if (${SanitizedCppName}Interface::Get() == this) + { + ${SanitizedCppName}Interface::Unregister(this); + } + } + + void ${SanitizedCppName}EditorSystemComponent::Activate() { AzToolsFramework::EditorEvents::Bus::Handler::BusConnect(); } - void ${Name}EditorSystemComponent::Deactivate() + void ${SanitizedCppName}EditorSystemComponent::Deactivate() { AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect(); } -} // namespace ${Name} +} // namespace ${SanitizedCppName} diff --git a/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.h b/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.h index 1f973651ee..ef7b0a2f2e 100644 --- a/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.h +++ b/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.h @@ -18,32 +18,33 @@ #include -namespace ${Name} +namespace ${SanitizedCppName} { - /// System component for ${Name} editor - class ${Name}EditorSystemComponent + /// System component for ${SanitizedCppName} editor + class ${SanitizedCppName}EditorSystemComponent : public AZ::Component , private AzToolsFramework::EditorEvents::Bus::Handler { public: - AZ_COMPONENT(${Name}EditorSystemComponent, "${EditorSysCompClassId}"); + AZ_COMPONENT(${SanitizedCppName}EditorSystemComponent, "${EditorSysCompClassId}"); static void Reflect(AZ::ReflectContext* context); - ${Name}EditorSystemComponent() = default; + ${SanitizedCppName}EditorSystemComponent(); + ~${SanitizedCppName}EditorSystemComponent(); private: static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { - provided.push_back(AZ_CRC("${Name}EditorService")); + provided.push_back(AZ_CRC("${SanitizedCppName}EditorService")); } static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { - required.push_back(AZ_CRC("${Name}Service")); + required.push_back(AZ_CRC("${SanitizedCppName}Service")); } // AZ::Component void Activate() override; void Deactivate() override; }; -} // namespace ${Name} +} // namespace ${SanitizedCppName} diff --git a/Templates/DefaultGem/Template/Code/Source/${Name}Module.cpp b/Templates/DefaultGem/Template/Code/Source/${Name}Module.cpp index 3c6be88158..ca4a724f49 100644 --- a/Templates/DefaultGem/Template/Code/Source/${Name}Module.cpp +++ b/Templates/DefaultGem/Template/Code/Source/${Name}Module.cpp @@ -17,21 +17,21 @@ #include <${Name}SystemComponent.h> -namespace ${Name} +namespace ${SanitizedCppName} { - class ${Name}Module + class ${SanitizedCppName}Module : public AZ::Module { public: - AZ_RTTI(${Name}Module, "${ModuleClassId}", AZ::Module); - AZ_CLASS_ALLOCATOR(${Name}Module, AZ::SystemAllocator, 0); + AZ_RTTI(${SanitizedCppName}Module, "${ModuleClassId}", AZ::Module); + AZ_CLASS_ALLOCATOR(${SanitizedCppName}Module, AZ::SystemAllocator, 0); - ${Name}Module() + ${SanitizedCppName}Module() : AZ::Module() { // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here. m_descriptors.insert(m_descriptors.end(), { - ${Name}SystemComponent::CreateDescriptor(), + ${SanitizedCppName}SystemComponent::CreateDescriptor(), }); } @@ -41,10 +41,10 @@ namespace ${Name} AZ::ComponentTypeList GetRequiredSystemComponents() const override { return AZ::ComponentTypeList { - azrtti_typeid<${Name}SystemComponent>(), + azrtti_typeid<${SanitizedCppName}SystemComponent>(), }; } }; -}// namespace ${Name} +}// namespace ${SanitizedCppName} -AZ_DECLARE_MODULE_CLASS(Gem_${Name}, ${Name}::${Name}Module) +AZ_DECLARE_MODULE_CLASS(Gem_${SanitizedCppName}, ${SanitizedCppName}::${SanitizedCppName}Module) diff --git a/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.cpp b/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.cpp index 7f91197e4a..8f7eabf74e 100644 --- a/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.cpp +++ b/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.cpp @@ -18,19 +18,19 @@ #include #include -namespace ${Name} +namespace ${SanitizedCppName} { - void ${Name}SystemComponent::Reflect(AZ::ReflectContext* context) + void ${SanitizedCppName}SystemComponent::Reflect(AZ::ReflectContext* context) { if (AZ::SerializeContext* serialize = azrtti_cast(context)) { - serialize->Class<${Name}SystemComponent, AZ::Component>() + serialize->Class<${SanitizedCppName}SystemComponent, AZ::Component>() ->Version(0) ; if (AZ::EditContext* ec = serialize->GetEditContext()) { - ec->Class<${Name}SystemComponent>("${Name}", "[Description of functionality provided by this System Component]") + ec->Class<${SanitizedCppName}SystemComponent>("${SanitizedCppName}", "[Description of functionality provided by this System Component]") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System")) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) @@ -39,45 +39,61 @@ namespace ${Name} } } - void ${Name}SystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) + void ${SanitizedCppName}SystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { - provided.push_back(AZ_CRC("${Name}Service")); + provided.push_back(AZ_CRC("${SanitizedCppName}Service")); } - void ${Name}SystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) + void ${SanitizedCppName}SystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { - incompatible.push_back(AZ_CRC("${Name}Service")); + incompatible.push_back(AZ_CRC("${SanitizedCppName}Service")); } - void ${Name}SystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) + void ${SanitizedCppName}SystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { AZ_UNUSED(required); } - void ${Name}SystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) + void ${SanitizedCppName}SystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { AZ_UNUSED(dependent); } - void ${Name}SystemComponent::Init() + ${SanitizedCppName}SystemComponent::${SanitizedCppName}SystemComponent() + { + if (${SanitizedCppName}Interface::Get() == nullptr) + { + ${SanitizedCppName}Interface::Register(this); + } + } + + ${SanitizedCppName}SystemComponent::~${SanitizedCppName}SystemComponent() + { + if (${SanitizedCppName}Interface::Get() == this) + { + ${SanitizedCppName}Interface::Unregister(this); + } + } + + void ${SanitizedCppName}SystemComponent::Init() { } - void ${Name}SystemComponent::Activate() + void ${SanitizedCppName}SystemComponent::Activate() { - ${Name}RequestBus::Handler::BusConnect(); + ${SanitizedCppName}RequestBus::Handler::BusConnect(); AZ::TickBus::Handler::BusConnect(); } - void ${Name}SystemComponent::Deactivate() + void ${SanitizedCppName}SystemComponent::Deactivate() { AZ::TickBus::Handler::BusDisconnect(); - ${Name}RequestBus::Handler::BusDisconnect(); + ${SanitizedCppName}RequestBus::Handler::BusDisconnect(); } - void ${Name}SystemComponent::OnTick(float /*deltaTime*/, AZ::ScriptTimePoint /*time*/) + void ${SanitizedCppName}SystemComponent::OnTick(float /*deltaTime*/, AZ::ScriptTimePoint /*time*/) { } -} // namespace ${Name} +} // namespace ${SanitizedCppName} diff --git a/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.h b/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.h index 5071e7b9c7..8e91650c65 100644 --- a/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.h +++ b/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.h @@ -18,15 +18,15 @@ #include #include <${Name}/${Name}Bus.h> -namespace ${Name} +namespace ${SanitizedCppName} { - class ${Name}SystemComponent + class ${SanitizedCppName}SystemComponent : public AZ::Component - , protected ${Name}RequestBus::Handler + , protected ${SanitizedCppName}RequestBus::Handler , public AZ::TickBus::Handler { public: - AZ_COMPONENT(${Name}SystemComponent, "${SysCompClassId}"); + AZ_COMPONENT(${SanitizedCppName}SystemComponent, "${SysCompClassId}"); static void Reflect(AZ::ReflectContext* context); @@ -35,9 +35,12 @@ namespace ${Name} static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); + ${SanitizedCppName}SystemComponent(); + ~${SanitizedCppName}SystemComponent(); + protected: //////////////////////////////////////////////////////////////////////// - // ${Name}RequestBus interface implementation + // ${SanitizedCppName}RequestBus interface implementation //////////////////////////////////////////////////////////////////////// @@ -54,4 +57,4 @@ namespace ${Name} //////////////////////////////////////////////////////////////////////// }; -} // namespace ${Name} +} // namespace ${SanitizedCppName} diff --git a/Templates/DefaultGem/Template/Code/Tests/${Name}EditorTest.cpp b/Templates/DefaultGem/Template/Code/Tests/${Name}EditorTest.cpp index 7fd3fa7cfa..9b36a3aadb 100644 --- a/Templates/DefaultGem/Template/Code/Tests/${Name}EditorTest.cpp +++ b/Templates/DefaultGem/Template/Code/Tests/${Name}EditorTest.cpp @@ -14,7 +14,7 @@ #include -class ${Name}EditorTest +class ${SanitizedCppName}EditorTest : public ::testing::Test { protected: @@ -29,7 +29,7 @@ protected: } }; -TEST_F(${Name}EditorTest, SanityTest) +TEST_F(${SanitizedCppName}EditorTest, SanityTest) { ASSERT_TRUE(true); } diff --git a/Templates/DefaultGem/Template/Code/Tests/${Name}Test.cpp b/Templates/DefaultGem/Template/Code/Tests/${Name}Test.cpp index 8021ca920e..bee38fa9d7 100644 --- a/Templates/DefaultGem/Template/Code/Tests/${Name}Test.cpp +++ b/Templates/DefaultGem/Template/Code/Tests/${Name}Test.cpp @@ -14,7 +14,7 @@ #include -class ${Name}Test +class ${SanitizedCppName}Test : public ::testing::Test { protected: @@ -29,7 +29,7 @@ protected: } }; -TEST_F(${Name}Test, SanityTest) +TEST_F(${SanitizedCppName}Test, SanityTest) { ASSERT_TRUE(true); } diff --git a/Templates/DefaultProject/Template/Code/Include/${Name}/${Name}Bus.h b/Templates/DefaultProject/Template/Code/Include/${Name}/${Name}Bus.h index faa0e8acf6..05e434ec03 100644 --- a/Templates/DefaultProject/Template/Code/Include/${Name}/${Name}Bus.h +++ b/Templates/DefaultProject/Template/Code/Include/${Name}/${Name}Bus.h @@ -15,20 +15,30 @@ #pragma once #include +#include -namespace ${Name} +namespace ${SanitizedCppName} { - class ${Name}Requests + class ${SanitizedCppName}Requests + { + public: + AZ_RTTI(${SanitizedCppName}Requests, "${Random_Uuid}"); + virtual ~${SanitizedCppName}Requests() = default; + // Put your public methods here + }; + + class ${SanitizedCppName}BusTraits : public AZ::EBusTraits { public: ////////////////////////////////////////////////////////////////////////// // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; + static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; + static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; ////////////////////////////////////////////////////////////////////////// - - // Put your public methods here }; - using ${Name}RequestBus = AZ::EBus<${Name}Requests>; -} // namespace ${Name} + + using ${SanitizedCppName}RequestBus = AZ::EBus<${SanitizedCppName}Requests, ${SanitizedCppName}BusTraits>; + using ${SanitizedCppName}Interface = AZ::Interface<${SanitizedCppName}Requests>; + +} // namespace ${SanitizedCppName} diff --git a/Templates/DefaultProject/Template/Code/Source/${Name}Module.cpp b/Templates/DefaultProject/Template/Code/Source/${Name}Module.cpp index 4f11828366..57b473b317 100644 --- a/Templates/DefaultProject/Template/Code/Source/${Name}Module.cpp +++ b/Templates/DefaultProject/Template/Code/Source/${Name}Module.cpp @@ -17,21 +17,21 @@ #include "${Name}SystemComponent.h" -namespace ${Name} +namespace ${SanitizedCppName} { - class ${Name}Module + class ${SanitizedCppName}Module : public AZ::Module { public: - AZ_RTTI(${Name}Module, "${ModuleClassId}", AZ::Module); - AZ_CLASS_ALLOCATOR(${Name}Module, AZ::SystemAllocator, 0); + AZ_RTTI(${SanitizedCppName}Module, "${ModuleClassId}", AZ::Module); + AZ_CLASS_ALLOCATOR(${SanitizedCppName}Module, AZ::SystemAllocator, 0); - ${Name}Module() + ${SanitizedCppName}Module() : AZ::Module() { // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here. m_descriptors.insert(m_descriptors.end(), { - ${Name}SystemComponent::CreateDescriptor(), + ${SanitizedCppName}SystemComponent::CreateDescriptor(), }); } @@ -41,10 +41,10 @@ namespace ${Name} AZ::ComponentTypeList GetRequiredSystemComponents() const override { return AZ::ComponentTypeList{ - azrtti_typeid<${Name}SystemComponent>(), + azrtti_typeid<${SanitizedCppName}SystemComponent>(), }; } }; -}// namespace ${Name} +}// namespace ${SanitizedCppName} -AZ_DECLARE_MODULE_CLASS(Gem_${Name}, ${Name}::${Name}Module) +AZ_DECLARE_MODULE_CLASS(Gem_${SanitizedCppName}, ${SanitizedCppName}::${SanitizedCppName}Module) diff --git a/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.cpp b/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.cpp index 1e505f743c..ed0a47d6db 100644 --- a/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.cpp +++ b/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.cpp @@ -18,19 +18,19 @@ #include "${Name}SystemComponent.h" -namespace ${Name} +namespace ${SanitizedCppName} { - void ${Name}SystemComponent::Reflect(AZ::ReflectContext* context) + void ${SanitizedCppName}SystemComponent::Reflect(AZ::ReflectContext* context) { if (AZ::SerializeContext* serialize = azrtti_cast(context)) { - serialize->Class<${Name}SystemComponent, AZ::Component>() + serialize->Class<${SanitizedCppName}SystemComponent, AZ::Component>() ->Version(0) ; if (AZ::EditContext* ec = serialize->GetEditContext()) { - ec->Class<${Name}SystemComponent>("${Name}", "[Description of functionality provided by this System Component]") + ec->Class<${SanitizedCppName}SystemComponent>("${SanitizedCppName}", "[Description of functionality provided by this System Component]") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System")) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) @@ -39,37 +39,53 @@ namespace ${Name} } } - void ${Name}SystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) + void ${SanitizedCppName}SystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { - provided.push_back(AZ_CRC("${Name}Service")); + provided.push_back(AZ_CRC("${SanitizedCppName}Service")); } - void ${Name}SystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) + void ${SanitizedCppName}SystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { - incompatible.push_back(AZ_CRC("${Name}Service")); + incompatible.push_back(AZ_CRC("${SanitizedCppName}Service")); } - void ${Name}SystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) + void ${SanitizedCppName}SystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { AZ_UNUSED(required); } - void ${Name}SystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) + void ${SanitizedCppName}SystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { AZ_UNUSED(dependent); } + + ${SanitizedCppName}SystemComponent::${SanitizedCppName}SystemComponent() + { + if (${SanitizedCppName}Interface::Get() == nullptr) + { + ${SanitizedCppName}Interface::Register(this); + } + } + + ${SanitizedCppName}SystemComponent::~${SanitizedCppName}SystemComponent() + { + if (${SanitizedCppName}Interface::Get() == this) + { + ${SanitizedCppName}Interface::Unregister(this); + } + } - void ${Name}SystemComponent::Init() + void ${SanitizedCppName}SystemComponent::Init() { } - void ${Name}SystemComponent::Activate() + void ${SanitizedCppName}SystemComponent::Activate() { - ${Name}RequestBus::Handler::BusConnect(); + ${SanitizedCppName}RequestBus::Handler::BusConnect(); } - void ${Name}SystemComponent::Deactivate() + void ${SanitizedCppName}SystemComponent::Deactivate() { - ${Name}RequestBus::Handler::BusDisconnect(); + ${SanitizedCppName}RequestBus::Handler::BusDisconnect(); } } diff --git a/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.h b/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.h index 39ccbda549..10a500aba2 100644 --- a/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.h +++ b/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.h @@ -18,14 +18,14 @@ #include <${Name}/${Name}Bus.h> -namespace ${Name} +namespace ${SanitizedCppName} { - class ${Name}SystemComponent + class ${SanitizedCppName}SystemComponent : public AZ::Component - , protected ${Name}RequestBus::Handler + , protected ${SanitizedCppName}RequestBus::Handler { public: - AZ_COMPONENT(${Name}SystemComponent, "${SysCompClassId}"); + AZ_COMPONENT(${SanitizedCppName}SystemComponent, "${SysCompClassId}"); static void Reflect(AZ::ReflectContext* context); @@ -34,9 +34,12 @@ namespace ${Name} static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); + ${SanitizedCppName}SystemComponent(); + ~${SanitizedCppName}SystemComponent(); + protected: //////////////////////////////////////////////////////////////////////// - // ${Name}RequestBus interface implementation + // ${SanitizedCppName}RequestBus interface implementation //////////////////////////////////////////////////////////////////////// diff --git a/cmake/Platform/Common/Install_common.cmake b/cmake/Platform/Common/Install_common.cmake index a579e3128d..933d64149b 100644 --- a/cmake/Platform/Common/Install_common.cmake +++ b/cmake/Platform/Common/Install_common.cmake @@ -374,7 +374,7 @@ function(ly_setup_cmake_install) string(APPEND builtinpackages "ly_associate_package(PACKAGE_NAME ${package_name} TARGETS ${targets} PACKAGE_HASH ${package_hash})\n") endforeach() - ly_get_absolute_pal_filename(pal_builtin_file ${CMAKE_CURRENT_BINARY_DIR}/cmake/3rdParty/Platform/${PAL_PLATFORM_NAME}/BuiltInPackages_${PAL_PLATFORM_NAME_LOWERCASE}.cmake) + set(pal_builtin_file ${CMAKE_CURRENT_BINARY_DIR}/cmake/3rdParty/Platform/${PAL_PLATFORM_NAME}/BuiltInPackages_${PAL_PLATFORM_NAME_LOWERCASE}.cmake) file(GENERATE OUTPUT ${pal_builtin_file} CONTENT ${builtinpackages} ) diff --git a/scripts/o3de/o3de/engine_template.py b/scripts/o3de/o3de/engine_template.py index 9bb62eff35..06e34cc449 100755 --- a/scripts/o3de/o3de/engine_template.py +++ b/scripts/o3de/o3de/engine_template.py @@ -1232,10 +1232,12 @@ def create_from_template(destination_path: str, with_this = replace.pop(0) replacements.append((replace_this, with_this)) + sanitized_cpp_name = utils.sanitize_identifier_for_cpp(destination_name) # dst name is Name replacements.append(("${Name}", destination_name)) replacements.append(("${NameUpper}", destination_name.upper())) replacements.append(("${NameLower}", destination_name.lower())) + replacements.append(("${SanitizedCppName}", sanitized_cpp_name)) if _instantiate_template(template_json_data, destination_name, @@ -1536,10 +1538,12 @@ def create_project(project_path: str, with_this = replace.pop(0) replacements.append((replace_this, with_this)) + sanitized_cpp_name = utils.sanitize_identifier_for_cpp(project_name) # project name replacements.append(("${Name}", project_name)) replacements.append(("${NameUpper}", project_name.upper())) replacements.append(("${NameLower}", project_name.lower())) + replacements.append(("${SanitizedCppName}", sanitized_cpp_name)) # module id is a uuid with { and - if module_id: @@ -1890,6 +1894,10 @@ def create_gem(gem_path: str, # gem name is now the last component of the gem_path gem_name = os.path.basename(gem_path) + if not utils.validate_identifier(gem_name): + logger.error(f'Gem name must be fewer than 64 characters, contain only alphanumeric, "_" or "-" characters, and start with a letter. {gem_name}') + return 1 + # gem name cannot be the same as a restricted platform name if gem_name in restricted_platforms: logger.error(f'Gem path cannot be a restricted name. {gem_name}') @@ -1927,10 +1935,13 @@ def create_gem(gem_path: str, with_this = replace.pop(0) replacements.append((replace_this, with_this)) + sanitized_cpp_name = utils.sanitize_identifier_for_cpp(gem_name) # gem name replacements.append(("${Name}", gem_name)) replacements.append(("${NameUpper}", gem_name.upper())) replacements.append(("${NameLower}", gem_name.lower())) + replacements.append(("${SanitizedCppName}", sanitized_cpp_name)) + # module id is a uuid with { and - if module_id: diff --git a/scripts/o3de/o3de/manifest.py b/scripts/o3de/o3de/manifest.py index 074e7f5a9e..8255946cfb 100644 --- a/scripts/o3de/o3de/manifest.py +++ b/scripts/o3de/o3de/manifest.py @@ -401,13 +401,6 @@ def get_templates_for_generic_creation(): # temporary until we have a better wa return list(filter(filter_project_and_gem_templates_out, get_all_templates())) -def get_all_restricted() -> list: - engine_restricted = get_engine_restricted() - restricted_data = get_restricted() - restricted_data.extend(engine_restricted) - return restricted_data - - def find_engine_data(json_data: dict, engine_path: str or pathlib.Path = None) -> dict or None: if not engine_path: diff --git a/scripts/o3de/o3de/utils.py b/scripts/o3de/o3de/utils.py index 4330de25b8..11c668a37b 100755 --- a/scripts/o3de/o3de/utils.py +++ b/scripts/o3de/o3de/utils.py @@ -36,6 +36,23 @@ def validate_identifier(identifier: str) -> bool: return True +def sanitize_identifier_for_cpp(identifier: str) -> str: + """ + Convert the provided identifier to a valid C++ identifier + :param identifier: the name which needs to to sanitized + :return: str: sanitized identifier + """ + if not identifier: + return '' + + sanitized_identifier = list(identifier) + for index, character in enumerate(sanitized_identifier): + if not (character.isalnum() or character == '_'): + sanitized_identifier[index] = '_' + + return "".join(sanitized_identifier) + + def validate_uuid4(uuid_string: str) -> bool: """ Determine if the uuid supplied is valid.