From 0041898dec103232ba767aea2565ada806b64936 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 19 Mar 2024 14:05:53 -0400 Subject: [PATCH] Return both indicies and items for some methods --- SabreTools.DatFiles/ItemDictionaryDB.cs | 33 ++++++++++++++----------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/SabreTools.DatFiles/ItemDictionaryDB.cs b/SabreTools.DatFiles/ItemDictionaryDB.cs index ecf0c465..f1c1770f 100644 --- a/SabreTools.DatFiles/ItemDictionaryDB.cs +++ b/SabreTools.DatFiles/ItemDictionaryDB.cs @@ -233,7 +233,12 @@ namespace SabreTools.DatFiles /// /// Get all bucket keys /// - public string[] GetBucketKeys() => [.. _buckets.Keys]; + public string[] GetBucketKeys() + { + List keys = [.. _buckets.Keys]; + keys.Sort(new NaturalComparer()); + return keys.ToArray(); + } /// /// Get an item based on the index @@ -258,54 +263,54 @@ namespace SabreTools.DatFiles } /// - /// Get the machine associated with an item index + /// Get the index and machine associated with an item index /// - public Machine? GetMachineForItem(long itemIndex) + public (long, Machine?) GetMachineForItem(long itemIndex) { if (!_itemToMachineMapping.ContainsKey(itemIndex)) - return null; + return (-1, null); long machineIndex = _itemToMachineMapping[itemIndex]; if (!_machines.ContainsKey(machineIndex)) - return null; + return (-1, null); - return _machines[machineIndex]; + return (machineIndex, _machines[machineIndex]); } /// - /// Get the items associated with a bucket name + /// Get the indices and items associated with a bucket name /// - public DatItem[]? GetDatItemsForBucket(string bucketName, bool filter = false) + public (long, DatItem)[]? GetDatItemsForBucket(string bucketName, bool filter = false) { if (!_buckets.ContainsKey(bucketName)) return null; var itemIds = _buckets[bucketName]; - var datItems = new List(); + var datItems = new List<(long, DatItem)>(); foreach (long itemId in itemIds) { if (_items.ContainsKey(itemId) && (!filter || _items[itemId].GetBoolFieldValue(DatItem.RemoveKey) != true)) - datItems.Add(_items[itemId]); + datItems.Add((itemId, _items[itemId])); } return [.. datItems]; } /// - /// Get the items associated with a machine index + /// Get the indices and items associated with a machine index /// - public DatItem[]? GetDatItemsForMachine(long machineIndex, bool filter = false) + public (long, DatItem)[]? GetDatItemsForMachine(long machineIndex, bool filter = false) { var itemIds = _itemToMachineMapping .Where(mapping => mapping.Value == machineIndex) .Select(mapping => mapping.Key); - var datItems = new List(); + var datItems = new List<(long, DatItem)>(); foreach (long itemId in itemIds) { if (_items.ContainsKey(itemId) && (!filter || _items[itemId].GetBoolFieldValue(DatItem.RemoveKey) != true)) - datItems.Add(_items[itemId]); + datItems.Add((itemId, _items[itemId])); } return [.. datItems];