Tons of extra UGCItem fields

This commit is contained in:
Garry Newman 2019-05-06 20:46:11 +01:00
parent dda27d2c61
commit ea97de9c02
2 changed files with 171 additions and 21 deletions

View File

@ -10,23 +10,83 @@ namespace Steamworks.Ugc
{
public struct Item
{
internal enum ItemState : int
{
None = 0,
Subscribed = 1,
LegacyItem = 2,
Installed = 4,
NeedsUpdate = 8,
Downloading = 16,
DownloadPending = 32,
}
internal SteamUGCDetails_t details;
public PublishedFileId Id { get; internal set; }
/// <summary>
/// The actual ID of this file
/// </summary>
public PublishedFileId Id => details.PublishedFileId;
public string Title { get; internal set; }
public string Description { get; internal set; }
/// <summary>
/// The given title of this item
/// </summary>
public string Title => details.Title;
/// <summary>
/// The description of this item, in your local language if available
/// </summary>
public string Description => details.Description;
/// <summary>
/// A list of tags for this item, all lowercase
/// </summary>
public string[] Tags { get; internal set; }
/// <summary>
/// App Id of the app that created this item
/// </summary>
public AppId CreatorApp => details.CreatorAppID;
/// <summary>
/// App Id of the app that will consume this item.
/// </summary>
public AppId ConsumerApp => details.ConsumerAppID;
/// <summary>
/// User who created this content
/// </summary>
public Friend Owner => new Friend( details.SteamIDOwner );
/// <summary>
/// The bayesian average for up votes / total votes, between [0,1]
/// </summary>
public float Score => details.Score;
/// <summary>
/// Time when the published item was created
/// </summary>
public DateTime Created => Epoch.ToDateTime( details.TimeCreated );
/// <summary>
/// Time when the published item was last updated
/// </summary>
public DateTime Updated => Epoch.ToDateTime( details.TimeUpdated );
/// <summary>
/// True if this is publically visible
/// </summary>
public bool IsPublic => details.Visibility == RemoteStoragePublishedFileVisibility.Public;
/// <summary>
/// True if this item is only visible by friends of the creator
/// </summary>
public bool IsFriendsOnly => details.Visibility == RemoteStoragePublishedFileVisibility.FriendsOnly;
/// <summary>
/// True if this is only visible to the creator
/// </summary>
public bool IsPrivate => details.Visibility == RemoteStoragePublishedFileVisibility.Private;
/// <summary>
/// True if this item has been banned
/// </summary>
public bool IsBanned => details.Banned;
/// <summary>
/// Whether the developer of this app has specifically flagged this item as accepted in the Workshop
/// </summary>
public bool IsAcceptedForUse => details.AcceptedForUse;
public bool IsInstalled => (State & ItemState.Installed) == ItemState.Installed;
public bool IsDownloading => (State & ItemState.Downloading) == ItemState.Downloading;
public bool IsDownloadPending => (State & ItemState.DownloadPending) == ItemState.DownloadPending;
@ -47,6 +107,9 @@ public string Directory
}
}
/// <summary>
/// Start downloading this item
/// </summary>
public bool Download( bool highPriority = false )
{
return SteamUGC.Internal.DownloadItem( Id, highPriority );
@ -66,13 +129,8 @@ internal static Item From( SteamUGCDetails_t details )
{
var d = new Item
{
Id = details.PublishedFileId,
// FileType = details.FileType,
Title = details.Title,
Description = details.Description,
Tags = details.Tags.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries )
details = details,
Tags = details.Tags.ToLower().Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries )
};
return d;
@ -88,5 +146,58 @@ public bool HasTag( string find )
return Tags.Contains( find, StringComparer.OrdinalIgnoreCase );
}
/// <summary>
/// Allows the user to rate a workshop item up or down.
/// </summary>
public async Task<bool> Vote( bool up )
{
var r = await SteamUGC.Internal.SetUserItemVote( Id, up );
return r?.Result == Result.OK;
}
/// <summary>
/// Return a URL to view this item online
/// </summary>
public string Url => $"http://steamcommunity.com/sharedfiles/filedetails/?source=Facepunch.Steamworks&id={Id}";
/// <summary>
/// The URl to view this item's changelog
/// </summary>
public string ChangelogUrl => $"http://steamcommunity.com/sharedfiles/filedetails/changelog/{Id}";
/// <summary>
/// The URL to view the comments on this item
/// </summary>
public string CommentsUrl => $"http://steamcommunity.com/sharedfiles/filedetails/comments/{Id}";
/// <summary>
/// The URL to discuss this item
/// </summary>
public string DiscussUrl => $"http://steamcommunity.com/sharedfiles/filedetails/discussions/{Id}";
/// <summary>
/// The URL to view this items stats online
/// </summary>
public string StatsUrl => $"http://steamcommunity.com/sharedfiles/filedetails/stats/{Id}";
public ulong NumSubscriptions { get; internal set; }
public ulong NumFavorites { get; internal set; }
public ulong NumFollowers { get; internal set; }
public ulong NumUniqueSubscriptions { get; internal set; }
public ulong NumUniqueFavorites { get; internal set; }
public ulong NumUniqueFollowers { get; internal set; }
public ulong NumUniqueWebsiteViews { get; internal set; }
public ulong ReportScore { get; internal set; }
public ulong NumSecondsPlayed { get; internal set; }
public ulong NumPlaytimeSessions { get; internal set; }
public ulong NumComments { get; internal set; }
public ulong NumSecondsPlayedDuringTimePeriod { get; internal set; }
public ulong NumPlaytimeSessionsDuringTimePeriod { get; internal set; }
/// <summary>
/// The URL to the preview image for this item
/// </summary>
public string PreviewUrl { get; internal set; }
}
}

View File

@ -16,17 +16,56 @@ public IEnumerable<Item> Entries
{
get
{
var details = default( SteamUGCDetails_t );
for ( uint i=0; i< ResultCount; i++ )
{
if ( SteamUGC.Internal.GetQueryUGCResult( Handle, i, ref details ) )
{
yield return Item.From( details );
var item = Item.From( details );
item.NumSubscriptions = GetStat( i, ItemStatistic.NumSubscriptions );
item.NumFavorites = GetStat( i, ItemStatistic.NumFavorites );
item.NumFollowers = GetStat( i, ItemStatistic.NumFollowers );
item.NumUniqueSubscriptions = GetStat( i, ItemStatistic.NumUniqueSubscriptions );
item.NumUniqueFavorites = GetStat( i, ItemStatistic.NumUniqueFavorites );
item.NumUniqueFollowers = GetStat( i, ItemStatistic.NumUniqueFollowers );
item.NumUniqueWebsiteViews = GetStat( i, ItemStatistic.NumUniqueWebsiteViews );
item.ReportScore = GetStat( i, ItemStatistic.ReportScore );
item.NumSecondsPlayed = GetStat( i, ItemStatistic.NumSecondsPlayed );
item.NumPlaytimeSessions = GetStat( i, ItemStatistic.NumPlaytimeSessions );
item.NumComments = GetStat( i, ItemStatistic.NumComments );
item.NumSecondsPlayedDuringTimePeriod = GetStat( i, ItemStatistic.NumSecondsPlayedDuringTimePeriod );
item.NumPlaytimeSessionsDuringTimePeriod = GetStat( i, ItemStatistic.NumPlaytimeSessionsDuringTimePeriod );
var sb = Helpers.TakeStringBuilder();
if ( SteamUGC.Internal.GetQueryUGCPreviewURL( Handle, i, sb, (uint)sb.Capacity ) )
{
item.PreviewUrl = sb.ToString();
}
// TODO GetQueryUGCAdditionalPreview
// TODO GetQueryUGCChildren
// TODO GetQueryUGCKeyValueTag
// TODO GetQueryUGCMetadata
yield return item;
}
}
}
}
private ulong GetStat( uint index, ItemStatistic stat )
{
ulong val = 0;
if ( !SteamUGC.Internal.GetQueryUGCStatistic( Handle, index, stat, ref val ) )
return 0;
return val;
}
public void Dispose()
{
if ( Handle > 0 )