Commit 4d709d6d authored by Kyrium's avatar Kyrium
Browse files

Merge branch 'dev' into 'main'

Update 1.9.0

See merge request !1
parents ae71b837 5962938f
......@@ -185,4 +185,5 @@ Friend=(Class="AFGBuildableFrackingActivator", FriendClass="UKBFLResourceNodeDes
Friend=(Class="AFGBuildableResourceExtractorBase", FriendClass="UKBFLResourceNodeDescriptor_ResourceWell")
Friend=(Class="AFGBuildableFrackingActivator", FriendClass="FKBFLModule")
Friend=(Class="AFGBuildableFrackingExtractor", FriendClass="FKBFLModule")
\ No newline at end of file
Friend=(Class="AFGBuildableFrackingExtractor", FriendClass="FKBFLModule")
Friend=(Class="UWorldModuleManager", FriendClass="FKBFLModule")
\ No newline at end of file
#include "BFL/KBFL_Asset.h"
template <class T>
bool UKBFL_Asset::GetSubclassFromAsset(FAssetData AssetData, TSubclassOf<T>& OutClass)
{
if(AssetData.IsValid())
{
if (AssetData.AssetClass != TEXT("Blueprint")) {
return false;
}
FString ExportedPath;
if (!AssetData.GetTagValue(FBlueprintTags::GeneratedClassPath, ExportedPath)) {
return false;
}
FString ClassPath;
if (!FPackageName::ParseExportTextPath(ExportedPath, NULL, &ClassPath)) {
return false;
}
UClass* AssetClass = LoadClass<UObject>(NULL, *ClassPath);
if(AssetClass != NULL && AssetClass->IsChildOf(T::StaticClass()))
{
OutClass = TSubclassOf<T>(AssetClass);
return OutClass != NULL;
}
}
return false;
}
......@@ -30,7 +30,7 @@ void UKBFL_Widgets::TextToNumbers(float& Float, int& Int, FText Text, bool Shoul
if(ShouldClamp)
Float = FMath::Clamp(Float, ClampMin, ClampMax);
Int = FMath::RoundToInt(Float);
Int = FMath::TruncateToHalfIfClose(Float);
}
......
#include "KBFLModule.h"
#include "FGGameMode.h"
#include "KBFLWorldModule.h"
#include "Buildables/FGBuildableFrackingActivator.h"
#include "Buildables/FGBuildableFrackingExtractor.h"
#include "Module/WorldModuleManager.h"
#include "Patching/NativeHookManager.h"
#include "Subsystems/KBFLContentCDOHelperSubsystem.h"
#include "Subsystems/KBFLCustomizerSubsystem.h"
#include "Subsystems/KBFLResourceNodeSubsystem.h"
/*
void GameModePostLogin(CallScope<void(*)(AFGGameMode*, APlayerController*)>& scope, AFGGameMode* gm,
APlayerController* pc)
{
if (gm->HasAuthority() && !gm->IsMainMenuGameMode())
{
//Register RSO
gm->RegisterRemoteCallObjectClass(UAKLBuildableBaseRCO::StaticClass());
}
}
*/
void FrackingActivator_BeginPlay(CallScope<void(*)(AFGBuildableFrackingActivator*)>& scope, AFGBuildableFrackingActivator* selfref)
{
UE_LOG(LogTemp, Warning, TEXT("FrackingActivator_BeginPlay"));
if(!selfref->GetExtractableResource())
{
UE_LOG(LogTemp, Warning, TEXT("FrackingActivator_BeginPlay > K2_DestroyActor"));
selfref->Destroy();
scope.Cancel();
}
}
DECLARE_LOG_CATEGORY_EXTERN(LogKBFLModule, Log, All);
DEFINE_LOG_CATEGORY(LogKBFLModule);
void FrackingExtractor_BeginPlay(CallScope<void(*)(AFGBuildableFrackingExtractor*)>& scope, AFGBuildableFrackingExtractor* selfref)
void AFGBuildableResourceExtractorBase_BeginPlay(CallScope<void(*)(AFGBuildableResourceExtractorBase*)>& scope, AFGBuildableResourceExtractorBase* selfref)
{
UE_LOG(LogTemp, Warning, TEXT("FrackingExtractor_BeginPlay"));
UE_LOG(LogTemp, Warning, TEXT("AFGBuildableResourceExtractorBase_BeginPlay"));
if(!selfref->GetExtractableResource())
{
UE_LOG(LogTemp, Warning, TEXT("FrackingExtractor_BeginPlay > K2_DestroyActor"));
selfref->Destroy();
UE_LOG(LogTemp, Warning, TEXT("AFGBuildableResourceExtractorBase_BeginPlay > (TRY!) K2_DestroyActor"));
selfref->K2_DestroyActor();
scope.Cancel();
}
}
......@@ -42,11 +27,52 @@ void FrackingExtractor_BeginPlay(CallScope<void(*)(AFGBuildableFrackingExtractor
void FKBFLModule::StartupModule()
{
#if !WITH_EDITOR
AFGBuildableFrackingActivator* FrackingActivator = GetMutableDefault<AFGBuildableFrackingActivator>();
SUBSCRIBE_METHOD_VIRTUAL(AFGBuildableFrackingActivator::BeginPlay, FrackingActivator, &FrackingActivator_BeginPlay);
AFGBuildableFrackingExtractor* FrackingExtractor = GetMutableDefault<AFGBuildableFrackingExtractor>();
SUBSCRIBE_METHOD_VIRTUAL(AFGBuildableFrackingExtractor::BeginPlay, FrackingExtractor, &FrackingExtractor_BeginPlay);
AFGBuildableResourceExtractorBase* FrackingExtractor = GetMutableDefault<AFGBuildableResourceExtractorBase>();
SUBSCRIBE_METHOD_VIRTUAL(AFGBuildableResourceExtractorBase::BeginPlay, FrackingExtractor, &AFGBuildableResourceExtractorBase_BeginPlay);
SUBSCRIBE_METHOD(UWorldModuleManager::DispatchLifecycleEvent,
[](auto& Call, UWorldModuleManager* Manager, ELifecyclePhase Phase)
{
if(Manager->RootModuleList.Num() > 0)
{
UKBFLContentCDOHelperSubsystem* CDOHelperSubsystem = Cast<UKBFLContentCDOHelperSubsystem>(Manager->GetWorld()->GetSubsystem<UKBFLContentCDOHelperSubsystem>());
UKBFLCustomizerSubsystem* CustomizerSubsystem = Cast<UKBFLCustomizerSubsystem>(Manager->GetWorld()->GetSubsystem<UKBFLCustomizerSubsystem>());
UKBFLResourceNodeSubsystem* NodeSubsystem = Cast<UKBFLResourceNodeSubsystem>(Manager->GetWorld()->GetSubsystem<UKBFLResourceNodeSubsystem>());
// going save that it called not in the registry phase to avoid crashed while CDO!
for (UWorldModule* RootModule : Manager->RootModuleList) {
if(UKBFLWorldModule* WorldModule = Cast<UKBFLWorldModule>(RootModule))
{
UE_LOG(LogKBFLModule, Log, TEXT("Starting %s Calls"), *WorldModule->GetName());
if(CDOHelperSubsystem)
{
UE_LOG(LogKBFLModule, Log, TEXT("Starting CDOHelperSubsystem"), *WorldModule->GetName());
CDOHelperSubsystem->BeginCDOForModule(RootModule, Phase);
}
if(CustomizerSubsystem && WorldModule->mCallCustomizerInPhase == Phase)
{
UE_LOG(LogKBFLModule, Log, TEXT("Starting CustomizerSubsystem"), *WorldModule->GetName());
CustomizerSubsystem->BeginForModule(RootModule);
}
if(NodeSubsystem && WorldModule->mCallNodesInPhase == Phase)
{
UE_LOG(LogKBFLModule, Log, TEXT("Starting NodeSubsystem"), *WorldModule->GetName());
NodeSubsystem->BeginSpawningForModule(RootModule);
}
}
}
for (UWorldModule* RootModule : Manager->RootModuleList) {
UE_LOG(LogKBFLModule, Log, TEXT("Dispatching lifecycle event %s to RootModule %s"),
*UModModule::LifecyclePhaseToString(Phase), *RootModule->GetName());
RootModule->DispatchLifecycleEvent(Phase);
}
Call.Cancel();
}
});
#endif
}
......
......@@ -3,10 +3,17 @@
#include "KBFLWorldModule.h"
#include "AssetRegistry/IAssetRegistry.h"
#include "BFL/KBFL_Asset.h"
#include "Engine/AssetManager.h"
#include "Registry/ModContentRegistry.h"
#include "Subsystems/KBFLContentCDOHelperSubsystem.h"
#include "Subsystems/KBFLCustomizerSubsystem.h"
#include "Subsystems/KBFLResourceNodeSubsystem.h"
DECLARE_LOG_CATEGORY_EXTERN(KBFLWorldModuleLog, Log, All);
DEFINE_LOG_CATEGORY(KBFLWorldModuleLog);
UKBFLWorldModule::UKBFLWorldModule()
{
bRootModule = false;
......@@ -14,6 +21,8 @@ UKBFLWorldModule::UKBFLWorldModule()
mCDOInformationMap.Add(ELifecyclePhase::CONSTRUCTION, FKBFLCDOInformation());
mCDOInformationMap.Add(ELifecyclePhase::INITIALIZATION, FKBFLCDOInformation());
mCDOInformationMap.Add(ELifecyclePhase::POST_INITIALIZATION, FKBFLCDOInformation());
mAssetRegistryOptions.Add(FKBFLRegistry("/<yourmodref>/<path to folder>"));
}
FKBFLCDOInformation UKBFLWorldModule::GetCDOInformationFromPhase_Implementation(ELifecyclePhase Phase, bool& bHasPhase)
......@@ -68,23 +77,70 @@ TArray<FKBFLMaterialDescriptorInformation> UKBFLWorldModule::GetMaterialInformat
void UKBFLWorldModule::DispatchLifecycleEvent(ELifecyclePhase Phase)
{
Super::DispatchLifecycleEvent(Phase);
if(UKBFLContentCDOHelperSubsystem * Subsystem = Cast<UKBFLContentCDOHelperSubsystem>(GetWorld()->GetSubsystem<UKBFLContentCDOHelperSubsystem>()))
{
Subsystem->BeginCDOForModule(this, Phase);
if (Phase == ELifecyclePhase::INITIALIZATION) {
RegisterKBFLLogicContent();
}
Super::DispatchLifecycleEvent(Phase);
}
// Subsystem begin this call if the phase that set!
if(Phase == mCallCustomizerInPhase)
if(UKBFLCustomizerSubsystem * Subsystem = Cast<UKBFLCustomizerSubsystem>(GetWorld()->GetSubsystem<UKBFLCustomizerSubsystem>()))
{
Subsystem->BeginForModule(this);
}
void UKBFLWorldModule::RegisterKBFLLogicContent()
{
UWorld* WorldObject = GetWorld();
AModContentRegistry* ModContentRegistry = AModContentRegistry::Get(WorldObject);
check(ModContentRegistry);
// Subsystem begin this call if the phase that set!
if(Phase == mCallNodesInPhase)
if(UKBFLResourceNodeSubsystem * Subsystem = Cast<UKBFLResourceNodeSubsystem>(GetWorld()->GetSubsystem<UKBFLResourceNodeSubsystem>()))
if(mUseAssetRegistry && mAssetRegistryOptions.Num() > 0)
{
UE_LOG(KBFLWorldModuleLog, Warning, TEXT("Option to find Assets is enabled, try to find assets for world module %s"), *GetName());
const FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(AssetRegistryConstants::ModuleName);
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
TArray<FAssetData> AssetDatas;
for (FKBFLRegistry Options : mAssetRegistryOptions)
{
Subsystem->BeginSpawningForModule(this);
AssetDatas.Empty();
if(AssetRegistry.GetAssetsByPath(Options.GetPath(), AssetDatas, Options.Recursive))
for (FAssetData AssetData : AssetDatas)
{
if(Options.bRegisterSchematics)
{
TSubclassOf<UFGSchematic> SchematicClass;
if(UKBFL_Asset::GetSubclassFromAsset<UFGSchematic>(AssetData, SchematicClass)) {
UE_LOG(KBFLWorldModuleLog, Warning, TEXT("Register Schematic (%s) in ModContentRegistry"), *SchematicClass->GetName());
ModContentRegistry->RegisterSchematic(GetOwnerModReference(), SchematicClass);
// is a fix for SF+ Content remover!
mSchematics.AddUnique(SchematicClass);
continue;
}
}
if(Options.bRegisterResearchTrees)
{
TSubclassOf<UFGResearchTree> ResearchTreeClass;
if(UKBFL_Asset::GetSubclassFromAsset<UFGResearchTree>(AssetData, ResearchTreeClass)) {
UE_LOG(KBFLWorldModuleLog, Warning, TEXT("Register ResearchTree (%s) in ModContentRegistry"), *AssetData.AssetName.ToString());
ModContentRegistry->RegisterResearchTree(GetOwnerModReference(), ResearchTreeClass);
// is a fix for SF+ Content remover!
mResearchTrees.AddUnique(ResearchTreeClass);
continue;
}
}
if(Options.bRegisterRecipes)
{
TSubclassOf<UFGRecipe> RecipeClass;
if(UKBFL_Asset::GetSubclassFromAsset<UFGRecipe>(AssetData, RecipeClass)) {
UE_LOG(KBFLWorldModuleLog, Warning, TEXT("Register Recipe (%s) in ModContentRegistry"), *AssetData.AssetName.ToString());
ModContentRegistry->RegisterRecipe(GetOwnerModReference(), RecipeClass);
continue;
}
}
}
}
}
}
......@@ -12,7 +12,6 @@ bool UKBFL_CDOHelperClass_RemoverBase::RemoveSchematic(TSubclassOf<UFGSchematic>
{
if(Subclass && RecipeSubsystem && SchematicSubsystem && !Exclude.Contains(Subclass))
{
UE_LOG(HelperClassRemoverBaseLog, Log, TEXT("RemoveSchematic > Start Remove %s"), *Subclass->GetName());
if(CheckClassString(Subclass, ExcludeStrings))
{
TArray<UFGUnlock*> Unlocks = UFGSchematic::GetUnlocks(Subclass);
......@@ -44,19 +43,19 @@ bool UKBFL_CDOHelperClass_RemoverBase::RemoveSchematic(TSubclassOf<UFGSchematic>
if(SchematicSubsystem->mAllSchematics.Contains(Subclass))
{
SchematicSubsystem->mAllSchematics.Remove(Subclass);
UE_LOG(HelperClassRemoverBaseLog, Log, TEXT("RemoveSchematic > Remove mAllSchematics %d"), SchematicSubsystem->mAllSchematics.Contains(Subclass));
UE_LOG(HelperClassRemoverBaseLog, Log, TEXT("RemoveSchematic > Remove mAllSchematics %s"), *Subclass->GetName());
}
if(SchematicSubsystem->mAvailableSchematics.Contains(Subclass))
{
SchematicSubsystem->mAvailableSchematics.Remove(Subclass);
UE_LOG(HelperClassRemoverBaseLog, Log, TEXT("RemoveSchematic > Remove mAvailableSchematics %d"), SchematicSubsystem->mAvailableSchematics.Contains(Subclass));
UE_LOG(HelperClassRemoverBaseLog, Log, TEXT("RemoveSchematic > Remove mAvailableSchematics %s"), *Subclass->GetName());
}
if(SchematicSubsystem->mPurchasedSchematics.Contains(Subclass))
{
SchematicSubsystem->mPurchasedSchematics.Remove(Subclass);
UE_LOG(HelperClassRemoverBaseLog, Log, TEXT("RemoveSchematic > Remove mPurchasedSchematics %d"), SchematicSubsystem->mPurchasedSchematics.Contains(Subclass));
UE_LOG(HelperClassRemoverBaseLog, Log, TEXT("RemoveSchematic > Remove mPurchasedSchematics %s"), *Subclass->GetName());
}
//Subclass.GetDefaultObject()->mType = ESchematicType::EST_Custom;
......@@ -123,15 +122,12 @@ bool UKBFL_CDOHelperClass_RemoverBase::CheckClassString(UClass* Class, TArray<FS
bool UKBFL_CDOHelperClass_RemoverBase::RemoveRecipe(TSubclassOf<UFGRecipe> Subclass, AFGRecipeManager* RecipeSubsystem, TArray<TSubclassOf<UFGRecipe>> Exclude, TArray<FString> ExcludeStrings)
{
UE_LOG(HelperClassRemoverBaseLog, Log, TEXT("Call RemoveRecipe"));
if(Subclass && RecipeSubsystem && !Exclude.Contains(Subclass))
{
if(CheckClassString(Subclass, ExcludeStrings))
{
UE_LOG(HelperClassRemoverBaseLog, Log, TEXT("Try RemoveRecipe > remove Recipe %s"), *Subclass->GetName());
if(ContainBuildGun(Subclass))
{
UE_LOG(HelperClassRemoverBaseLog, Log, TEXT("Try RemoveRecipe > ContainBuildGun"));
TArray< FItemAmount > Products = UFGRecipe::GetProducts(Subclass);
if(Products.IsValidIndex(0))
{
......@@ -179,12 +175,10 @@ bool UKBFL_CDOHelperClass_RemoverBase::RemoveResearchTree(TSubclassOf<UFGResearc
TArray<TSubclassOf<UFGRecipe>> ExcludeRecipes, TArray<FString> ExcludeRecipesStrings,
TArray<TSubclassOf<UFGSchematic>> ExcludeSchematics, TArray<FString> ExcludeSchematicsStrings)
{
UE_LOG( HelperClassRemoverBaseLog, Log, TEXT( "RemoveResearchTree" ) );
if(Subclass && ResearchManager && RecipeSubsystem && SchematicSubsystem && !Exclude.Contains(Subclass))
{
if(CheckClassString(Subclass, ExcludeStrings))
{
UE_LOG( HelperClassRemoverBaseLog, Log, TEXT( "RemoveResearchTree CheckClassString" ) );
TArray<TSubclassOf<UFGSchematic>> Schematics;
ExtractSchematicsFromResearchTree(Subclass, Schematics);
......
#pragma once
#include "CoreMinimal.h"
#include "FGInventoryComponent.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "KBFL_Asset.generated.h"
/**
*
*/
UCLASS()
class KBFL_API UKBFL_Asset : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/** Return the Index where the ItemClass allowed on Slot in Inventory */
template<class T>
UFUNCTION(BlueprintCallable, Category="KBFL Items")
static bool GetSubclassFromAsset(FAssetData AssetData, TSubclassOf<T>& OutClass);
};
\ No newline at end of file
......@@ -21,6 +21,47 @@ struct KBFL_API FKBFLSchematicArray
TArray<TSubclassOf<UFGSchematic>> mSchematics = {};
};
/**
*
*/
USTRUCT(BlueprintType)
struct KBFL_API FKBFLRegistry
{
GENERATED_BODY()
FKBFLRegistry() {};
FKBFLRegistry(FString InPath) {
Path = InPath;
};
FKBFLRegistry(FString InPath, bool InRecursive) {
Path = InPath;
Recursive = InRecursive;
};
UPROPERTY(BlueprintReadWrite, EditAnywhere)
FString Path = "/<modref>/";
UPROPERTY(BlueprintReadWrite, EditAnywhere)
bool Recursive = false;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
bool bRegisterSchematics = true;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
bool bRegisterResearchTrees = true;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
bool bRegisterRecipes = false;
FName GetPath()
{
Path.RemoveFromEnd("/", ESearchCase::IgnoreCase);
return FName(Path);
}
};
/**
*
*/
......
......@@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "BFL/KBFL_Struct.h"
#include "Interfaces/KBFLContentCDOHelperInterface.h"
#include "Interfaces/KBFLCustomizerInterface.h"
#include "Interfaces/KBFLResourceNodeInterface.h"
......@@ -44,6 +45,8 @@ class KBFL_API UKBFLWorldModule : public UGameWorldModule, public IKBFLCustomize
virtual void DispatchLifecycleEvent(ELifecyclePhase Phase) override;
// END UGameWorldModule
void RegisterKBFLLogicContent();
/** Information for CDO's */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "KBFL|CDOHelper")
TMap<ELifecyclePhase, FKBFLCDOInformation> mCDOInformationMap;
......@@ -88,5 +91,20 @@ class KBFL_API UKBFLWorldModule : public UGameWorldModule, public IKBFLCustomize
/** Default Swatches for the Swatch Group */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "KBFL|ResourceNodes")
ELifecyclePhase mCallNodesInPhase = ELifecyclePhase::INITIALIZATION;
/**
* List of schematics that will be automatically registered
* by the SML during the loading phase
*/
//UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="KBFL GameWorldModule")
//TMap<ESchematicType, FKBFLSchematicArray> mSortedSchematics;
UPROPERTY(meta=(NoAutoJson = true))
bool mUseAssetRegistry = false;
/**
* Path for automatic find classes to register
*/
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="KBFL GameWorldModule", meta = ( EditCondition = mUseAssetRegistry ))
TArray<FKBFLRegistry> mAssetRegistryOptions;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment