From cda59960b271cf8fe825da69a8a783ba0b4677d3 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Thu, 27 Oct 2016 21:03:27 +0100 Subject: [PATCH] Added ItemDefinition.SetProperty --- .../Interfaces/Inventory.Definition.cs | 28 +++++++++++++++++-- Facepunch.Steamworks/Interfaces/Inventory.cs | 23 ++++++++------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Facepunch.Steamworks/Interfaces/Inventory.Definition.cs b/Facepunch.Steamworks/Interfaces/Inventory.Definition.cs index 731a135..fab14af 100644 --- a/Facepunch.Steamworks/Interfaces/Inventory.Definition.cs +++ b/Facepunch.Steamworks/Interfaces/Inventory.Definition.cs @@ -17,16 +17,37 @@ public class Definition { internal SteamNative.SteamInventory inventory; - public int Id; + public int Id { get; private set; } public string Name; public string Description; public DateTime Created; public DateTime Modified; - internal Definition( int id ) + private Dictionary customProperties; + + internal Definition( SteamNative.SteamInventory i, int id ) { + inventory = i; Id = id; + + SetupCommonProperties(); + } + + /// + /// If you're manually occupying the Definition (because maybe you're on a server + /// and want to hack around the fact that definitions aren't presented to you), + /// you can use this to set propertis. + /// + public void SetProperty( string name, string value ) + { + if ( customProperties == null ) + customProperties = new Dictionary(); + + if ( !customProperties.ContainsKey( name ) ) + customProperties.Add( name, value ); + else + customProperties[name] = value; } public T GetProperty( string name ) @@ -50,6 +71,9 @@ public string GetStringProperty( string name ) { string val = string.Empty; + if ( customProperties != null && customProperties.ContainsKey( name ) ) + return customProperties[name]; + if ( !inventory.GetItemDefinitionProperty( Id, name, out val ) ) return string.Empty; diff --git a/Facepunch.Steamworks/Interfaces/Inventory.cs b/Facepunch.Steamworks/Interfaces/Inventory.cs index 7cd44b5..6c17123 100644 --- a/Facepunch.Steamworks/Interfaces/Inventory.cs +++ b/Facepunch.Steamworks/Interfaces/Inventory.cs @@ -100,10 +100,7 @@ public void Refresh() /// public Definition CreateDefinition( int id ) { - return new Definition( id ) - { - inventory = inventory - }; + return new Definition( inventory, id ); } internal void FetchItemDefinitions() @@ -118,9 +115,7 @@ internal void FetchItemDefinitions() Definitions = ids.Select( x => { - var d = CreateDefinition( x ); - d.SetupCommonProperties(); - return d; + return CreateDefinition( x ); } ).ToArray(); } @@ -130,9 +125,13 @@ internal void FetchItemDefinitions() /// internal void Update() { - if ( Definitions == null && !IsServer ) + if ( Definitions == null ) + { FetchItemDefinitions(); + inventory.LoadItemDefinitions(); + } + UpdateLocalRequest(); } @@ -197,11 +196,15 @@ public static float PriceCategoryToFloat( string price ) return int.Parse( price ) / 100.0f; } - private Definition FindDefinition( int def ) + /// + /// You really need me to explain what this does? + /// Use your brains. + /// + public Definition FindDefinition( int DefinitionId ) { if ( Definitions == null ) return null; - return Definitions.FirstOrDefault( x => x.Id == def ); + return Definitions.FirstOrDefault( x => x.Id == DefinitionId ); } public unsafe Result Deserialize( byte[] data, int dataLength = -1 )