Tag include/exclude

This commit is contained in:
Garry Newman 2016-10-06 12:43:38 +01:00
parent e98441f28d
commit 668a682173
2 changed files with 102 additions and 5 deletions

View File

@ -37,6 +37,7 @@ public void Query()
Query.Order = Workshop.Order.RankedByTextSearch;
Query.QueryType = Workshop.QueryType.Items_Mtx;
Query.SearchText = "shit";
Query.RequireTags.Add( "LongTShirt Skin" );
Query.Run();
// Block, wait for result
@ -53,11 +54,77 @@ public void Query()
{
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();
Thread.Sleep( 10 );
Query.RequireTags.Add( "LongTShirt Skin" );
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" ) );
}
}
}
}

View File

@ -88,7 +88,7 @@ internal static WorkshopItem From( SteamUGCDetails_t details )
item.Title = details.m_rgchTitle;
item.Description = details.m_rgchDescription;
item.OwnerId = details.m_ulSteamIDOwner;
item.Tags = details.m_rgchTags.Split( ' ' );
item.Tags = details.m_rgchTags.Split( ',' );
item.Score = details.m_flScore;
item.VotesUp = details.m_unVotesUp;
item.VotesDown = details.m_unVotesDown;
@ -97,7 +97,7 @@ internal static WorkshopItem From( SteamUGCDetails_t details )
}
}
public class WorkshopQuery
public class WorkshopQuery : IDisposable
{
internal ulong Handle;
internal QueryCompleted Callback;
@ -141,6 +141,15 @@ public void Run()
if ( !string.IsNullOrEmpty( 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.Handle = workshop.ugc.SendQueryUGCRequest( Handle );
Callback.OnResult = OnResult;
@ -170,6 +179,22 @@ public bool IsRunning
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>
/// Don't call this in production!
/// </summary>
@ -183,6 +208,11 @@ public void Block()
workshop.steamworks.Update();
}
}
public void Dispose()
{
}
}
}
}