Make item counts private

This commit is contained in:
Matt Nadareski
2025-01-29 20:49:24 -05:00
parent dd243a2bbd
commit 1571c8291b
3 changed files with 25 additions and 25 deletions

View File

@@ -13,6 +13,11 @@ namespace SabreTools.DatFiles
{
#region Private instance variables
/// <summary>
/// Number of items for each item type
/// </summary>
private readonly Dictionary<ItemType, long> _itemCounts = [];
/// <summary>
/// Lock for statistics calculation
/// </summary>
@@ -27,11 +32,6 @@ namespace SabreTools.DatFiles
/// </summary>
public long TotalCount { get; private set; } = 0;
/// <summary>
/// Number of items for each item type
/// </summary>
public Dictionary<ItemType, long> ItemCounts { get; } = [];
/// <summary>
/// Number of machines
/// </summary>
@@ -173,7 +173,7 @@ namespace SabreTools.DatFiles
TotalCount += stats.TotalCount;
// Loop through and add stats for all items
foreach (var itemCountKvp in stats.ItemCounts)
foreach (var itemCountKvp in stats._itemCounts)
{
AddItemCount(itemCountKvp.Key, itemCountKvp.Value);
}
@@ -220,12 +220,12 @@ namespace SabreTools.DatFiles
/// <returns>The number of items of that type, if it exists</returns>
public long GetItemCount(ItemType itemType)
{
lock (ItemCounts)
lock (_itemCounts)
{
if (!ItemCounts.ContainsKey(itemType))
if (!_itemCounts.ContainsKey(itemType))
return 0;
return ItemCounts[itemType];
return _itemCounts[itemType];
}
}
@@ -270,14 +270,14 @@ namespace SabreTools.DatFiles
/// <param name="interval">Amount to increment by, defaults to 1</param>
private void AddItemCount(ItemType itemType, long interval = 1)
{
lock (ItemCounts)
lock (_itemCounts)
{
if (!ItemCounts.ContainsKey(itemType))
ItemCounts[itemType] = 0;
if (!_itemCounts.ContainsKey(itemType))
_itemCounts[itemType] = 0;
ItemCounts[itemType] += interval;
if (ItemCounts[itemType] < 0)
ItemCounts[itemType] = 0;
_itemCounts[itemType] += interval;
if (_itemCounts[itemType] < 0)
_itemCounts[itemType] = 0;
}
}
@@ -372,7 +372,7 @@ namespace SabreTools.DatFiles
public void ResetStatistics()
{
TotalCount = 0;
ItemCounts.Clear();
_itemCounts.Clear();
GameCount = 0;
TotalSize = 0;
HashCounts.Clear();
@@ -405,14 +405,14 @@ namespace SabreTools.DatFiles
/// <param name="interval">Amount to increment by, defaults to 1</param>
private void RemoveItemCount(ItemType itemType, long interval = 1)
{
lock (ItemCounts)
lock (_itemCounts)
{
if (!ItemCounts.ContainsKey(itemType))
if (!_itemCounts.ContainsKey(itemType))
return;
ItemCounts[itemType] -= interval;
if (ItemCounts[itemType] < 0)
ItemCounts[itemType] = 0;
_itemCounts[itemType] -= interval;
if (_itemCounts[itemType] < 0)
_itemCounts[itemType] = 0;
}
}