(Feat) Add Cooking and Workbench

This commit is contained in:
2026-08-01 00:03:53 +02:00
parent 3f3ae1f5fa
commit d50ef564ba
360 changed files with 5316 additions and 67 deletions
@@ -19,8 +19,8 @@ void UCraftingComponent::InitializeComponent()
{
Super::InitializeComponent();
// Les mains sont toujours disponibles. Les postes s'ajoutent par-dessus.
AvailableStations.Add(ECraftingStation::Hands);
// Les mains sont toujours disponibles, et rien ne peut les retirer.
StationRefCounts.Add(ECraftingStation::Hands, 1);
if (const AActor* Owner = GetOwner())
{
@@ -40,6 +40,12 @@ void UCraftingComponent::InitializeComponent()
}
}
bool UCraftingComponent::HasStation(ECraftingStation Station) const
{
const int32* Count = StationRefCounts.Find(Station);
return Count && *Count > 0;
}
void UCraftingComponent::AddAvailableStation(ECraftingStation Station)
{
if (Station == ECraftingStation::Count)
@@ -47,12 +53,13 @@ void UCraftingComponent::AddAvailableStation(ECraftingStation Station)
return;
}
bool bAlreadyThere = false;
AvailableStations.Add(Station, &bAlreadyThere);
int32& Count = StationRefCounts.FindOrAdd(Station);
++Count;
// On ne diffuse que sur un vrai changement : deux volumes d'etabli qui se
// chevauchent rafraichiraient l'interface deux fois pour rien.
if (!bAlreadyThere)
// On ne diffuse que sur la transition 0 -> 1. Entrer dans le rayon d'un
// deuxieme etabli ne change rien de visible, inutile de reconstruire la
// grille de recettes pour ca.
if (Count == 1)
{
OnAvailableStationsChanged.Broadcast();
}
@@ -67,8 +74,17 @@ void UCraftingComponent::RemoveAvailableStation(ECraftingStation Station)
return;
}
if (AvailableStations.Remove(Station) > 0)
int32* Count = StationRefCounts.Find(Station);
if (!Count || *Count <= 0)
{
return;
}
--(*Count);
if (*Count <= 0)
{
StationRefCounts.Remove(Station);
OnAvailableStationsChanged.Broadcast();
}
}
@@ -94,7 +110,7 @@ void UCraftingComponent::GatherRecipes(TArray<UCraftingRecipeDataAsset*>& OutRec
continue;
}
if (!AvailableStations.Contains(Recipe->RequiredStation))
if (!HasStation(Recipe->RequiredStation))
{
continue;
}
@@ -130,7 +146,7 @@ bool UCraftingComponent::CanCraft(const UCraftingRecipeDataAsset* Recipe, ECraft
return false;
}
if (!AvailableStations.Contains(Recipe->RequiredStation))
if (!HasStation(Recipe->RequiredStation))
{
OutReason = ECraftFailureReason::StationUnavailable;
return false;