mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Added ItemDefinition.SetProperty
This commit is contained in:
parent
2e9c077535
commit
cda59960b2
@ -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<string, string> customProperties;
|
||||
|
||||
internal Definition( SteamNative.SteamInventory i, int id )
|
||||
{
|
||||
inventory = i;
|
||||
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 )
|
||||
@ -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;
|
||||
|
||||
|
@ -100,10 +100,7 @@ public void Refresh()
|
||||
/// </summary>
|
||||
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()
|
||||
/// </summary>
|
||||
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 )
|
||||
/// <summary>
|
||||
/// You really need me to explain what this does?
|
||||
/// Use your brains.
|
||||
/// </summary>
|
||||
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 )
|
||||
|
Loading…
Reference in New Issue
Block a user