diff --git a/Facepunch.Steamworks.Test/Client/Workshop.cs b/Facepunch.Steamworks.Test/Client/Workshop.cs index 721cabb..4bf8a01 100644 --- a/Facepunch.Steamworks.Test/Client/Workshop.cs +++ b/Facepunch.Steamworks.Test/Client/Workshop.cs @@ -27,18 +27,31 @@ public void Query() Query.Block(); Assert.IsFalse( Query.IsRunning ); + Assert.IsTrue( Query.TotalResults > 0 ); + Assert.IsTrue( Query.Items.Length > 0 ); // results Console.WriteLine( "Searching" ); - Query.SearchText = "shit"; + Query.Order = Workshop.Order.RankedByTextSearch; + Query.QueryType = Workshop.QueryType.Items_Mtx; + Query.SearchText = "rock"; Query.Run(); // Block, wait for result // (don't do this in realtime) Query.Block(); + Assert.IsTrue( Query.TotalResults > 0 ); + Assert.IsTrue( Query.Items.Length > 0 ); + + foreach ( var item in Query.Items ) + { + Console.WriteLine( "{0}", item.Title ); + Console.WriteLine( "{0}\n", item.Description ); + } + for ( int i=0; i<100; i++ ) { client.Update(); diff --git a/Facepunch.Steamworks/Interfaces/Workshop.cs b/Facepunch.Steamworks/Interfaces/Workshop.cs index 39d5a21..71bfee7 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.cs @@ -59,7 +59,6 @@ public enum QueryType UsableInGame = 10, // ready-to-use items and integrated guides ControllerBindings = 11, GameManagedItems = 12, // game managed items (not managed by users) - All = ~0, // return everything }; public WorkshopQuery CreateQuery() @@ -69,16 +68,48 @@ public WorkshopQuery CreateQuery() return q; } + public class WorkshopItem + { + public string Description { get; private set; } + public ulong Id { get; private set; } + public ulong OwnerId { get; private set; } + public float Score { get; private set; } + public string[] Tags { get; private set; } + public string Title { get; private set; } + public uint VotesDown { get; private set; } + public uint VotesUp { get; private set; } + + internal static WorkshopItem From( SteamUGCDetails_t details ) + { + var item = new WorkshopItem(); + + item.Id = details.m_nPublishedFileId; + item.Title = details.m_rgchTitle; + item.Description = details.m_rgchDescription; + item.OwnerId = details.m_ulSteamIDOwner; + item.Tags = details.m_rgchTags.Split( ' ' ); + item.Score = details.m_flScore; + item.VotesUp = details.m_unVotesUp; + item.VotesDown = details.m_unVotesDown; + + return item; + } + } + public class WorkshopQuery { internal ulong Handle; internal QueryCompleted Callback; - public QueryType QueryType { get; set; } = QueryType.All; - public Order Order { get; set; } = Order.RankedByPublicationDate; + public QueryType QueryType { get; set; } = QueryType.Items; + public Order Order { get; set; } = Order.RankedByVote; public string SearchText { get; set; } + public WorkshopItem[] Items { get; set; } + + public int TotalResults { get; set; } + /// /// Page starts at 1 !! /// @@ -106,10 +137,20 @@ public void Run() void OnResult( QueryCompleted.Data data ) { + List< WorkshopItem > items = new List(); + for ( int i = 0; i < data.m_unNumResultsReturned; i++ ) + { + SteamUGCDetails_t details = new SteamUGCDetails_t(); + workshop.ugc.GetQueryUGCResult( data.Handle, (uint) i, ref details ); + + items.Add( WorkshopItem.From( details ) ); + } + + Items = items.ToArray(); + TotalResults = (int) data.m_unTotalMatchingResults; + Callback.Dispose(); Callback = null; - - Console.WriteLine( "Results: " + data.m_unTotalMatchingResults ); } public bool IsRunning