Commit e99bf883 authored by Kyrium's avatar Kyrium
Browse files

Merge branch 'dev' into 'main'

Update 1.9.5

See merge request !3
parents 33bf719c 727a34f5
......@@ -118,6 +118,7 @@ BlueprintReadWrite=(Class="AFGTutorialIntroManager", Property="mHasCompletedIntr
BlueprintReadWrite=(Class="AFGTutorialIntroManager", Property="mHasCompletedIntroTutorial")
BlueprintReadWrite=(Class="AFGGameState", Property="mUnlockCustomizerSchematic")
BlueprintReadWrite=(Class="UFGPoolSettings", Property="PoolEntry")
Friend=(Class="UFGItemDescriptor", FriendClass="UKBFL_Items")
Friend=(Class="UFGRecipe", FriendClass="UKBFL_Recipes")
......@@ -187,4 +188,6 @@ Friend=(Class="AFGBuildableResourceExtractorBase", FriendClass="UKBFLResourceNod
Friend=(Class="AFGBuildableFrackingActivator", FriendClass="FKBFLModule")
Friend=(Class="AFGBuildableFrackingExtractor", FriendClass="FKBFLModule")
Friend=(Class="UWorldModuleManager", FriendClass="FKBFLModule")
\ No newline at end of file
Friend=(Class="UWorldModuleManager", FriendClass="FKBFLModule")
Friend=(Class="UFGPoolSettings", FriendClass="UKBFLWorldModule")
\ No newline at end of file
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.6.0",
"SemVersion": "1.6.0",
"VersionName": "1.9.5",
"SemVersion": "1.9.5",
"FriendlyName": "KBFL",
"Description": "Lib for Kyris Mods",
"Category": "Modding",
......
......@@ -268,4 +268,60 @@ void UKBFLCppInventoryHelper::PullBelt(UFGInventoryComponent* Inventory, int Inv
{
PullBelt(Inventory, InventoryIndex, dt, Item, BeltInput);
}
}
void UKBFLCppInventoryHelper::PullBeltChildClass(UFGInventoryComponent* Inventory, int InventoryIndex, float dt,
UClass* AllowedItemClass, UFGFactoryConnectionComponent* BeltInput)
{
if(BeltInput)
{
if(BeltInput->IsConnected())
{
TArray<FInventoryItem> Items;
if(BeltInput->Factory_PeekOutput(Items))
for (FInventoryItem InventoryItem : Items)
{
if(InventoryItem.ItemClass)
{
if(InventoryItem.ItemClass->IsChildOf(AllowedItemClass) && CanStoreItem(Inventory, InventoryIndex, InventoryItem.ItemClass, 1))
{
FInventoryItem Item;
float offset;
if (BeltInput->Factory_GrabOutput(Item, offset, InventoryItem.ItemClass))
{
StoreItemAmountInInventory(Inventory, InventoryIndex, InventoryItem.ItemClass);
}
}
}
}
}
}
}
void UKBFLCppInventoryHelper::PullBeltChildClass(UFGInventoryComponent* Inventory, float dt, UClass* AllowedItemClass,
UFGFactoryConnectionComponent* BeltInput)
{
if(BeltInput)
{
if(BeltInput->IsConnected())
{
TArray<FInventoryItem> Items;
if(BeltInput->Factory_PeekOutput(Items))
for (FInventoryItem InventoryItem : Items)
{
if(InventoryItem.ItemClass)
{
if(InventoryItem.ItemClass->IsChildOf(AllowedItemClass) && Inventory->HasEnoughSpaceForItem(InventoryItem))
{
FInventoryItem Item;
float offset;
if (BeltInput->Factory_GrabOutput(Item, offset, InventoryItem.ItemClass))
{
AddItemsInInventory(Inventory, InventoryItem.ItemClass);
}
}
}
}
}
}
}
\ No newline at end of file
#include "EnumStrucs/FunctionalStrucs.h"
......@@ -3,6 +3,7 @@
#include "KBFLWorldModule.h"
#include "FGBackgroundThread.h"
#include "AssetRegistry/IAssetRegistry.h"
#include "BFL/KBFL_Asset.h"
#include "Engine/AssetManager.h"
......@@ -77,6 +78,10 @@ TArray<FKBFLMaterialDescriptorInformation> UKBFLWorldModule::GetMaterialInformat
void UKBFLWorldModule::DispatchLifecycleEvent(ELifecyclePhase Phase)
{
if (Phase == ELifecyclePhase::CONSTRUCTION) {
RegisterPoolSettings();
}
if (Phase == ELifecyclePhase::INITIALIZATION) {
RegisterKBFLLogicContent();
}
......@@ -145,6 +150,30 @@ void UKBFLWorldModule::RegisterKBFLLogicContent()
}
}
void UKBFLWorldModule::RegisterPoolSettings()
{
if(mAddPoolEntry && mPoolEntryToAdd.Num() > 0)
{
if(UFGPoolSettings* Settings = GetMutableDefault<UFGPoolSettings>())
for (FFGPoolType PoolEntry : mPoolEntryToAdd)
if(!IsPoolEntryThere(Settings->PoolEntry, PoolEntry) && PoolEntry.mProxyComponent)
{
UE_LOG(KBFLWorldModuleLog, Warning, TEXT("Register PoolEntry (%s) from mod (%s)"), *PoolEntry.mProxyComponent->GetName(), *GetOwnerModReference().ToString());
Settings->PoolEntry.Add(PoolEntry);
}
}
}
bool UKBFLWorldModule::IsPoolEntryThere(TArray<FFGPoolType> Source, FFGPoolType CheckStruc)
{
for (FFGPoolType PoolType : Source)
{
if(PoolType.mProxyComponent == CheckStruc.mProxyComponent)
return true;
}
return false;
}
void UKBFLWorldModule::FindAllCDOs()
{
if(!bScanForCDOsDone && mUseAssetCDOSearch && mAssetCdoFinder.Num() > 0)
......
......@@ -42,4 +42,8 @@ class KBFL_API UKBFLCppInventoryHelper : public UBlueprintFunctionLibrary
static void PullPipe(UFGInventoryComponent* Inventory, int InventoryIndex, float dt, TArray<TSubclassOf<UFGItemDescriptor>> AllowedItem, UFGPipeConnectionFactory* PipeInputComp, int PullAmount = 200);
static void PullBelt(UFGInventoryComponent* Inventory, int InventoryIndex, float dt, TSubclassOf<UFGItemDescriptor> AllowedItem, UFGFactoryConnectionComponent* BeltInput);
static void PullBelt(UFGInventoryComponent* Inventory, int InventoryIndex, float dt, TArray<TSubclassOf<UFGItemDescriptor>> AllowedItem, UFGFactoryConnectionComponent* BeltInput);
/** Pull Items with ChildClass Ref */
static void PullBeltChildClass(UFGInventoryComponent* Inventory, int InventoryIndex, float dt, UClass* AllowedItemClass, UFGFactoryConnectionComponent* BeltInput);
static void PullBeltChildClass(UFGInventoryComponent* Inventory, float dt, UClass* AllowedItemClass, UFGFactoryConnectionComponent* BeltInput);
};
\ No newline at end of file
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
//#include "FunctionalStrucs.generated.h"
template<typename T>
USTRUCT()
struct FSortedComponentDistanceArray {
FSortedComponentDistanceArray() {};
FSortedComponentDistanceArray(T* RefObject)
{
SetSortRef(RefObject);
};
/** Set our ref for sorting */
void SetSortRef(T* Object)
{
if(Object)
mSortRef = Object;
}
/** Sorting Functions */
void Sort()
{
if(mSortRef.IsValid())
{
mObjects = SortByTempRef(mSortRef);
}
}
/** Getter Functions */
uint64 Num() const
{
return mObjects.Num();
}
TArray<TWeakObjectPtr<T>> GetAllConst() const
{
return mObjects;
}
void SortArrayByLocation(FVector LocationRef)
{
mObjects = SortByLocationRef(LocationRef);
}
/** Note: Get the last sort state! */
TArray<TWeakObjectPtr<T>> GetAllObjects(const bool Sorted = true)
{
if(Sorted)
Sort();
return mObjects;
}
TArray<TWeakObjectPtr<T>> GetSortedByRef(T* Object) const
{
if(Object)
return SortByTempRef(Object);
return mObjects;
}
TWeakObjectPtr<T> GetClosedObject()
{
return GetClosedObjectWithRef(mSortRef.Get());
}
TWeakObjectPtr<T> GetClosedObjectWithRef(T* Object)
{
if(!Object)
{
if(mObjects.Num() > 0)
return mObjects[0];
}
if(Object)
{
TArray<TWeakObjectPtr<T>> Sorted = SortByTempRef(Object);
if(Sorted.Num() > 0)
{
return Sorted[0];
}
}
return {};
}
TWeakObjectPtr<T> GetClosedObjectWithRefAndDistance(T* Object, float Distance = 500.f)
{
TWeakObjectPtr<T> ClosedObject = GetClosedObjectWithRef(Object);
if(ClosedObject.IsValid() && mSortRef.IsValid())
{
T* TargetObject = ClosedObject.Get();
if(FVector::Distance(TargetObject->GetComponentLocation(), Object->GetComponentLocation()) <= Distance)
{
return ClosedObject;
}
}
if(!Object)
{
if(mObjects.Num() > 0)
{
if(FVector::Distance(mObjects[0]->GetComponentLocation(), Object->GetComponentLocation()) <= Distance)
{
return mObjects[0];
}
}
}
return {};
}
TWeakObjectPtr<T> GetClosedObjectWithLocRefAndDistance(FVector Location, float Distance = 500.f)
{
TWeakObjectPtr<T> ClosedObject = GetClosedObject();
if(ClosedObject.IsValid())
{
T* TargetObject = ClosedObject.Get();
if(FVector::Distance(TargetObject->GetComponentLocation(), Location) <= Distance)
{
return ClosedObject;
}
}
if(!ClosedObject.IsValid())
{
if(mObjects.Num() > 0)
{
if(FVector::Distance(mObjects[0]->GetComponentLocation(), Location) <= Distance)
{
return mObjects[0];
}
}
}
return {};
}
TWeakObjectPtr<T> GetClosedObjectWithDistance(float Distance = 500.f)
{
TWeakObjectPtr<T> ClosedObject = GetClosedObject();
if(ClosedObject.IsValid() && mSortRef.IsValid())
{
T* RefObject = mSortRef.Get();
T* Object = ClosedObject.Get();
if(FVector::Distance(RefObject->GetComponentLocation(), Object->GetComponentLocation()) <= Distance)
{
return ClosedObject;
}
}
return {};
}
uint64 AddObject(T* Object)
{
if(Object)
{
uint64 Return = mObjects.AddUnique(Object);
Sort();
return Return;
}
return -1;
}
void RemoveObject(T* Object)
{
if(Object)
{
if(mObjects.Contains(Object))
mObjects.Remove(Object);
}
}
void Empty()
{
mObjects.Empty();
}
private:
/** Sort the Array */
TArray<TWeakObjectPtr<T>> SortByTempRef(TWeakObjectPtr<T> Ref) const
{
TArray<TWeakObjectPtr<T>> SortArray = mObjects;
if(Ref.IsValid() && SortArray.Num() > 1)
{
SortArray.Sort([Ref](const TWeakObjectPtr<T>& A, const TWeakObjectPtr<T>& B)
{
float ADistance = 0.0f;
float BDistance = 0.0f;
if(A.IsValid() && B.IsValid() && Ref.IsValid())
{
ADistance = FVector::Distance(A->GetComponentLocation(), Ref->GetComponentLocation());
BDistance = FVector::Distance(B->GetComponentLocation(), Ref->GetComponentLocation());
}
return ADistance < BDistance;
});
}
return SortArray;
}
/** Sort the Array by Location*/
TArray<TWeakObjectPtr<T>> SortByLocationRef(FVector LocationRef) const
{
TArray<TWeakObjectPtr<T>> SortArray = mObjects;
if(SortArray.Num() > 1)
{
SortArray.Sort([LocationRef](const TWeakObjectPtr<T>& A, const TWeakObjectPtr<T>& B)
{
float ADistance = 0.0f;
float BDistance = 0.0f;
if(A.IsValid() && B.IsValid())
{
ADistance = FVector::Distance(A->GetComponentLocation(), LocationRef);
BDistance = FVector::Distance(B->GetComponentLocation(), LocationRef);
}
return ADistance < BDistance;
});
}
return SortArray;
}
TArray<TWeakObjectPtr<T>> mObjects;
TWeakObjectPtr<T> mSortRef;
};
template<typename T>
USTRUCT()
struct FSortedActorDistanceArray {
FSortedActorDistanceArray() {};
FSortedActorDistanceArray(T* RefObject)
{
SetSortRef(RefObject);
};
/** Set our ref for sorting */
void SetSortRef(T* Object)
{
if(Object)
mSortRef = Object;
}
/** Sorting Functions */
void Sort()
{
if(mSortRef.IsValid())
{
mObjects = SortByTempRef(mSortRef);
}
}
/** Getter Functions */
uint64 Num() const
{
return mObjects.Num();
}
TArray<TWeakObjectPtr<T>> GetAllConst() const
{
return mObjects;
}
/** Note: Get the last sort state! */
TArray<TWeakObjectPtr<T>> GetAllObjects(const bool Sorted = true)
{
if(Sorted)
Sort();
return mObjects;
}
TArray<TWeakObjectPtr<T>> GetSortedByRef(T* Object) const
{
if(Object)
return SortByTempRef(Object);
}
TWeakObjectPtr<T> GetClosedObject()
{
return GetClosedObjectWithRef(mSortRef);
}
TWeakObjectPtr<T> GetClosedObjectWithRef(T* Object)
{
if(Object)
{
TArray<TWeakObjectPtr<T>> Sorted = SortByTempRef(Object);
if(Sorted.Num() > 0)
{
return Sorted[0];
}
}
return {};
}
TWeakObjectPtr<T> GetClosedObjectWithRefAndDistance(T* Object, float Distance = 500.f)
{
TWeakObjectPtr<T> ClosedObject = GetClosedObjectWithRef(Object);
if(ClosedObject.IsValid() && mSortRef.IsValid())
{
T* TargetObject = ClosedObject.Get();
if(Object->GetDistanceTo(TargetObject) <= Distance)
{
return ClosedObject;
}
}
return {};
}
TWeakObjectPtr<T> GetClosedObjectWithDistance(float Distance = 500.f)
{
TWeakObjectPtr<T> ClosedObject = GetClosedObject();
if(ClosedObject.IsValid() && mSortRef.IsValid())
{
T* RefObject = mSortRef.Get();
T* Object = ClosedObject.Get();
if(RefObject->GetDistanceTo(Object) <= Distance)
{
return ClosedObject;
}
}
return {};
}
void AddObject(T* Object)
{
if(Object)
{
if(Object)
mObjects.AddUnique(Object);
}
}
void RemoveObject(T* Object)
{
if(Object)
{
if(mObjects.Contains(Object))
mObjects.Remove(Object);
}
}
void Empty()
{
mObjects.Empty();
}
private:
/** Sort the Array */
TArray<TWeakObjectPtr<T>> SortByTempRef(TWeakObjectPtr<T> Ref) const
{
TArray<TWeakObjectPtr<T>> SortArray = mObjects;
if(Ref.IsValid())
{
SortArray.Sort([Ref](const TWeakObjectPtr<T>& A, const TWeakObjectPtr<T>& B)
{
float ADistance = A.Get()->GetDistanceTo(Ref.Get());
float BDistance = B.Get()->GetDistanceTo(Ref.Get());
return ADistance > BDistance;
});
}
return SortArray;
}
TArray<TWeakObjectPtr<T>> mObjects;
TWeakObjectPtr<T> mSortRef;
};
template<typename T>
USTRUCT()
struct FSortedComponentDistanceArrayV2 {
FSortedComponentDistanceArrayV2() {};
FSortedComponentDistanceArrayV2(FVector RefLocation)
{
SetSortRef(RefLocation);
};
/** Set our ref for sorting */
void SetSortRef(FVector RefLocation)
{
mSortRef = RefLocation;
}
/** Sorting Functions */
void Sort()
{
mObjects = SortByTempRef(mSortRef);
}
/** Getter Functions */
uint64 Num() const
{
return mObjects.Num();
}
TArray<TWeakObjectPtr<T>> GetAllConst() const
{
return mObjects;
}
void SortArrayByLocation(FVector LocationRef)
{
mObjects = SortByLocationRef(LocationRef);
}
/** Note: Get the last sort state! */
TArray<TWeakObjectPtr<T>> GetAllObjects(const bool Sorted = true)
{
if(Sorted)
Sort();
return mObjects;
}
TArray<TWeakObjectPtr<T>> GetSortedByRef(FVector RefLocation) const
{
return SortByTempRef(RefLocation);
}
TWeakObjectPtr<T> GetClosedObject()
{
return GetClosedObjectWithRef(mSortRef);
}
TWeakObjectPtr<T> GetClosedObjectWithRef(FVector RefLocation)
{
TArray<TWeakObjectPtr<T>> Sorted = SortByTempRef(RefLocation);
if(Sorted.Num() > 0)
{
return Sorted[0];
}
return nullptr;
}
TWeakObjectPtr<T> GetClosedObjectWithRefAndDistance(FVector RefLocation, float Distance = 500.f)
{
TWeakObjectPtr<T> ClosedObject = GetClosedObjectWithRef(RefLocation);
if(ClosedObject.IsValid())
{
T* TargetObject = ClosedObject.Get();
if(FVector::Distance(TargetObject->GetComponentLocation(), RefLocation) <= Distance)
{
return ClosedObject;
}
}
return nullptr;
}
TWeakObjectPtr<T> GetClosedObjectWithDistance(float Distance = 500.f)
{