Add method to get items from a bucket

This commit is contained in:
Matt Nadareski
2024-03-13 19:41:10 -04:00
parent bbf8772ed3
commit 4f8a5c4b0b

View File

@@ -135,7 +135,7 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Get an item based on the index /// Get an item based on the index
/// </summary> /// </summary>
public DatItem? GetItemByIndex(long index) public DatItem? GetItem(long index)
{ {
if (!_items.ContainsKey(index)) if (!_items.ContainsKey(index))
return null; return null;
@@ -146,7 +146,7 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Get a machine based on the index /// Get a machine based on the index
/// </summary> /// </summary>
public Machine? GetMachineByIndex(long index) public Machine? GetMachine(long index)
{ {
if (!_machines.ContainsKey(index)) if (!_machines.ContainsKey(index))
return null; return null;
@@ -157,7 +157,7 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Get the machine associated with an item index /// Get the machine associated with an item index
/// </summary> /// </summary>
public Machine? GetMachineForItemByIndex(long itemIndex) public Machine? GetMachineForItem(long itemIndex)
{ {
if (!_itemToMachineMapping.ContainsKey(itemIndex)) if (!_itemToMachineMapping.ContainsKey(itemIndex))
return null; return null;
@@ -169,10 +169,30 @@ namespace SabreTools.DatFiles
return _machines[machineIndex]; return _machines[machineIndex];
} }
/// <summary>
/// Get the items associated with a bucket name
/// </summary>
public DatItem[]? GetDatItemsForBucket(string bucketName)
{
if (!_buckets.ContainsKey(bucketName))
return null;
var itemIds = _buckets[bucketName];
var datItems = new List<DatItem>();
foreach (long itemId in itemIds)
{
if (_items.ContainsKey(itemId))
datItems.Add(_items[itemId]);
}
return [.. datItems];
}
/// <summary> /// <summary>
/// Get the items associated with a machine index /// Get the items associated with a machine index
/// </summary> /// </summary>
public DatItem[]? GetDatItemsForMachineByIndex(long machineIndex) public DatItem[]? GetDatItemsForMachine(long machineIndex)
{ {
var itemIds = _itemToMachineMapping var itemIds = _itemToMachineMapping
.Where(mapping => mapping.Value == machineIndex) .Where(mapping => mapping.Value == machineIndex)
@@ -185,7 +205,7 @@ namespace SabreTools.DatFiles
datItems.Add(_items[itemId]); datItems.Add(_items[itemId]);
} }
return datItems.ToArray(); return [.. datItems];
} }
/// <summary> /// <summary>