mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-26 06:35:49 +03:00
Workshop item info
This commit is contained in:
parent
ffa2bf493b
commit
e181bef77b
@ -27,18 +27,31 @@ public void Query()
|
|||||||
Query.Block();
|
Query.Block();
|
||||||
|
|
||||||
Assert.IsFalse( Query.IsRunning );
|
Assert.IsFalse( Query.IsRunning );
|
||||||
|
Assert.IsTrue( Query.TotalResults > 0 );
|
||||||
|
Assert.IsTrue( Query.Items.Length > 0 );
|
||||||
|
|
||||||
// results
|
// results
|
||||||
|
|
||||||
Console.WriteLine( "Searching" );
|
Console.WriteLine( "Searching" );
|
||||||
|
|
||||||
Query.SearchText = "shit";
|
Query.Order = Workshop.Order.RankedByTextSearch;
|
||||||
|
Query.QueryType = Workshop.QueryType.Items_Mtx;
|
||||||
|
Query.SearchText = "rock";
|
||||||
Query.Run();
|
Query.Run();
|
||||||
|
|
||||||
// Block, wait for result
|
// Block, wait for result
|
||||||
// (don't do this in realtime)
|
// (don't do this in realtime)
|
||||||
Query.Block();
|
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++ )
|
for ( int i=0; i<100; i++ )
|
||||||
{
|
{
|
||||||
client.Update();
|
client.Update();
|
||||||
|
@ -59,7 +59,6 @@ public enum QueryType
|
|||||||
UsableInGame = 10, // ready-to-use items and integrated guides
|
UsableInGame = 10, // ready-to-use items and integrated guides
|
||||||
ControllerBindings = 11,
|
ControllerBindings = 11,
|
||||||
GameManagedItems = 12, // game managed items (not managed by users)
|
GameManagedItems = 12, // game managed items (not managed by users)
|
||||||
All = ~0, // return everything
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public WorkshopQuery CreateQuery()
|
public WorkshopQuery CreateQuery()
|
||||||
@ -69,16 +68,48 @@ public WorkshopQuery CreateQuery()
|
|||||||
return q;
|
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
|
public class WorkshopQuery
|
||||||
{
|
{
|
||||||
internal ulong Handle;
|
internal ulong Handle;
|
||||||
internal QueryCompleted Callback;
|
internal QueryCompleted Callback;
|
||||||
|
|
||||||
public QueryType QueryType { get; set; } = QueryType.All;
|
public QueryType QueryType { get; set; } = QueryType.Items;
|
||||||
public Order Order { get; set; } = Order.RankedByPublicationDate;
|
public Order Order { get; set; } = Order.RankedByVote;
|
||||||
|
|
||||||
public string SearchText { get; set; }
|
public string SearchText { get; set; }
|
||||||
|
|
||||||
|
public WorkshopItem[] Items { get; set; }
|
||||||
|
|
||||||
|
public int TotalResults { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Page starts at 1 !!
|
/// Page starts at 1 !!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -106,10 +137,20 @@ public void Run()
|
|||||||
|
|
||||||
void OnResult( QueryCompleted.Data data )
|
void OnResult( QueryCompleted.Data data )
|
||||||
{
|
{
|
||||||
|
List< WorkshopItem > items = new List<WorkshopItem>();
|
||||||
|
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.Dispose();
|
||||||
Callback = null;
|
Callback = null;
|
||||||
|
|
||||||
Console.WriteLine( "Results: " + data.m_unTotalMatchingResults );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsRunning
|
public bool IsRunning
|
||||||
|
Loading…
Reference in New Issue
Block a user