mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-04-16 14:22:27 +03:00
KeyValue tags for workshop items / queries
This commit is contained in:
parent
538bed982a
commit
79b73ff576
@ -2,8 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
|
||||||
using SteamNative;
|
using SteamNative;
|
||||||
|
|
||||||
namespace Facepunch.Steamworks
|
namespace Facepunch.Steamworks
|
||||||
@ -19,6 +17,7 @@ namespace Facepunch.Steamworks
|
|||||||
public ulong OwnerId { get; private set; }
|
public ulong OwnerId { get; private set; }
|
||||||
public float Score { get; private set; }
|
public float Score { get; private set; }
|
||||||
public string[] Tags { get; private set; }
|
public string[] Tags { get; private set; }
|
||||||
|
public Dictionary<string, string[]> KeyValueTags { get; private set; }
|
||||||
public string Title { get; private set; }
|
public string Title { get; private set; }
|
||||||
public uint VotesDown { get; private set; }
|
public uint VotesDown { get; private set; }
|
||||||
public uint VotesUp { get; private set; }
|
public uint VotesUp { get; private set; }
|
||||||
@ -48,6 +47,34 @@ namespace Facepunch.Steamworks
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void ReadKeyValueTags( SteamUGCQueryCompleted_t data, uint index )
|
||||||
|
{
|
||||||
|
var tempDict = new Dictionary<string, List<string>>( StringComparer.InvariantCultureIgnoreCase );
|
||||||
|
|
||||||
|
var numKeyValTags = workshop.ugc.GetQueryUGCNumKeyValueTags( data.Handle, index );
|
||||||
|
|
||||||
|
for ( uint kvTagIndex = 0; kvTagIndex < numKeyValTags; ++kvTagIndex )
|
||||||
|
{
|
||||||
|
if ( !workshop.ugc.GetQueryUGCKeyValueTag( data.Handle, index, kvTagIndex, out var key, out var value ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ( !tempDict.TryGetValue( key, out var list ) )
|
||||||
|
{
|
||||||
|
list = new List<string>();
|
||||||
|
tempDict.Add( key, list );
|
||||||
|
}
|
||||||
|
|
||||||
|
list.Add( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyValueTags = new Dictionary<string, string[]>( StringComparer.InvariantCultureIgnoreCase );
|
||||||
|
|
||||||
|
foreach ( var keyValues in tempDict )
|
||||||
|
{
|
||||||
|
KeyValueTags.Add( keyValues.Key, keyValues.Value.ToArray() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Download( bool highPriority = true )
|
public bool Download( bool highPriority = true )
|
||||||
{
|
{
|
||||||
if ( Installed ) return true;
|
if ( Installed ) return true;
|
||||||
|
@ -35,6 +35,8 @@ namespace Facepunch.Steamworks
|
|||||||
|
|
||||||
public ulong? UserId { get; set; }
|
public ulong? UserId { get; set; }
|
||||||
|
|
||||||
|
public bool ReturnKeyValueTags { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If order is RankedByTrend, this value represents how many days to take
|
/// If order is RankedByTrend, this value represents how many days to take
|
||||||
/// into account.
|
/// into account.
|
||||||
@ -83,7 +85,7 @@ namespace Facepunch.Steamworks
|
|||||||
RunInternal();
|
RunInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe void RunInternal()
|
void RunInternal()
|
||||||
{
|
{
|
||||||
if ( FileId.Count != 0 )
|
if ( FileId.Count != 0 )
|
||||||
{
|
{
|
||||||
@ -111,12 +113,17 @@ namespace Facepunch.Steamworks
|
|||||||
if ( RequireTags.Count > 0 )
|
if ( RequireTags.Count > 0 )
|
||||||
workshop.ugc.SetMatchAnyTag( Handle, !RequireAllTags );
|
workshop.ugc.SetMatchAnyTag( Handle, !RequireAllTags );
|
||||||
|
|
||||||
|
foreach ( var keyValueTag in RequireKeyValueTags )
|
||||||
|
workshop.ugc.AddRequiredKeyValueTag( Handle, keyValueTag.Key, keyValueTag.Value );
|
||||||
|
|
||||||
if ( RankedByTrendDays > 0 )
|
if ( RankedByTrendDays > 0 )
|
||||||
workshop.ugc.SetRankedByTrendDays( Handle, (uint) RankedByTrendDays );
|
workshop.ugc.SetRankedByTrendDays( Handle, (uint) RankedByTrendDays );
|
||||||
|
|
||||||
foreach ( var tag in ExcludeTags )
|
foreach ( var tag in ExcludeTags )
|
||||||
workshop.ugc.AddExcludedTag( Handle, tag );
|
workshop.ugc.AddExcludedTag( Handle, tag );
|
||||||
|
|
||||||
|
workshop.ugc.SetReturnKeyValueTags( Handle, ReturnKeyValueTags );
|
||||||
|
|
||||||
Callback = workshop.ugc.SendQueryUGCRequest( Handle, ResultCallback );
|
Callback = workshop.ugc.SendQueryUGCRequest( Handle, ResultCallback );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,6 +157,9 @@ namespace Facepunch.Steamworks
|
|||||||
item.WebsiteViews = GetStat( data.Handle, i, ItemStatistic.NumUniqueWebsiteViews );
|
item.WebsiteViews = GetStat( data.Handle, i, ItemStatistic.NumUniqueWebsiteViews );
|
||||||
item.ReportScore = GetStat( data.Handle, i, ItemStatistic.ReportScore );
|
item.ReportScore = GetStat( data.Handle, i, ItemStatistic.ReportScore );
|
||||||
|
|
||||||
|
if ( ReturnKeyValueTags )
|
||||||
|
item.ReadKeyValueTags( data, (uint)i );
|
||||||
|
|
||||||
string url = null;
|
string url = null;
|
||||||
if ( workshop.ugc.GetQueryUGCPreviewURL( data.Handle, (uint)i, out url ) )
|
if ( workshop.ugc.GetQueryUGCPreviewURL( data.Handle, (uint)i, out url ) )
|
||||||
item.PreviewImageUrl = url;
|
item.PreviewImageUrl = url;
|
||||||
@ -202,7 +212,7 @@ namespace Facepunch.Steamworks
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Only return items with these tags
|
/// Only return items with these tags
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> RequireTags { get; set; } = new List<string>();
|
public List<string> RequireTags { get; } = new List<string>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If true, return items that have all RequireTags
|
/// If true, return items that have all RequireTags
|
||||||
@ -213,14 +223,14 @@ namespace Facepunch.Steamworks
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Don't return any items with this tag
|
/// Don't return any items with this tag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> ExcludeTags { get; set; } = new List<string>();
|
public List<string> ExcludeTags { get; } = new List<string>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If you're querying for a particular file or files, add them to this.
|
/// If you're querying for a particular file or files, add them to this.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ulong> FileId { get; set; } = new List<ulong>();
|
public List<ulong> FileId { get; } = new List<ulong>();
|
||||||
|
|
||||||
|
|
||||||
|
public List<KeyValuePair<string, string>> RequireKeyValueTags { get; } = new List<KeyValuePair<string, string>>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Don't call this in production!
|
/// Don't call this in production!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user