/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include #include #include #include #include namespace AWSGameLift { AWSGameLiftClientSystemComponent::AWSGameLiftClientSystemComponent() { m_gameliftClientManager = AZStd::make_unique(); } void AWSGameLiftClientSystemComponent::Reflect(AZ::ReflectContext* context) { ReflectCreateSessionRequest(context); AWSGameLiftCreateSessionOnQueueRequest::Reflect(context); AWSGameLiftCreateSessionRequest::Reflect(context); AWSGameLiftJoinSessionRequest::Reflect(context); AWSGameLiftSearchSessionsRequest::Reflect(context); ReflectSearchSessionsResponse(context); if (AZ::SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() ->Version(0) ; if (AZ::EditContext* editContext = serialize->GetEditContext()) { editContext ->Class( "AWSGameLiftClient", "Create the GameLift client manager that handles communication between game clients and the GameLift service.") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System")) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ; } } if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) { behaviorContext->EBus("AWSGameLiftRequestBus") ->Attribute(AZ::Script::Attributes::Category, "AWSGameLift") ->Event("ConfigureGameLiftClient", &AWSGameLiftRequestBus::Events::ConfigureGameLiftClient, {{{"Region", ""}}}) ->Event("CreatePlayerId", &AWSGameLiftRequestBus::Events::CreatePlayerId, {{{"IncludeBrackets", ""}, {"IncludeDashes", ""}}}) ; behaviorContext->EBus("AWSGameLiftSessionAsyncRequestBus") ->Attribute(AZ::Script::Attributes::Category, "AWSGameLift") ->Event("CreateSessionAsync", &AWSGameLiftSessionAsyncRequestBus::Events::CreateSessionAsync, {{{"CreateSessionRequest", ""}}}) ->Event("JoinSessionAsync", &AWSGameLiftSessionAsyncRequestBus::Events::JoinSessionAsync, {{{"JoinSessionRequest", ""}}}) ->Event("SearchSessionsAsync", &AWSGameLiftSessionAsyncRequestBus::Events::SearchSessionsAsync, {{{"SearchSessionsRequest", ""}}}) ->Event("LeaveSessionAsync", &AWSGameLiftSessionAsyncRequestBus::Events::LeaveSessionAsync) ; behaviorContext ->EBus("AWSGameLiftSessionAsyncRequestNotificationBus") ->Attribute(AZ::Script::Attributes::Category, "AWSGameLift") ->Handler() ; behaviorContext->EBus("AWSGameLiftSessionRequestBus") ->Attribute(AZ::Script::Attributes::Category, "AWSGameLift") ->Event("CreateSession", &AWSGameLiftSessionRequestBus::Events::CreateSession, {{{"CreateSessionRequest", ""}}}) ->Event("JoinSession", &AWSGameLiftSessionRequestBus::Events::JoinSession, {{{"JoinSessionRequest", ""}}}) ->Event("SearchSessions", &AWSGameLiftSessionRequestBus::Events::SearchSessions, {{{"SearchSessionsRequest", ""}}}) ->Event("LeaveSession", &AWSGameLiftSessionRequestBus::Events::LeaveSession) ; } } void AWSGameLiftClientSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC_CE("AWSGameLiftClientService")); } void AWSGameLiftClientSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC_CE("AWSGameLiftClientService")); } void AWSGameLiftClientSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { required.push_back(AZ_CRC_CE("AWSCoreService")); } void AWSGameLiftClientSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { AZ_UNUSED(dependent); } void AWSGameLiftClientSystemComponent::Init() { } void AWSGameLiftClientSystemComponent::Activate() { m_gameliftClientManager->ActivateManager(); } void AWSGameLiftClientSystemComponent::Deactivate() { m_gameliftClientManager->DeactivateManager(); } void AWSGameLiftClientSystemComponent::ReflectCreateSessionRequest(AZ::ReflectContext* context) { AzFramework::CreateSessionRequest::Reflect(context); if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) { behaviorContext->Class("CreateSessionRequest") ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value) // Expose base type to BehaviorContext, but hide it to be used directly ->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All) ; } } void AWSGameLiftClientSystemComponent::ReflectSearchSessionsResponse(AZ::ReflectContext* context) { // As it is a common response type, reflection could be moved to AzFramework to avoid duplication AzFramework::SessionConfig::Reflect(context); AzFramework::SearchSessionsResponse::Reflect(context); if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) { behaviorContext->Class("SessionConfig") ->Attribute(AZ::Script::Attributes::Category, "Session") ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value) ->Property("CreationTime", BehaviorValueProperty(&AzFramework::SessionConfig::m_creationTime)) ->Property("CreatorId", BehaviorValueProperty(&AzFramework::SessionConfig::m_creatorId)) ->Property("CurrentPlayer", BehaviorValueProperty(&AzFramework::SessionConfig::m_currentPlayer)) ->Property("DnsName", BehaviorValueProperty(&AzFramework::SessionConfig::m_dnsName)) ->Property("IpAddress", BehaviorValueProperty(&AzFramework::SessionConfig::m_ipAddress)) ->Property("MaxPlayer", BehaviorValueProperty(&AzFramework::SessionConfig::m_maxPlayer)) ->Property("Port", BehaviorValueProperty(&AzFramework::SessionConfig::m_port)) ->Property("SessionId", BehaviorValueProperty(&AzFramework::SessionConfig::m_sessionId)) ->Property("SessionName", BehaviorValueProperty(&AzFramework::SessionConfig::m_sessionName)) ->Property("SessionProperties", BehaviorValueProperty(&AzFramework::SessionConfig::m_sessionProperties)) ->Property("Status", BehaviorValueProperty(&AzFramework::SessionConfig::m_status)) ->Property("StatusReason", BehaviorValueProperty(&AzFramework::SessionConfig::m_statusReason)) ->Property("TerminationTime", BehaviorValueProperty(&AzFramework::SessionConfig::m_terminationTime)) ; behaviorContext->Class("SearchSessionsResponse") ->Attribute(AZ::Script::Attributes::Category, "Session") ->Attribute(AZ::Script::Attributes::Storage, AZ::Script::Attributes::StorageType::Value) ->Property("NextToken", BehaviorValueProperty(&AzFramework::SearchSessionsResponse::m_nextToken)) ->Property("SessionConfigs", BehaviorValueProperty(&AzFramework::SearchSessionsResponse::m_sessionConfigs)) ; } } void AWSGameLiftClientSystemComponent::SetGameLiftClientManager(AZStd::unique_ptr gameliftClientManager) { m_gameliftClientManager.reset(); m_gameliftClientManager = AZStd::move(gameliftClientManager); } } // namespace AWSGameLift