From 96511dcc64824eceea5a8c9dabe368223b03f3ef Mon Sep 17 00:00:00 2001 From: Rohan Singh Date: Mon, 3 Dec 2018 08:17:55 -0500 Subject: [PATCH] Make Inventory.OnUpdate an event, FormatPrice can be passed LocalPrice without needing to multiply it --- Facepunch.Steamworks.Test/Client/InventoryTest.cs | 2 +- Facepunch.Steamworks/Interfaces/Inventory.cs | 3 ++- Facepunch.Steamworks/Utility.cs | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Facepunch.Steamworks.Test/Client/InventoryTest.cs b/Facepunch.Steamworks.Test/Client/InventoryTest.cs index 837b1b8..0886996 100644 --- a/Facepunch.Steamworks.Test/Client/InventoryTest.cs +++ b/Facepunch.Steamworks.Test/Client/InventoryTest.cs @@ -107,7 +107,7 @@ public void InventoryItemList() bool CallbackCalled = false; // OnUpdate hsould be called when we receive a list of our items - client.Inventory.OnUpdate = () => { CallbackCalled = true; }; + client.Inventory.OnUpdate += () => { CallbackCalled = true; }; // tell steam to download the items client.Inventory.Refresh(); diff --git a/Facepunch.Steamworks/Interfaces/Inventory.cs b/Facepunch.Steamworks/Interfaces/Inventory.cs index d3b34e5..a6d00bf 100644 --- a/Facepunch.Steamworks/Interfaces/Inventory.cs +++ b/Facepunch.Steamworks/Interfaces/Inventory.cs @@ -14,7 +14,7 @@ public partial class Inventory : IDisposable /// Called when the local client's items are first retrieved, and when they change. /// Obviously not called on the server. /// - public Action OnUpdate; + public event Action OnUpdate; /// /// A list of items owned by this user. You should call Refresh() before trying to access this, @@ -466,6 +466,7 @@ public void UpdatePrices() Definitions[i].UpdatePrice(); } + OnUpdate?.Invoke(); }); } } diff --git a/Facepunch.Steamworks/Utility.cs b/Facepunch.Steamworks/Utility.cs index cdf1e8a..7ddd9b3 100644 --- a/Facepunch.Steamworks/Utility.cs +++ b/Facepunch.Steamworks/Utility.cs @@ -60,9 +60,14 @@ public static uint FromDateTime( DateTime dt ) } - public static string FormatPrice(string currency, ulong price) + internal static string FormatPrice(string currency, ulong price) { - var decimaled = (price / 100.0).ToString("0.00"); + return FormatPrice(currency, price / 100.0); + } + + public static string FormatPrice(string currency, double price) + { + var decimaled = price.ToString("0.00"); switch (currency) {