231 lines
8.9 KiB
C++
231 lines
8.9 KiB
C++
/**
|
|
* @file
|
|
*
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @section LICENSE
|
|
*
|
|
* (The MIT License)
|
|
*
|
|
* Copyright (c) 2020 - 2026 SenseGlove
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
* @section DESCRIPTION
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
#include "SenseGloveModule.h"
|
|
|
|
#include "Engine/Engine.h"
|
|
#include "GameMapsSettings.h"
|
|
#include "Misc/CoreDelegates.h"
|
|
#include "Runtime/Launch/Resources/Version.h"
|
|
|
|
#include "SGLog/SGLog.h"
|
|
#include "SenseGlove/Engine/SGGameInstance.h"
|
|
#include "SenseGlove/GameFramework/SGGameModeBase.h"
|
|
#include "SenseGlove/GameFramework/SGGameUserSettings.h"
|
|
#include "SGSettings/SGSettings.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "FSenseGloveModule"
|
|
|
|
void FSenseGloveModule::StartupModule()
|
|
{
|
|
SGLOG("Starting up the SenseGlove module...");
|
|
|
|
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 8
|
|
OnPostEngineInitHandle = FCoreDelegates::GetOnPostEngineInit().AddRaw(
|
|
this, &FSenseGloveModule::OnPostEngineInit);
|
|
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 8 */
|
|
OnPostEngineInitHandle = FCoreDelegates::OnPostEngineInit.AddRaw(
|
|
this, &FSenseGloveModule::OnPostEngineInit);
|
|
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 8 */
|
|
}
|
|
|
|
void FSenseGloveModule::PreUnloadCallback()
|
|
{
|
|
SGLOG("Unloading the SenseGlove module...");
|
|
}
|
|
|
|
void FSenseGloveModule::PostLoadCallback()
|
|
{
|
|
SGLOG("Loading of SenseGlove module has succeeded!");
|
|
}
|
|
|
|
void FSenseGloveModule::ShutdownModule()
|
|
{
|
|
SGLOG("Shutting down the SenseGlove module...");
|
|
|
|
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 8
|
|
FCoreDelegates::GetOnPostEngineInit().Remove(OnPostEngineInitHandle);
|
|
#else /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 8 */
|
|
FCoreDelegates::OnPostEngineInit.Remove(OnPostEngineInitHandle);
|
|
#endif /* ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 8 */
|
|
}
|
|
|
|
void FSenseGloveModule::OnPostEngineInit() const
|
|
{
|
|
const FSGInitializationSettings& Settings{
|
|
USGSettings::GetInstance()->GetInitializationSettings()
|
|
};
|
|
if (!Settings.bValidateIfDefaultClassesAreSGCompliant)
|
|
{
|
|
SGLOG("Will not be checking whether the default classes are SenseGlove-compliant, or not since it's disabled!");
|
|
return;
|
|
}
|
|
|
|
SGLOG("Checking whether the default classes are SenseGlove-compliant, or not...");
|
|
|
|
SGLOG("Checking whether the GameMapsSettings is compliant with SenseGlove, or not...");
|
|
|
|
UGameMapsSettings* GameMapsSettings{UGameMapsSettings::GetGameMapsSettings()};
|
|
if (ensureAlwaysMsgf(GameMapsSettings, TEXT("Invalid GameMapsSettings!")))
|
|
{
|
|
/*************************************************************************************************************
|
|
* GameInstanceClass
|
|
*************************************************************************************************************/
|
|
|
|
{
|
|
SGLOG("Validating if the GameInstanceClass is a SenseGlove GameInstance...");
|
|
|
|
bool bValidGameInstance = false;
|
|
const UClass* CurrentGameInstanceClass{GameMapsSettings->GameInstanceClass.TryLoadClass<UObject>()};
|
|
if (CurrentGameInstanceClass)
|
|
{
|
|
if (CurrentGameInstanceClass->IsChildOf(USGGameInstance::StaticClass()))
|
|
{
|
|
bValidGameInstance = true;
|
|
SGLOG("The GameInstanceClass is a SenseGlove GameInstance, or a subclass.");
|
|
}
|
|
else
|
|
{
|
|
SGLOG("The GameInstanceClass is not a SenseGlove GameInstance, or a subclass.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SGLOG_ERROR("Failed to construct a valid GameInstance from the current settings!");
|
|
}
|
|
|
|
if (!bValidGameInstance)
|
|
{
|
|
SGLOG("Setting the SenseGlove GameInstance as the GameInstanceClass...");
|
|
|
|
static const FSoftClassPath GameInstanceClassPath{TEXT("/Script/SenseGlove.SGGameInstance")};
|
|
GameMapsSettings->GameInstanceClass = GameInstanceClassPath;
|
|
|
|
SGLOG("Successfully set the SenseGlove GameInstance as the GameInstanceClass!");
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************************
|
|
* DefaultGameMode
|
|
*************************************************************************************************************/
|
|
|
|
{
|
|
SGLOG("Validating if the DefaultGameMode is a SenseGlove GameMode...");
|
|
|
|
bool bValidDefaultGameMode = false;
|
|
const FSoftClassPath CurrentDefaultGameModeClassPath{GameMapsSettings->GetGlobalDefaultGameMode()};
|
|
const UClass* CurrentDefaultGameMode{CurrentDefaultGameModeClassPath.TryLoadClass<UObject>()};
|
|
if (CurrentDefaultGameMode)
|
|
{
|
|
if (CurrentDefaultGameMode->IsChildOf(ASGGameModeBase::StaticClass()))
|
|
{
|
|
bValidDefaultGameMode = true;
|
|
SGLOG("The DefaultGameMode is a SenseGlove GameMode, or a subclass.");
|
|
}
|
|
else
|
|
{
|
|
SGLOG("The DefaultGameMode is not a SenseGlove GameMode, or a subclass.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SGLOG_ERROR("Failed to construct a valid GameMode from the current settings!");
|
|
}
|
|
|
|
if (!bValidDefaultGameMode)
|
|
{
|
|
SGLOG("Setting the SenseGlove GameMode as the DefaultGameMode...");
|
|
|
|
static const FString DefaultGameMode{TEXT("/Script/SenseGlove.SGGameModeBase")};
|
|
GameMapsSettings->SetGlobalDefaultGameMode(DefaultGameMode);
|
|
|
|
SGLOG("Successfully set the SenseGlove GameMode as the DefaultGameMode!");
|
|
}
|
|
}
|
|
|
|
/*************************************************************************************************************
|
|
*
|
|
*************************************************************************************************************/
|
|
}
|
|
else
|
|
{
|
|
SGLOG_ERROR("Failed to check whether the GameMapsSettings is compliant with SenseGlove, or not!");
|
|
}
|
|
|
|
SGLOG("Checking whether the GameUserSettingsClass is compliant with SenseGlove, or not...");
|
|
|
|
if (ensureAlwaysMsgf(GEngine, TEXT("Invalid GEngine!")))
|
|
{
|
|
SGLOG("Validating if the GameUserSettingsClass is a SenseGlove GameUserSettings...");
|
|
|
|
bool bValidGameUserSettings = false;
|
|
const UClass* CurrentGameUserSettingsClass{GEngine->GameUserSettingsClassName.TryLoadClass<UObject>()};
|
|
if (CurrentGameUserSettingsClass)
|
|
{
|
|
if (CurrentGameUserSettingsClass->IsChildOf(USGGameUserSettings::StaticClass()))
|
|
{
|
|
bValidGameUserSettings = true;
|
|
SGLOG("The GameUserSettingsClass is a SenseGlove GameUserSettings, or a subclass.");
|
|
}
|
|
else
|
|
{
|
|
SGLOG("The GameUserSettingsClass is not a SenseGlove GameUserSettings, or a subclass.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SGLOG_ERROR("Failed to construct a valid GameUserSettings from the current settings!");
|
|
}
|
|
|
|
if (!bValidGameUserSettings)
|
|
{
|
|
SGLOG("Setting the SenseGlove GameUserSettings as the GameUserSettingsClass...");
|
|
|
|
static const FSoftClassPath GameUserSettingsClassPath{TEXT("/Script/SenseGlove.SGGameUserSettings")};
|
|
GEngine->GameUserSettingsClassName = GameUserSettingsClassPath;
|
|
GEngine->GameUserSettingsClass = USGGameUserSettings::StaticClass();
|
|
GEngine->GameUserSettings = NewObject<USGGameUserSettings>();
|
|
GEngine->GetGameUserSettings()->LoadSettings(true);
|
|
|
|
SGLOG("Successfully set the SenseGlove GameInstance as the GameInstanceClass!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SGLOG_ERROR("Failed to check whether the GameUserSettings is compliant with SenseGlove, or not!");
|
|
}
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE |