Files
Plugin/Source/SenseGlove/Private/SenseGloveModule.cpp
T

221 lines
8.3 KiB
C++
Raw Normal View History

2022-11-02 22:43:14 +01:00
/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
2024-02-03 04:39:36 +01:00
* Copyright (c) 2020 - 2024 SenseGlove
2022-11-02 22:43:14 +01:00
*
* 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"
2024-06-06 14:30:02 +02:00
#include "Engine/Engine.h"
2024-06-06 14:30:02 +02:00
#include "GameMapsSettings.h"
#include "Misc/CoreDelegates.h"
2022-11-02 22:43:14 +01:00
#include "SGLog/SGLog.h"
2024-06-06 14:30:02 +02:00
#include "SenseGlove/Engine/SGGameInstance.h"
#include "SenseGlove/GameFramework/SGGameModeBase.h"
#include "SenseGlove/GameFramework/SGGameUserSettings.h"
#include "SGSettings/SGSettings.h"
2022-11-02 22:43:14 +01:00
#define LOCTEXT_NAMESPACE "FSenseGloveModule"
void FSenseGloveModule::StartupModule()
{
2024-03-20 18:20:11 +01:00
SGLOG("Starting up the SenseGlove module...");
2024-06-06 14:30:02 +02:00
OnPostEngineInitHandle = FCoreDelegates::OnPostEngineInit.AddRaw(
this, &FSenseGloveModule::OnPostEngineInit);
2022-11-02 22:43:14 +01:00
}
void FSenseGloveModule::PreUnloadCallback()
{
2024-03-20 18:20:11 +01:00
SGLOG("Unloading the SenseGlove module...");
2022-11-02 22:43:14 +01:00
}
void FSenseGloveModule::PostLoadCallback()
{
SGLOG("Loading of SenseGlove module has succeeded!");
}
void FSenseGloveModule::ShutdownModule()
{
2024-03-20 18:20:11 +01:00
SGLOG("Shutting down the SenseGlove module...");
2024-06-06 14:30:02 +02:00
FCoreDelegates::OnPostEngineInit.Remove(OnPostEngineInitHandle);
2022-11-02 22:43:14 +01:00
}
2024-06-06 14:30:02 +02:00
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...");
2024-06-06 14:30:02 +02:00
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