Added ItemDefinition.SetProperty

This commit is contained in:
Garry Newman 2016-10-27 21:03:27 +01:00
parent 2e9c077535
commit cda59960b2
2 changed files with 39 additions and 12 deletions

View File

@ -17,16 +17,37 @@ public class Definition
{ {
internal SteamNative.SteamInventory inventory; internal SteamNative.SteamInventory inventory;
public int Id; public int Id { get; private set; }
public string Name; public string Name;
public string Description; public string Description;
public DateTime Created; public DateTime Created;
public DateTime Modified; public DateTime Modified;
internal Definition( int id ) private Dictionary<string, string> customProperties;
internal Definition( SteamNative.SteamInventory i, int id )
{ {
inventory = i;
Id = id; Id = id;
SetupCommonProperties();
}
/// <summary>
/// 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.
/// </summary>
public void SetProperty( string name, string value )
{
if ( customProperties == null )
customProperties = new Dictionary<string, string>();
if ( !customProperties.ContainsKey( name ) )
customProperties.Add( name, value );
else
customProperties[name] = value;
} }
public T GetProperty<T>( string name ) public T GetProperty<T>( string name )
@ -50,6 +71,9 @@ public string GetStringProperty( string name )
{ {
string val = string.Empty; string val = string.Empty;
if ( customProperties != null && customProperties.ContainsKey( name ) )
return customProperties[name];
if ( !inventory.GetItemDefinitionProperty( Id, name, out val ) ) if ( !inventory.GetItemDefinitionProperty( Id, name, out val ) )
return string.Empty; return string.Empty;

View File

@ -100,10 +100,7 @@ public void Refresh()
/// </summary> /// </summary>
public Definition CreateDefinition( int id ) public Definition CreateDefinition( int id )
{ {
return new Definition( id ) return new Definition( inventory, id );
{
inventory = inventory
};
} }
internal void FetchItemDefinitions() internal void FetchItemDefinitions()
@ -118,9 +115,7 @@ internal void FetchItemDefinitions()
Definitions = ids.Select( x => Definitions = ids.Select( x =>
{ {
var d = CreateDefinition( x ); return CreateDefinition( x );
d.SetupCommonProperties();
return d;
} ).ToArray(); } ).ToArray();
} }
@ -130,9 +125,13 @@ internal void FetchItemDefinitions()
/// </summary> /// </summary>
internal void Update() internal void Update()
{ {
if ( Definitions == null && !IsServer ) if ( Definitions == null )
{
FetchItemDefinitions(); FetchItemDefinitions();
inventory.LoadItemDefinitions();
}
UpdateLocalRequest(); UpdateLocalRequest();
} }
@ -197,11 +196,15 @@ public static float PriceCategoryToFloat( string price )
return int.Parse( price ) / 100.0f; return int.Parse( price ) / 100.0f;
} }
private Definition FindDefinition( int def ) /// <summary>
/// You really need me to explain what this does?
/// Use your brains.
/// </summary>
public Definition FindDefinition( int DefinitionId )
{ {
if ( Definitions == null ) return null; 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 ) public unsafe Result Deserialize( byte[] data, int dataLength = -1 )