From 37f619221314d274d37c99109646835fdc75e8d5 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Sat, 27 Apr 2019 21:52:30 +0100 Subject: [PATCH] LocalPriceFormatted --- Facepunch.Steamworks/SteamInventory.cs | 4 ++-- Facepunch.Steamworks/Structs/SteamItemDef.cs | 10 ++++++++-- Facepunch.Steamworks/Utility/Utility.cs | 7 +------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Facepunch.Steamworks/SteamInventory.cs b/Facepunch.Steamworks/SteamInventory.cs index ad69f20..d02d23f 100644 --- a/Facepunch.Steamworks/SteamInventory.cs +++ b/Facepunch.Steamworks/SteamInventory.cs @@ -37,16 +37,16 @@ namespace Steamworks public static event Action OnDefinitionsUpdated; public static async Task GetItemsWithPricesAsync() + public static string Currency { get; internal set; } { var priceRequest = await Internal.RequestPrices(); if ( !priceRequest.HasValue || priceRequest.Value.Result != Result.OK ) return null; - Console.WriteLine( $"Currency: {priceRequest?.Currency}" ); + Currency = priceRequest?.Currency; var num = Internal.GetNumItemsWithPrices(); - Console.WriteLine( $"num: {num}" ); if ( num <= 0 ) return null; diff --git a/Facepunch.Steamworks/Structs/SteamItemDef.cs b/Facepunch.Steamworks/Structs/SteamItemDef.cs index fd1fa8f..15c6f64 100644 --- a/Facepunch.Steamworks/Structs/SteamItemDef.cs +++ b/Facepunch.Steamworks/Structs/SteamItemDef.cs @@ -8,6 +8,11 @@ namespace Steamworks { internal SteamItemDef_t _id; + public SteamItemDef( int defId ) + { + _id = defId; + } + public int Id => _id.Value; /// @@ -146,6 +151,8 @@ namespace Steamworks } } + public string LocalPriceFormatted => Utility.FormatPrice( SteamInventory.Currency, LocalPrice / 100.0 ); + /// /// If the price has been discounted, LocalPrice will differ from LocalBasePrice /// (assumed, this isn't documented) @@ -164,7 +171,6 @@ namespace Steamworks } } - public int CurrentPrice; - public int BasePrice; + public string LocalBasePriceFormatted => Utility.FormatPrice( SteamInventory.Currency, LocalPrice / 100.0 ); } } \ No newline at end of file diff --git a/Facepunch.Steamworks/Utility/Utility.cs b/Facepunch.Steamworks/Utility/Utility.cs index 10c38eb..ec47daa 100644 --- a/Facepunch.Steamworks/Utility/Utility.cs +++ b/Facepunch.Steamworks/Utility/Utility.cs @@ -27,12 +27,7 @@ namespace Steamworks return new IPAddress( Swap( ipAddress ) ); } - internal static string FormatPrice(string currency, ulong price) - { - return FormatPrice(currency, price / 100.0); - } - - public static string FormatPrice(string currency, double price) + public static string FormatPrice(string currency, double price) { var decimaled = price.ToString("0.00");