Skip to content

Commit

Permalink
Convert GameplayModule to UPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
JDSherbert committed Jun 9, 2024
1 parent 8297508 commit 1c7bb1c
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 39 deletions.
16 changes: 0 additions & 16 deletions DependencyInjector/DependencyInjectorModule.Build.cs

This file was deleted.

5 changes: 0 additions & 5 deletions DependencyInjector/Private/DependencyInjectorModule.cpp

This file was deleted.

24 changes: 24 additions & 0 deletions DependencyInjectorPlugin/DependencyInjectorPlugin.uplugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.0",
"FriendlyName": "DependencyInjector",
"Description": "Dependency Injector Plugin",
"Category": "Sherbert",
"CreatedBy": "JDSherbert",
"CreatedByURL": "https://github.com/JDSherbert",
"DocsURL": "https://github.com/JDSherbert",
"MarketplaceURL": "",
"SupportURL": "mailto:[email protected]",
"CanContainContent": true,
"IsBetaVersion": false,
"IsExperimentalVersion": false,
"Installed": false,
"Modules": [
{
"Name": "DependencyInjectorPlugin",
"Type": "Runtime",
"LoadingPhase": "Default"
}
]
}
Binary file added DependencyInjectorPlugin/Resources/Icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// �2024 JDSherbert. All rights reserved.

using UnrealBuildTool;

public class DependencyInjectorPlugin : ModuleRules
{
public DependencyInjectorPlugin(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicIncludePaths.AddRange(
new string[] {
// ... add public include paths required here ...
}
);


PrivateIncludePaths.AddRange(
new string[] {
// ... add other private include paths required here ...
}
);


PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
// ... add other public dependencies that you statically link with here ...
}
);


PrivateDependencyModuleNames.AddRange(
new string[]
{
"Projects",
"InputCore",
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
// ... add private dependencies that you statically link with here ...
}
);


DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#include "DependencyInjector.h"

/* ------------------------------ Initializations --------------------------------- */
/* ------------------------------------------------------------ */

UDependencyInjector* UDependencyInjector::Instance = nullptr;

/* ---------------------------- Method Definitions ------------------------------- */
/* ------------------------------------------------------------ */

void UDependencyInjector::RegisterObject(UObject* InjectionObject)
{
Expand All @@ -20,7 +20,7 @@ void UDependencyInjector::RegisterObject(UObject* InjectionObject)
Instance->RegisteredObjects.FindOrAdd(ObjectClass).Add(InjectionObject);
}

/* ------------------------------------------------------------------------------- */
/* ------------------------------------------------------------ */

void UDependencyInjector::UnregisterObject(UObject* InjectionObject)
{
Expand All @@ -37,7 +37,7 @@ void UDependencyInjector::UnregisterObject(UObject* InjectionObject)
}
}

/* ------------------------------------------------------------------------------- */
/* ------------------------------------------------------------ */

template<class T>
T* UDependencyInjector::GetRegisteredObject()
Expand All @@ -60,4 +60,4 @@ T* UDependencyInjector::GetRegisteredObject()
return nullptr;
}

/* ------------------------------------------------------------------------------- */
/* ------------------------------------------------------------ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ©2024 JDSherbert. All rights reserved.

#include "DependencyInjectorPlugin.h"

/* ------------------------------------------------------------ */

#define LOCTEXT_NAMESPACE "FDependencyInjectorPluginModule"

/* ------------------------------------------------------------ */

void FDependencyInjectorPluginModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
}

/* ------------------------------------------------------------ */

void FDependencyInjectorPluginModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
}

/* ------------------------------------------------------------ */

#undef LOCTEXT_NAMESPACE

/* ------------------------------------------------------------ */

IMPLEMENT_MODULE(FDependencyInjectorPluginModule, DependencyInjectorPlugin)

/* ------------------------------------------------------------ */
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@

#include "DependencyInjector.generated.h"

/* ------------------------------ Class Definition ------------------------------- */
/* ------------------------------------------------------------ */

/**
* Dependency Injection Class. Performs behaviors related to DI.
* Register the objects/services and then populate clients with those service/object instances.
* @since 09/01/2024
*
* @since Unreal Engine 5.2
* @author JDSherbert
*/
UCLASS()
class SHERBERT_API UDependencyInjector : public UObject
class DEPENDENCYINJECTORPLUGIN_API UDependencyInjector : public UObject
{
GENERATED_BODY()

Expand All @@ -30,51 +31,59 @@ class SHERBERT_API UDependencyInjector : public UObject

/**
* Get Injector Singleton instance.
*
* @return UDependencyInjector* : Returns the singleton instance of this class, if it exists.
* @since 09/01/2024
*
* @since Unreal Engine 5.2
* @author JDSherbert
*/
UFUNCTION(BlueprintCallable, Category = "Sherbert|Dependency Injector")
UFUNCTION(BlueprintCallable, Category = "Dependency Injector")
FORCEINLINE static UDependencyInjector* GetInjectorInstance() { return Instance; }

/**
* Register an object with the Dependency Injector.
*
* @param InjectionObject : The object to add to the Injector.
* @since 09/01/2024
*
* @since Unreal Engine 5.2
* @author JDSherbert
*/
template<class T>
UFUNCTION(BlueprintCallable, Category = "Sherbert|Dependency Injector")
UFUNCTION(BlueprintCallable, Category = "Dependency Injector")
static void RegisterObject(T* InjectionObject);

/**
* Unregister an object with the Dependency Injector.
*
* @param InjectionObject : The object to remove from the Injector.
* @since 09/01/2024
*
* @since Unreal Engine 5.2
* @author JDSherbert
*/
template<class T>
UFUNCTION(BlueprintCallable, Category = "Sherbert|Dependency Injector")
UFUNCTION(BlueprintCallable, Category = "Dependency Injector")
static void UnregisterObject(T* InjectionObject);

/**
* Get an object of a specific class that is registered with the Dependency Injector.
*
* @return T* : Returns a copy of a registered object based on type.
* @since 09/01/2024
*
* @since Unreal Engine 5.2
* @author JDSherbert
*/
template<class T>
UFUNCTION(BlueprintCallable, Category = "Sherbert|Dependency Injector")
UFUNCTION(BlueprintCallable, Category = "Dependency Injector")
static T* GetRegisteredObject();

private:

/** Map to store registered objects. */
UPROPERTY(Category = "Sherbert|Dependency Injector")
UPROPERTY(Category = "Dependency Injector")
TMap<const UClass*, TArray<UObject*>> RegisteredObjects;

// Singleton instance
static UDependencyInjector* Instance;
};

/* ------------------------------------------------------------------------------- */
/* ------------------------------------------------------------ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ©2024 JDSherbert. All rights reserved.

#pragma once

#include <Runtime/Core/Public/CoreMinimal.h>

#include <Runtime/Core/Public/Modules/ModuleManager.h>

/* ------------------------------------------------------------ */

class FDependencyInjectorPluginModule : public IModuleInterface
{

public:

/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;

};

/* ------------------------------------------------------------ */

0 comments on commit 1c7bb1c

Please sign in to comment.