Commit 3a55890d authored by Kyrium's avatar Kyrium
Browse files

Merge branch 'dev' into 'main'

1.12.1

See merge request !10
parents eb2d04ea eaf70588
No preview for this file type
......@@ -185,7 +185,7 @@ TArray<FKBFLRecipeInfo> UKBFL_Recipes::GetAllModsRecipesWithInfo(UObject* WorldC
}
void UKBFL_Recipes::CDO_MoveRecipesFromBuilding(UObject* WorldContext, TSoftClassPtr<UObject> From, TSoftClassPtr<UObject> To, TArray<TSubclassOf<UFGItemCategory>> IgnoreCategory, TArray<TSubclassOf<UFGRecipe>> IgnoreRecipe)
{
{
TSubclassOf<UObject> SubFrom = nullptr;
TSubclassOf<UObject> SubTo = nullptr;
......@@ -222,20 +222,16 @@ void UKBFL_Recipes::CDO_MoveRecipesFromBuilding(UObject* WorldContext, TSoftClas
{
if(!IgnoreRecipe.Contains(Recipe))
{
auto Default = Cast<UFGRecipe>(Recipe->GetDefaultObject());
UFGRecipe* Default = Recipe.GetDefaultObject();
check(Default);
if(Default)
{
if(!IgnoreCategory.Contains(Default->mOverriddenCategory))
if(!IgnoreCategory.Contains(Default->mOverriddenCategory) || Default->mOverriddenCategory == nullptr)
{
if(Default->mProducedIn.Contains(From))
{
Default->mProducedIn.Remove(From);
Default->mProducedIn.Add(To);
UE_LOG(LogTemp, Error, TEXT("CDO_MoveRecipesFromBuilding -> Move Recipe %s : %s -> %s"), *Default->GetName(), *From->GetName(), *To->GetName());
}
Default->mProducedIn.Remove(From);
Default->mProducedIn.Add(To);
UE_LOG(LogTemp, Error, TEXT("CDO_MoveRecipesFromBuilding -> Move Recipe %s : %s -> %s"), *Default->GetName(), *From->GetName(), *To->GetName());
Recipe->MarkPackageDirty();
Default->MarkPackageDirty();
}
}
......
#include "KBFLModule.h"
#include "FGGameMode.h"
#include "FGGameState.h"
#include "KBFLWorldModule.h"
#include "Buildables/FGBuildableFrackingActivator.h"
#include "Buildables/FGBuildableFrackingExtractor.h"
......@@ -37,17 +38,41 @@ void GameModePostLogin(CallScope<void(*)(AFGGameMode*, APlayerController*)>& sco
}
}
void GetBuildingColorDataForSlot(CallScope<FFactoryCustomizationColorSlot(*)(AFGGameState*, uint8)>& scope, AFGGameState* GameState, uint8 slot)
{
if(GameState)
if(GameState->GetWorld())
if(UKBFLCustomizerSubsystem* CustomizerSubsystem = Cast<UKBFLCustomizerSubsystem>(GameState->GetWorld()->GetSubsystem<UKBFLCustomizerSubsystem>()))
if(!CustomizerSubsystem->Initialized)
CustomizerSubsystem->GatherInterfaces();
if(!GameState)
{
UE_LOG(LogKBFLModule, Log, TEXT("Cancel function GetBuildingColorDataForSlot because GameState is currently INVALID!"));
scope.Override(FFactoryCustomizationColorSlot());
}
else if(!GameState->GetWorld())
{
UE_LOG(LogKBFLModule, Log, TEXT("Cancel function GetBuildingColorDataForSlot because GameState->GetWorld() is currently INVALID!"));
scope.Override(FFactoryCustomizationColorSlot());
}
}
void FKBFLModule::StartupModule()
{
#if !WITH_EDITOR
AFGBuildableResourceExtractorBase* FrackingExtractor = GetMutableDefault<AFGBuildableResourceExtractorBase>();
AFGGameMode* LocalGameMode = GetMutableDefault<AFGGameMode>();
AFGGameState* GameState = GetMutableDefault<AFGGameState>();
SUBSCRIBE_METHOD_VIRTUAL(AFGBuildableResourceExtractorBase::BeginPlay, FrackingExtractor, &AFGBuildableResourceExtractorBase_BeginPlay);
SUBSCRIBE_METHOD_VIRTUAL(AFGGameMode::PostLogin, LocalGameMode, &GameModePostLogin)
SUBSCRIBE_METHOD(AFGGameState::GetBuildingColorDataForSlot, &GetBuildingColorDataForSlot);
SUBSCRIBE_METHOD(UWorldModuleManager::DispatchLifecycleEvent,
[](auto& Call, UWorldModuleManager* Manager, ELifecyclePhase Phase)
SUBSCRIBE_METHOD(UWorldModuleManager::DispatchLifecycleEvent, [](auto& Call, UWorldModuleManager* Manager, ELifecyclePhase Phase)
{
if(Manager->RootModuleList.Num() > 0)
{
......@@ -61,16 +86,11 @@ void FKBFLModule::StartupModule()
{
if(!WorldModule->bScanForCDOsDone)
{
UE_LOG(LogKBFLModule, Log, TEXT("Try to find all CDOs in Mod: %s"), *WorldModule->GetOwnerModReference().ToString());
WorldModule->FindAllCDOs();
}
UE_LOG(LogKBFLModule, Log, TEXT("Starting Calls for Mod: %s"), *WorldModule->GetOwnerModReference().ToString());
if(CDOHelperSubsystem)
{
UE_LOG(LogKBFLModule, Log, TEXT("Starting CDOHelperSubsystem for Mod: %s"), *WorldModule->GetOwnerModReference().ToString());
CDOHelperSubsystem->BeginCDOForModule(RootModule, Phase);
}
if(CustomizerSubsystem && WorldModule->mCallCustomizerInPhase == Phase)
{
......
......@@ -412,16 +412,19 @@ void UKBFLAssetDataSubsystem::GetRecipesOfProducer(TArray<TSubclassOf<UObject>>
UE_LOG(AssetDataSubsystemLog, Error, TEXT("Try to get classes without Init before the subsytem! CANCEL!"));
return;
}
FCriticalSection Mutex;
ParallelFor(mAllFoundedRecipes.Num(), [&](int32 Idx) {
if(TSubclassOf<UFGRecipe> Class = mAllFoundedRecipes[Idx])
{
Mutex.Lock();
if(CheckHasRecipeProducer(Class, Producers))
{
Mutex.Lock();
Out_Items.Add(Class);
Mutex.Unlock();
}
Mutex.Unlock();
}
});
}
......@@ -436,12 +439,14 @@ void UKBFLAssetDataSubsystem::GetBuildableOfChilds(TArray<UClass*> Childs, TArra
FCriticalSection Mutex;
ParallelFor(mAllFoundedBuildables.Num(), [&](int32 Idx) {
if(TSubclassOf<AFGBuildable> Class = mAllFoundedBuildables[Idx])
{
Mutex.Lock();
if(CheckChild(Class, Childs, UseNativeCheck))
{
Mutex.Lock();
Out_Items.Add(Class);
Mutex.Unlock();
}
Mutex.Unlock();
}
});
}
......@@ -465,9 +470,17 @@ bool UKBFLAssetDataSubsystem::CheckHasRecipeProducer(TSubclassOf<UFGRecipe> Test
TArray<TSubclassOf<UObject>> Producers)
{
if(TestClass)
for (TSubclassOf<AFGBuildable> Producer : Producers)
if(UFGRecipe::IsProducedIn(TestClass, Producer))
return true;
{
const TArray<TSubclassOf<UObject>> RecipeProducers = UFGRecipe::GetProducedIn(TestClass);
for (TSubclassOf<UObject> Producer : Producers)
if(Producer)
{
if(RecipeProducers.Contains(Producer))
{
return true;
}
}
}
return false;
}
......@@ -482,13 +495,15 @@ void UKBFLAssetDataSubsystem::GetObjectsOfChilds(TArray<UClass*> Childs, TArray<
FCriticalSection Mutex;
ParallelFor(mAllFoundedObjects.Num(), [&](int32 Idx) {
if(TSubclassOf<UObject> Class = mAllFoundedObjects[Idx])
{
Mutex.Lock();
if(CheckChild(Class, Childs, UseNativeCheck))
{
Mutex.Lock();
Out_Items.Add(Class);
Mutex.Unlock();
}
});
Mutex.Unlock();
}
}, EParallelForFlags::ForceSingleThread);
}
void UKBFLAssetDataSubsystem::GetDriveablePawnsOfChilds(TArray<UClass*> Childs,
......
......@@ -14,6 +14,20 @@ DECLARE_LOG_CATEGORY_EXTERN(CustomizerSubsystem, Log, All)
DEFINE_LOG_CATEGORY(CustomizerSubsystem)
void UKBFLCustomizerSubsystem::Tick(float DeltaTime)
{
if(Initialized && !Gathered)
{
Initialized = false;
OnWorldBeginPlay();
}
}
TStatId UKBFLCustomizerSubsystem::GetStatId() const
{
RETURN_QUICK_DECLARE_CYCLE_STAT(UKBFLCustomizerSubsystem, STATGROUP_Tickables);
}
void UKBFLCustomizerSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Collection.InitializeDependency(USubsystemActorManager::StaticClass());
......@@ -68,7 +82,7 @@ void UKBFLCustomizerSubsystem::OnWorldBeginPlay()
}
}
void UKBFLCustomizerSubsystem::RegisterSwatchesInSubsystem(TArray<FKBFLSwatchInformation> SwatchInformations)
bool UKBFLCustomizerSubsystem::RegisterSwatchesInSubsystem(TArray<FKBFLSwatchInformation> SwatchInformations)
{
AFGBuildableSubsystem* Subsystem = AFGBuildableSubsystem::Get(this);
AFGGameState* FGGameState = Cast<AFGGameState>(UGameplayStatics::GetGameState(this));
......@@ -103,7 +117,6 @@ void UKBFLCustomizerSubsystem::RegisterSwatchesInSubsystem(TArray<FKBFLSwatchInf
);
// Add to Array
FGGameState->mBuildingColorSlots_Data.Add(NewColourSlot);
Subsystem->mColorSlots_Data.Add(NewColourSlot);
FGGameState->SetupColorSlots_Data(Subsystem->mColorSlots_Data);
FGGameState->Server_SetBuildingColorDataForSlot(i, NewColourSlot);
......@@ -123,16 +136,13 @@ void UKBFLCustomizerSubsystem::RegisterSwatchesInSubsystem(TArray<FKBFLSwatchInf
UE_LOG(CustomizerSubsystem, Log, TEXT("New Colour slot added: %d"), i);
}
}
else
// Add to Array
if(!FGGameState->mBuildingColorSlots_Data.IsValidIndex(ColourIndex))
{
UE_LOG(CustomizerSubsystem, Log, TEXT("Index allready set %d"), ColourIndex);
// Add to Array
if(!FGGameState->mBuildingColorSlots_Data.IsValidIndex(ColourIndex))
{
FGGameState->mBuildingColorSlots_Data[ColourIndex] = Subsystem->mColorSlots_Data[ColourIndex];
FGGameState->SetupColorSlots_Data(Subsystem->mColorSlots_Data);
UE_LOG(CustomizerSubsystem, Log, TEXT("write color again to gamestate: %d / %d"), FGGameState->mBuildingColorSlots_Data.Num(), Subsystem->mColorSlots_Data.Num());
}
FGGameState->mBuildingColorSlots_Data[ColourIndex] = Subsystem->mColorSlots_Data[ColourIndex];
FGGameState->SetupColorSlots_Data(Subsystem->mColorSlots_Data);
UE_LOG(CustomizerSubsystem, Log, TEXT("write color again to gamestate: %d / %d"), FGGameState->mBuildingColorSlots_Data.Num(), Subsystem->mColorSlots_Data.Num());
}
mSwatchIDMap.Add(ColourIndex, Swatch.mSwatch);
......@@ -161,19 +171,44 @@ void UKBFLCustomizerSubsystem::RegisterSwatchesInSubsystem(TArray<FKBFLSwatchInf
//FGGameState->Init();
Subsystem->mColorSlotsAreDirty = true;
return;
return true;
}
if(FGGameState)
{
for (FKBFLSwatchInformation Swatch : SwatchInformations)
{
if(Swatch.mSwatch)
{
UFGFactoryCustomizationDescriptor_Swatch* SwatchDefauls = Swatch.mSwatch.GetDefaultObject();
if(SwatchDefauls)
{
uint8 ColourIndex = SwatchDefauls->ID;
SwatchDefauls->mBuildMenuPriority = (float)ColourIndex;
if(!FGGameState->mBuildingColorSlots_Data.IsValidIndex(ColourIndex))
{
FGGameState->mBuildingColorSlots_Data[ColourIndex] = Subsystem->mColorSlots_Data[ColourIndex];
FGGameState->SetupColorSlots_Data(Subsystem->mColorSlots_Data);
UE_LOG(CustomizerSubsystem, Log, TEXT("write color again to gamestate: %d / %d"), FGGameState->mBuildingColorSlots_Data.Num(), Subsystem->mColorSlots_Data.Num());
}
}
}
}
}
UE_LOG(CustomizerSubsystem, Error, TEXT("Cannot load AFGBuildableSubsystem for Swatches"));
return false;
}
void UKBFLCustomizerSubsystem::RegisterSwatchGroups(TMap<TSubclassOf<UFGSwatchGroup>, TSubclassOf<UFGFactoryCustomizationDescriptor_Swatch>> Map)
bool UKBFLCustomizerSubsystem::RegisterSwatchGroups(TMap<TSubclassOf<UFGSwatchGroup>, TSubclassOf<UFGFactoryCustomizationDescriptor_Swatch>> Map)
{
for (TTuple<TSubclassOf<UFGSwatchGroup>, TSubclassOf<UFGFactoryCustomizationDescriptor_Swatch>> Group : Map)
{
if(Group.Key && Group.Value)
SetDefaultToSwatchGroup(Group.Key, Group.Value);
if(!SetDefaultToSwatchGroup(Group.Key, Group.Value))
return false;
}
return true;
}
void UKBFLCustomizerSubsystem::CDOMaterials(TArray<FKBFLMaterialDescriptorInformation> CDOInformation)
......@@ -205,19 +240,28 @@ void UKBFLCustomizerSubsystem::BeginForModule(UWorldModule* Module)
{
if(!Gathered)
{
UE_LOG(CustomizerSubsystem, Log, TEXT("CustomizerSubsystem > RegisterCollectionsInSubsystem"));
GatherDefaultCollections();
UE_LOG(CustomizerSubsystem, Log, TEXT("RegisterCollectionsInSubsystem"));
Gathered = GatherDefaultCollections();
}
RegisterSwatchesInSubsystem(IKBFLCustomizerInterface::Execute_GetSwatchDescriptionInformation(Module));
RegisterSwatchGroups(IKBFLCustomizerInterface::Execute_GetSwatchGroups(Module));
CDOMaterials(IKBFLCustomizerInterface::Execute_GetMaterialInformation(Module));
if(Gathered)
{
RegisterSwatchGroups(IKBFLCustomizerInterface::Execute_GetSwatchGroups(Module));
CDOMaterials(IKBFLCustomizerInterface::Execute_GetMaterialInformation(Module));
mCalled.AddUnique(Module);
mCalled.AddUnique(Module);
}
else
{
const FTimerDelegate RespawnDelegate = FTimerDelegate::CreateUObject( this, &UKBFLCustomizerSubsystem::BeginForModule, Module );
GetWorld()->GetTimerManager().SetTimerForNextTick(RespawnDelegate);
UE_LOG(CustomizerSubsystem, Log, TEXT("Gather was invalid Retry next tick!"));
}
}
}
void UKBFLCustomizerSubsystem::GatherDefaultCollections()
bool UKBFLCustomizerSubsystem::GatherDefaultCollections()
{
AFGBuildableSubsystem* Subsystem = AFGBuildableSubsystem::Get(this);
......@@ -235,11 +279,11 @@ void UKBFLCustomizerSubsystem::GatherDefaultCollections()
mDefaultSkinCollection = CustomizationClass;
}
Gathered = true;
return;
return true;
}
UE_LOG(CustomizerSubsystem, Error, TEXT("Cannot load AFGBuildableSubsystem for Collections"));
return false;
}
void UKBFLCustomizerSubsystem::GatherInterfaces()
......
......@@ -19,9 +19,12 @@
*
*/
UCLASS()
class KBFL_API UKBFLCustomizerSubsystem : public UWorldSubsystem
class KBFL_API UKBFLCustomizerSubsystem : public UWorldSubsystem, public FTickableGameObject
{
GENERATED_BODY()
virtual void Tick(float DeltaTime) override;
virtual TStatId GetStatId() const override;
/** Implement this for initialization of instances of the system */
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
......@@ -31,10 +34,10 @@ public:
void OnWorldBeginPlay();
void OnActorsInitialized(const UWorld::FActorsInitializedParams&);
void GatherDefaultCollections();
bool GatherDefaultCollections();
void GatherInterfaces();
void RegisterSwatchesInSubsystem(TArray<FKBFLSwatchInformation> SwatchInformations);
void RegisterSwatchGroups(TMap<TSubclassOf<UFGSwatchGroup>, TSubclassOf<UFGFactoryCustomizationDescriptor_Swatch>> Map);
bool RegisterSwatchesInSubsystem(TArray<FKBFLSwatchInformation> SwatchInformations);
bool RegisterSwatchGroups(TMap<TSubclassOf<UFGSwatchGroup>, TSubclassOf<UFGFactoryCustomizationDescriptor_Swatch>> Map);
void CDOMaterials(TArray<FKBFLMaterialDescriptorInformation> CDOInformation);
UFUNCTION(BlueprintCallable)
......@@ -56,10 +59,10 @@ public:
UFUNCTION(BlueprintPure, Category="KMods|Customizer Subsystem")
FORCEINLINE TMap<uint8, TSubclassOf<UFGFactoryCustomizationDescriptor_Swatch>> GetSwatchMap() const {return mSwatchIDMap;}
private:
bool Initialized = false;
bool Gathered = false;
private:
UPROPERTY()
TArray<UWorldModule*> mCalled;
......
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