|
|
|
@@ -661,20 +661,75 @@ enum class NetworkProperties
|
|
|
|
|
{#
|
|
|
|
|
|
|
|
|
|
#}
|
|
|
|
|
{% macro DefineNetworkPropertyBehaviorReflection(Component, ReplicateFrom, ReplicateTo, ClassType) %}
|
|
|
|
|
{% macro DefineNetworkPropertyBehaviorReflection(Component, ReplicateFrom, ReplicateTo, ClassName) %}
|
|
|
|
|
{% call(Property) AutoComponentMacros.ParseNetworkProperties(Component, ReplicateFrom, ReplicateTo) %}
|
|
|
|
|
{% if (Property.attrib['IsPublic'] | booleanTrue == true) %}
|
|
|
|
|
{% if Property.attrib['Container'] == 'Array' %}
|
|
|
|
|
->Event("Get{{ Property.attrib['Name'] }}", &{{ ClassType }}Bus::Events::Get{{ Property.attrib['Name'] }})
|
|
|
|
|
{% elif Property.attrib['Container'] == 'Vector' %}
|
|
|
|
|
->Event("Get{{ Property.attrib['Name'] }}", &{{ ClassType }}Bus::Events::Get{{ Property.attrib['Name'] }})
|
|
|
|
|
->Event("{{ Property.attrib['Name'] }}GetBack", &{{ ClassType }}Bus::Events::{{ Property.attrib['Name'] }}GetBack)
|
|
|
|
|
->Event("{{ Property.attrib['Name'] }}GetSize", &{{ ClassType }}Bus::Events::{{ Property.attrib['Name'] }}GetSize)
|
|
|
|
|
{% else %}
|
|
|
|
|
->Event("Get{{ Property.attrib['Name'] }}", &{{ ClassType }}Bus::Events::Get{{ Property.attrib['Name'] }})
|
|
|
|
|
{% endif %}
|
|
|
|
|
{% if (Property.attrib['IsPublic'] | booleanTrue == true) and (Property.attrib['GenerateEventBindings'] | booleanTrue == true) -%}
|
|
|
|
|
// {{ UpperFirst(Property.attrib['Name']) }}: Replicate from {{ ReplicateFrom }} to {{ ReplicateTo }}
|
|
|
|
|
->Method("Get{{ UpperFirst(Property.attrib['Name']) }}", [](AZ::EntityId id) -> {{ Property.attrib['Type'] }}
|
|
|
|
|
{
|
|
|
|
|
AZ::Entity* entity = AZ::Interface<AZ::ComponentApplicationRequests>::Get()->FindEntity(id);
|
|
|
|
|
if (!entity)
|
|
|
|
|
{
|
|
|
|
|
AZ_Warning("Network Property", false, "{{ ClassName }} Get{{ UpperFirst(Property.attrib['Name']) }} failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str())
|
|
|
|
|
return {{ Property.attrib['Type'] }}();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{{ ClassName }}* networkComponent = entity->FindComponent<{{ ClassName }}>();
|
|
|
|
|
if (!networkComponent)
|
|
|
|
|
{
|
|
|
|
|
AZ_Warning("Network Property", false, "{{ ClassName }} Get{{ UpperFirst(Property.attrib['Name']) }} failed. Entity '%s' (id: %s) is missing {{ ClassName }}, be sure to add {{ ClassName }} to this entity.", entity->GetName().c_str(), id.ToString().c_str())
|
|
|
|
|
return {{ Property.attrib['Type'] }}();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return networkComponent->Get{{ UpperFirst(Property.attrib['Name']) }}();
|
|
|
|
|
})
|
|
|
|
|
->Method("Set{{ UpperFirst(Property.attrib['Name']) }}", [](AZ::EntityId id, const {{ Property.attrib['Type'] }}& {{ LowerFirst(Property.attrib['Name']) }}) -> void
|
|
|
|
|
{
|
|
|
|
|
AZ::Entity* entity = AZ::Interface<AZ::ComponentApplicationRequests>::Get()->FindEntity(id);
|
|
|
|
|
if (!entity)
|
|
|
|
|
{
|
|
|
|
|
AZ_Warning("Network Property", false, "{{ ClassName }} Set{{ UpperFirst(Property.attrib['Name']) }} failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str())
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{{ ClassName }}* networkComponent = entity->FindComponent<{{ ClassName }}>();
|
|
|
|
|
if (!networkComponent)
|
|
|
|
|
{
|
|
|
|
|
AZ_Warning("Network Property", false, "{{ ClassName }} Set{{ UpperFirst(Property.attrib['Name']) }} method failed. Entity '%s' (id: %s) is missing {{ ClassName }}, be sure to add {{ ClassName }} to this entity.", entity->GetName().c_str(), id.ToString().c_str())
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{{ ClassName }}Controller* controller = static_cast<{{ ClassName }}Controller*>(networkComponent->GetController());
|
|
|
|
|
if (!controller)
|
|
|
|
|
{
|
|
|
|
|
AZ_Warning("Network Property", false, "{{ ClassName }} Set{{ UpperFirst(Property.attrib['Name']) }} method failed. Entity '%s' (id: %s) {{ ClassName }} is missing the network controller. Network controllers only spawn when some form of write access is available; for example, when you're server authoritatively controlling this entity, or you're a client predictively writing to your player entity. Please check your network context before attempting to set {{ UpperFirst(Property.attrib['Name']) }}.", entity->GetName().c_str(), id.ToString().c_str())
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
controller->Set{{ UpperFirst(Property.attrib['Name']) }}({{ LowerFirst(Property.attrib['Name']) }});
|
|
|
|
|
})
|
|
|
|
|
->Method("GetOn{{ UpperFirst(Property.attrib['Name']) }}ChangedEvent", [](AZ::EntityId id) -> AZ::Event<{{ Property.attrib['Type'] }}>*
|
|
|
|
|
{
|
|
|
|
|
AZ::Entity* entity = AZ::Interface<AZ::ComponentApplicationRequests>::Get()->FindEntity(id);
|
|
|
|
|
if (!entity)
|
|
|
|
|
{
|
|
|
|
|
AZ_Warning("Network Property", false, "{{ ClassName }} GetOn{{ UpperFirst(Property.attrib['Name']) }}ChangedEvent failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str())
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{{ ClassName }}* networkComponent = entity->FindComponent<{{ ClassName }}>();
|
|
|
|
|
if (!networkComponent)
|
|
|
|
|
{
|
|
|
|
|
AZ_Warning("Network Property", false, "{{ ClassName }} Get{{ UpperFirst(Property.attrib['Name']) }} failed. Entity '%s' (id: %s) is missing {{ ClassName }}, be sure to add {{ ClassName }} to this entity.", entity->GetName().c_str(), id.ToString().c_str())
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &networkComponent->m_{{ LowerFirst(Property.attrib['Name']) }}Event;
|
|
|
|
|
})
|
|
|
|
|
->Attribute(AZ::Script::Attributes::AzEventDescription, AZ::BehaviorAzEventDescription{ "On {{ UpperFirst(Property.attrib['Name']) }} Changed Event", {"New {{ Property.attrib['Type'] }}"} })
|
|
|
|
|
|
|
|
|
|
{% endif %}
|
|
|
|
|
{% endcall -%}
|
|
|
|
|
{% endcall %}
|
|
|
|
|
{% endmacro %}
|
|
|
|
|
{#
|
|
|
|
|
|
|
|
|
@@ -805,6 +860,7 @@ m_{{ LowerFirst(Service.attrib['Name']) }} = FindComponent<{{ UpperFirst(Service
|
|
|
|
|
{% endmacro %}
|
|
|
|
|
{#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#}
|
|
|
|
|
{% macro DefineNetworkPropertyEditConstruction(Component, ReplicateFrom, ReplicateTo, ClassName) %}
|
|
|
|
|
{% call(Property) AutoComponentMacros.ParseNetworkProperties(Component, ReplicateFrom, ReplicateTo) %}
|
|
|
|
@@ -1131,6 +1187,7 @@ namespace {{ Component.attrib['Namespace'] }}
|
|
|
|
|
{{ DefineArchetypePropertyReflection(Component, ComponentBaseName)|indent(16) }};
|
|
|
|
|
}
|
|
|
|
|
ReflectToEditContext(context);
|
|
|
|
|
ReflectToBehaviorContext(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void {{ ComponentBaseName }}::{{ ComponentBaseName }}::ReflectToEditContext(AZ::ReflectContext* context)
|
|
|
|
@@ -1162,6 +1219,26 @@ namespace {{ Component.attrib['Namespace'] }}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void {{ ComponentBaseName }}::{{ ComponentBaseName }}::ReflectToBehaviorContext(AZ::ReflectContext* context)
|
|
|
|
|
{
|
|
|
|
|
AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
|
|
|
|
|
if (behaviorContext)
|
|
|
|
|
{
|
|
|
|
|
behaviorContext->Class<{{ ComponentName }}>("{{ ComponentName }}")
|
|
|
|
|
->Attribute(AZ::Script::Attributes::Module, "{{ LowerFirst(Component.attrib['Namespace']) }}")
|
|
|
|
|
->Attribute(AZ::Script::Attributes::Category, "{{ UpperFirst(Component.attrib['Namespace']) }}")
|
|
|
|
|
|
|
|
|
|
// Reflect Network Properties Get, Set, and OnChanged methods
|
|
|
|
|
{{ DefineNetworkPropertyBehaviorReflection(Component, 'Authority', 'Authority', ComponentName) | indent(16) -}}
|
|
|
|
|
{{ DefineNetworkPropertyBehaviorReflection(Component, 'Authority', 'Server', ComponentName) | indent(16) -}}
|
|
|
|
|
{{ DefineNetworkPropertyBehaviorReflection(Component, 'Authority', 'Client', ComponentName) | indent(16) -}}
|
|
|
|
|
{{ DefineNetworkPropertyBehaviorReflection(Component, 'Authority', 'Autonomous', ComponentName) | indent(16) -}}
|
|
|
|
|
{{ DefineNetworkPropertyBehaviorReflection(Component, 'Autonomous', 'Authority', ComponentName) | indent(16) -}}
|
|
|
|
|
{{- DefineArchetypePropertyBehaviorReflection(Component, ComponentName) | indent(16) }}
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void {{ ComponentBaseName }}::{{ ComponentBaseName }}::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
|
|
|
|
|
{
|
|
|
|
|
provided.push_back(AZ_CRC_CE("{{ ComponentName }}Service"));
|
|
|
|
|