mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-12 14:48:02 +03:00
Tag include/exclude
This commit is contained in:
parent
e98441f28d
commit
668a682173
@ -37,6 +37,7 @@ namespace Facepunch.Steamworks.Test
|
|||||||
Query.Order = Workshop.Order.RankedByTextSearch;
|
Query.Order = Workshop.Order.RankedByTextSearch;
|
||||||
Query.QueryType = Workshop.QueryType.Items_Mtx;
|
Query.QueryType = Workshop.QueryType.Items_Mtx;
|
||||||
Query.SearchText = "shit";
|
Query.SearchText = "shit";
|
||||||
|
Query.RequireTags.Add( "LongTShirt Skin" );
|
||||||
Query.Run();
|
Query.Run();
|
||||||
|
|
||||||
// Block, wait for result
|
// Block, wait for result
|
||||||
@ -53,11 +54,77 @@ namespace Facepunch.Steamworks.Test
|
|||||||
{
|
{
|
||||||
Console.WriteLine( "{0}", item.Title );
|
Console.WriteLine( "{0}", item.Title );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for ( int i=0; i<100; i++ )
|
[TestMethod]
|
||||||
|
public void QueryTagRequire()
|
||||||
|
{
|
||||||
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||||
|
{
|
||||||
|
Assert.IsTrue( client.IsValid );
|
||||||
|
|
||||||
|
using ( var Query = client.Workshop.CreateQuery() )
|
||||||
{
|
{
|
||||||
client.Update();
|
Query.RequireTags.Add( "LongTShirt Skin" );
|
||||||
Thread.Sleep( 10 );
|
Query.Run();
|
||||||
|
|
||||||
|
Query.Block();
|
||||||
|
|
||||||
|
Assert.IsFalse( Query.IsRunning );
|
||||||
|
Assert.IsTrue( Query.TotalResults > 0 );
|
||||||
|
Assert.IsTrue( Query.Items.Length > 0 );
|
||||||
|
|
||||||
|
Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
|
||||||
|
Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
|
||||||
|
|
||||||
|
Assert.IsTrue( Query.TotalResults > 0 );
|
||||||
|
Assert.IsTrue( Query.Items.Length > 0 );
|
||||||
|
|
||||||
|
foreach ( var item in Query.Items )
|
||||||
|
{
|
||||||
|
Console.WriteLine( "{0}", item.Title );
|
||||||
|
Console.WriteLine( "\t{0}", string.Join( ";", item.Tags ) );
|
||||||
|
|
||||||
|
Assert.IsTrue( item.Tags.Contains( "LongTShirt Skin" ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void QueryTagExclude()
|
||||||
|
{
|
||||||
|
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||||
|
{
|
||||||
|
Assert.IsTrue( client.IsValid );
|
||||||
|
|
||||||
|
using ( var Query = client.Workshop.CreateQuery() )
|
||||||
|
{
|
||||||
|
Query.RequireTags.Add( "LongTShirt Skin" );
|
||||||
|
Query.ExcludeTags.Add( "version2" );
|
||||||
|
Query.Run();
|
||||||
|
|
||||||
|
Query.Block();
|
||||||
|
|
||||||
|
Assert.IsFalse( Query.IsRunning );
|
||||||
|
Assert.IsTrue( Query.TotalResults > 0 );
|
||||||
|
Assert.IsTrue( Query.Items.Length > 0 );
|
||||||
|
|
||||||
|
Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
|
||||||
|
Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
|
||||||
|
|
||||||
|
Assert.IsTrue( Query.TotalResults > 0 );
|
||||||
|
Assert.IsTrue( Query.Items.Length > 0 );
|
||||||
|
|
||||||
|
foreach ( var item in Query.Items )
|
||||||
|
{
|
||||||
|
Console.WriteLine( "{0}", item.Title );
|
||||||
|
Console.WriteLine( "\t{0}", string.Join( ";", item.Tags ) );
|
||||||
|
|
||||||
|
Assert.IsTrue( item.Tags.Contains( "LongTShirt Skin" ) );
|
||||||
|
Assert.IsFalse( item.Tags.Contains( "version2" ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ namespace Facepunch.Steamworks
|
|||||||
item.Title = details.m_rgchTitle;
|
item.Title = details.m_rgchTitle;
|
||||||
item.Description = details.m_rgchDescription;
|
item.Description = details.m_rgchDescription;
|
||||||
item.OwnerId = details.m_ulSteamIDOwner;
|
item.OwnerId = details.m_ulSteamIDOwner;
|
||||||
item.Tags = details.m_rgchTags.Split( ' ' );
|
item.Tags = details.m_rgchTags.Split( ',' );
|
||||||
item.Score = details.m_flScore;
|
item.Score = details.m_flScore;
|
||||||
item.VotesUp = details.m_unVotesUp;
|
item.VotesUp = details.m_unVotesUp;
|
||||||
item.VotesDown = details.m_unVotesDown;
|
item.VotesDown = details.m_unVotesDown;
|
||||||
@ -97,7 +97,7 @@ namespace Facepunch.Steamworks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WorkshopQuery
|
public class WorkshopQuery : IDisposable
|
||||||
{
|
{
|
||||||
internal ulong Handle;
|
internal ulong Handle;
|
||||||
internal QueryCompleted Callback;
|
internal QueryCompleted Callback;
|
||||||
@ -141,6 +141,15 @@ namespace Facepunch.Steamworks
|
|||||||
if ( !string.IsNullOrEmpty( SearchText ) )
|
if ( !string.IsNullOrEmpty( SearchText ) )
|
||||||
workshop.ugc.SetSearchText( Handle, SearchText );
|
workshop.ugc.SetSearchText( Handle, SearchText );
|
||||||
|
|
||||||
|
foreach ( var tag in RequireTags )
|
||||||
|
workshop.ugc.AddRequiredTag( Handle, tag );
|
||||||
|
|
||||||
|
if ( RequireTags.Count > 0 )
|
||||||
|
workshop.ugc.SetMatchAnyTag( Handle, RequireAllTags );
|
||||||
|
|
||||||
|
foreach ( var tag in ExcludeTags )
|
||||||
|
workshop.ugc.AddExcludedTag( Handle, tag );
|
||||||
|
|
||||||
Callback = new QueryCompleted();
|
Callback = new QueryCompleted();
|
||||||
Callback.Handle = workshop.ugc.SendQueryUGCRequest( Handle );
|
Callback.Handle = workshop.ugc.SendQueryUGCRequest( Handle );
|
||||||
Callback.OnResult = OnResult;
|
Callback.OnResult = OnResult;
|
||||||
@ -170,6 +179,22 @@ namespace Facepunch.Steamworks
|
|||||||
get { return Callback != null; }
|
get { return Callback != null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Only return items with these tags
|
||||||
|
/// </summary>
|
||||||
|
public List<string> RequireTags { get; set; } = new List<string>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If true, return items that have all RequireTags
|
||||||
|
/// If false, return items that have any tags in RequireTags
|
||||||
|
/// </summary>
|
||||||
|
public bool RequireAllTags { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Don't return any items with this tag
|
||||||
|
/// </summary>
|
||||||
|
public List<string> ExcludeTags { get; set; } = new List<string>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Don't call this in production!
|
/// Don't call this in production!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -183,6 +208,11 @@ namespace Facepunch.Steamworks
|
|||||||
workshop.steamworks.Update();
|
workshop.steamworks.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user