Renamed TryFillContainerMapWithItem and changed output to better follow c# conventions
This commit is contained in:
@@ -84,16 +84,20 @@ public static class ContainerExtensions
|
||||
/// <param name="itemXWidth">Items width</param>
|
||||
/// <param name="itemYHeight">Items height</param>
|
||||
/// <param name="isRotated">is item rotated</param>
|
||||
/// <returns>bool = true when successful, string = error message if failed</returns>
|
||||
public static (bool, string) FillContainerMapWithItem(
|
||||
/// <param name="errorMessage">Error message if failed</param>
|
||||
/// <returns>bool = true when successful</returns>
|
||||
public static bool TryFillContainerMapWithItem(
|
||||
this int[,] container2D,
|
||||
int columnStartPositionX,
|
||||
int rowStartPositionY,
|
||||
int? itemXWidth,
|
||||
int? itemYHeight,
|
||||
bool isRotated
|
||||
bool isRotated,
|
||||
out string errorMessage
|
||||
)
|
||||
{
|
||||
errorMessage = string.Empty;
|
||||
|
||||
var containerY = container2D.GetLength(0); // rows
|
||||
var containerX = container2D.GetLength(1); // columns
|
||||
|
||||
@@ -109,7 +113,7 @@ public static class ContainerExtensions
|
||||
{
|
||||
container2D[rowStartPositionY, columnStartPositionX] = 1;
|
||||
|
||||
return (true, string.Empty);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Loop over rows and columns and flag each as taken by item
|
||||
@@ -124,15 +128,14 @@ public static class ContainerExtensions
|
||||
}
|
||||
else
|
||||
{
|
||||
return (
|
||||
false,
|
||||
$"Slot at: ({containerX}, {containerY}) is already filled. Cannot fit: {itemXWidth} by {itemYHeight} item"
|
||||
);
|
||||
errorMessage =
|
||||
$"Slot at: ({containerX}, {containerY}) is already filled. Cannot fit: {itemXWidth} by {itemYHeight} item";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (true, string.Empty);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -503,12 +503,13 @@ public class LocationLootGenerator(
|
||||
}
|
||||
|
||||
// Find somewhere for item inside container
|
||||
containerMap.FillContainerMapWithItem(
|
||||
containerMap.TryFillContainerMapWithItem(
|
||||
result.X.Value,
|
||||
result.Y.Value,
|
||||
chosenItemWithChildren.Width,
|
||||
chosenItemWithChildren.Height,
|
||||
result.Rotation.GetValueOrDefault(false)
|
||||
result.Rotation.GetValueOrDefault(false),
|
||||
out _
|
||||
);
|
||||
|
||||
// Update root item properties with result of position finder
|
||||
|
||||
@@ -240,12 +240,13 @@ public class InventoryHelper(
|
||||
{
|
||||
try
|
||||
{
|
||||
containerFS2D.FillContainerMapWithItem(
|
||||
containerFS2D.TryFillContainerMapWithItem(
|
||||
findSlotResult.X.Value,
|
||||
findSlotResult.Y.Value,
|
||||
sizeX,
|
||||
sizeY,
|
||||
findSlotResult.Rotation.Value
|
||||
findSlotResult.Rotation.Value,
|
||||
out _
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -286,12 +287,13 @@ public class InventoryHelper(
|
||||
{
|
||||
try
|
||||
{
|
||||
containerFS2D.FillContainerMapWithItem(
|
||||
containerFS2D.TryFillContainerMapWithItem(
|
||||
findSlotResult.X.Value,
|
||||
findSlotResult.Y.Value,
|
||||
sizeX,
|
||||
sizeY,
|
||||
findSlotResult.Rotation.Value
|
||||
findSlotResult.Rotation.Value,
|
||||
out _
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -346,12 +348,13 @@ public class InventoryHelper(
|
||||
{
|
||||
try
|
||||
{
|
||||
stashFS2D.FillContainerMapWithItem(
|
||||
stashFS2D.TryFillContainerMapWithItem(
|
||||
findSlotResult.X.Value,
|
||||
findSlotResult.Y.Value,
|
||||
sizeX,
|
||||
sizeY,
|
||||
findSlotResult.Rotation.Value
|
||||
findSlotResult.Rotation.Value,
|
||||
out _
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -383,12 +386,13 @@ public class InventoryHelper(
|
||||
|
||||
try
|
||||
{
|
||||
sortingTableFS2D.FillContainerMapWithItem(
|
||||
sortingTableFS2D.TryFillContainerMapWithItem(
|
||||
findSortingSlotResult.X.Value,
|
||||
findSortingSlotResult.Y.Value,
|
||||
sizeX,
|
||||
sizeY,
|
||||
findSortingSlotResult.Rotation.Value
|
||||
findSortingSlotResult.Rotation.Value,
|
||||
out _
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -122,12 +122,13 @@ public class AirdropService(
|
||||
lootResult.AddRange(itemAndChildren);
|
||||
|
||||
// Update container with item we just added
|
||||
containerMap.FillContainerMapWithItem(
|
||||
containerMap.TryFillContainerMapWithItem(
|
||||
result.X.Value,
|
||||
result.Y.Value,
|
||||
itemSize.Width,
|
||||
itemSize.Height,
|
||||
result.Rotation.GetValueOrDefault(false)
|
||||
result.Rotation.GetValueOrDefault(false),
|
||||
out _
|
||||
);
|
||||
|
||||
continue;
|
||||
|
||||
@@ -217,14 +217,15 @@ public class BotInventoryContainerService(ISptLogger<BotGeneratorHelper> logger,
|
||||
}
|
||||
|
||||
// Look for a slot in the grid to place item
|
||||
var result = gridDetails.GridMap.FillContainerMapWithItem(
|
||||
var result = gridDetails.GridMap.TryFillContainerMapWithItem(
|
||||
fixedLocation.X.Value,
|
||||
fixedLocation.Y.Value,
|
||||
itemWidth,
|
||||
itemHeight,
|
||||
fixedLocation.R == ItemRotation.Vertical
|
||||
fixedLocation.R == ItemRotation.Vertical,
|
||||
out _
|
||||
);
|
||||
if (result.Item1)
|
||||
if (result)
|
||||
{
|
||||
// It Fits!
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ public partial class ContainerExtensionsTests
|
||||
var destinationPosY = 0;
|
||||
var isRotated = false;
|
||||
|
||||
container.FillContainerMapWithItem(destinationPosX, destinationPosY, itemWidth, itemHeight, isRotated);
|
||||
container.TryFillContainerMapWithItem(destinationPosX, destinationPosY, itemWidth, itemHeight, isRotated, out _);
|
||||
|
||||
Assert.AreEqual(container[0, 0], 1);
|
||||
}
|
||||
@@ -243,7 +243,7 @@ public partial class ContainerExtensionsTests
|
||||
var destinationPosY = 0;
|
||||
var isRotated = false;
|
||||
|
||||
container.FillContainerMapWithItem(destinationPosX, destinationPosY, itemWidth, itemHeight, isRotated);
|
||||
container.TryFillContainerMapWithItem(destinationPosX, destinationPosY, itemWidth, itemHeight, isRotated, out _);
|
||||
|
||||
Assert.AreEqual(container[0, 0], 1);
|
||||
Assert.AreEqual(container[1, 0], 1);
|
||||
@@ -261,7 +261,7 @@ public partial class ContainerExtensionsTests
|
||||
var destinationPosY = 0;
|
||||
var isRotated = false;
|
||||
|
||||
container.FillContainerMapWithItem(destinationPosX, destinationPosY, itemWidth, itemHeight, isRotated);
|
||||
container.TryFillContainerMapWithItem(destinationPosX, destinationPosY, itemWidth, itemHeight, isRotated, out _);
|
||||
|
||||
Assert.AreEqual(container[0, 0], 1);
|
||||
Assert.AreEqual(container[1, 1], 1);
|
||||
@@ -279,7 +279,7 @@ public partial class ContainerExtensionsTests
|
||||
var destinationPosY = 0;
|
||||
var isRotated = true;
|
||||
|
||||
container.FillContainerMapWithItem(destinationPosX, destinationPosY, itemWidth, itemHeight, isRotated);
|
||||
container.TryFillContainerMapWithItem(destinationPosX, destinationPosY, itemWidth, itemHeight, isRotated, out _);
|
||||
|
||||
Assert.AreEqual(container[0, 0], 1);
|
||||
Assert.AreEqual(container[0, 1], 1);
|
||||
@@ -298,7 +298,7 @@ public partial class ContainerExtensionsTests
|
||||
var destinationPosY = 1;
|
||||
var isRotated = true;
|
||||
|
||||
container.FillContainerMapWithItem(destinationPosX, destinationPosY, itemWidth, itemHeight, isRotated);
|
||||
container.TryFillContainerMapWithItem(destinationPosX, destinationPosY, itemWidth, itemHeight, isRotated, out _);
|
||||
|
||||
Assert.AreEqual(container[1, 0], 1);
|
||||
Assert.AreEqual(container[1, 1], 1);
|
||||
|
||||
Reference in New Issue
Block a user