diff --git a/Facepunch.Steamworks/SteamUgc.cs b/Facepunch.Steamworks/SteamUgc.cs index a2f377d..a329954 100644 --- a/Facepunch.Steamworks/SteamUgc.cs +++ b/Facepunch.Steamworks/SteamUgc.cs @@ -64,5 +64,23 @@ namespace Steamworks return item; } + + public static async Task StartPlaytimeTracking(PublishedFileId fileId) + { + var result = await Internal.StartPlaytimeTracking(new[] {fileId}, 1); + return result.Value.Result == Result.OK; + } + + public static async Task StopPlaytimeTracking(PublishedFileId fileId) + { + var result = await Internal.StopPlaytimeTracking(new[] {fileId}, 1); + return result.Value.Result == Result.OK; + } + + public static async Task StopPlaytimeTrackingForAllItems() + { + var result = await Internal.StopPlaytimeTrackingForAllItems(); + return result.Value.Result == Result.OK; + } } -} \ No newline at end of file +} diff --git a/Facepunch.Steamworks/Structs/UgcEditor.cs b/Facepunch.Steamworks/Structs/UgcEditor.cs index a97c153..b842df8 100644 --- a/Facepunch.Steamworks/Structs/UgcEditor.cs +++ b/Facepunch.Steamworks/Structs/UgcEditor.cs @@ -69,6 +69,8 @@ namespace Steamworks.Ugc public Editor WithPrivateVisibility() { Visibility = RemoteStoragePublishedFileVisibility.Private; return this; } List Tags; + Dictionary KeyValueTags; + public Editor WithTag( string tag ) { if ( Tags == null ) Tags = new List(); @@ -78,6 +80,13 @@ namespace Steamworks.Ugc return this; } + public Editor AddKeyValueTag(string key, string value) + { + if (KeyValueTags == null) KeyValueTags = new Dictionary(); + KeyValueTags.Add(key, value); + return this; + } + public async Task SubmitAsync( IProgress progress = null ) { var result = default( PublishResult ); @@ -134,6 +143,14 @@ namespace Steamworks.Ugc } } + if (KeyValueTags != null && KeyValueTags.Count > 0) + { + foreach (var keyValueTag in KeyValueTags) + { + SteamUGC.Internal.AddItemKeyValueTag(handle, keyValueTag.Key, keyValueTag.Value); + } + } + result.Result = Steamworks.Result.Fail; if ( ChangeLog == null ) @@ -171,7 +188,7 @@ namespace Steamworks.Ugc } case ItemUpdateStatus.UploadingPreviewFile: { - progress?.Report( 8f ); + progress?.Report( 0.8f ); break; } case ItemUpdateStatus.CommittingChanges: diff --git a/Facepunch.Steamworks/Structs/UgcItem.cs b/Facepunch.Steamworks/Structs/UgcItem.cs index b661aa3..820a581 100644 --- a/Facepunch.Steamworks/Structs/UgcItem.cs +++ b/Facepunch.Steamworks/Structs/UgcItem.cs @@ -263,19 +263,48 @@ namespace Steamworks.Ugc return result?.Result == Result.OK; } + /// + /// Adds item to user favorite list + /// + public async Task AddFavorite() + { + var result = await SteamUGC.Internal.AddItemToFavorites(details.ConsumerAppID, _id); + return result?.Result == Result.OK; + } + + /// + /// Removes item from user favorite list + /// + public async Task RemoveFavorite() + { + var result = await SteamUGC.Internal.RemoveItemFromFavorites(details.ConsumerAppID, _id); + return result?.Result == Result.OK; + } + /// /// Allows the user to rate a workshop item up or down. /// - public async Task Vote( bool up ) + public async Task Vote( bool up ) { var r = await SteamUGC.Internal.SetUserItemVote( Id, up ); - return r?.Result == Result.OK; + return r?.Result; } - /// - /// Return a URL to view this item online - /// - public string Url => $"http://steamcommunity.com/sharedfiles/filedetails/?source=Facepunch.Steamworks&id={Id}"; + /// + /// Gets the current users vote on the item + /// + public async Task GetUserVote() + { + var result = await SteamUGC.Internal.GetUserItemVote(_id); + if (!result.HasValue) + return null; + return UserItemVote.From(result.Value); + } + + /// + /// Return a URL to view this item online + /// + public string Url => $"http://steamcommunity.com/sharedfiles/filedetails/?source=Facepunch.Steamworks&id={Id}"; /// /// The URl to view this item's changelog @@ -323,6 +352,7 @@ namespace Steamworks.Ugc { return new Ugc.Editor( Id ); } + + public Result Result => details.Result; } - -} \ No newline at end of file +} diff --git a/Facepunch.Steamworks/Structs/UgcQuery.cs b/Facepunch.Steamworks/Structs/UgcQuery.cs index e69ef1c..986bdcd 100644 --- a/Facepunch.Steamworks/Structs/UgcQuery.cs +++ b/Facepunch.Steamworks/Structs/UgcQuery.cs @@ -127,6 +127,13 @@ namespace Steamworks.Ugc handle = SteamUGC.Internal.CreateQueryAllUGCRequest1( queryType, matchingType, creatorApp.Value, consumerApp.Value, (uint)page ); } + ApplyReturns(handle); + + if (maxCacheAge.HasValue) + { + SteamUGC.Internal.SetAllowCachedResponse(handle, (uint)maxCacheAge.Value); + } + ApplyConstraints( handle ); var result = await SteamUGC.Internal.SendQueryUGCRequest( handle ); @@ -145,25 +152,8 @@ namespace Steamworks.Ugc }; } - - #region SharedConstraints + #region SharedConstraints public QueryType WithType( UgcType type ) { matchingType = type; return this; } - bool? WantsReturnOnlyIDs; - public QueryType WithOnlyIDs( bool b ) { WantsReturnOnlyIDs = b; return this; } - bool? WantsReturnKeyValueTags; - public QueryType WithKeyValueTag( bool b ) { WantsReturnKeyValueTags = b; return this; } - bool? WantsReturnLongDescription; - public QueryType WithLongDescription( bool b ) { WantsReturnLongDescription = b; return this; } - bool? WantsReturnMetadata; - public QueryType WithMetadata( bool b ) { WantsReturnMetadata = b; return this; } - bool? WantsReturnChildren; - public QueryType WithChildren( bool b ) { WantsReturnChildren = b; return this; } - bool? WantsReturnAdditionalPreviews; - public QueryType WithAdditionalPreviews( bool b ) { WantsReturnAdditionalPreviews = b; return this; } - bool? WantsReturnTotalOnly; - public QueryType WithTotalOnly( bool b ) { WantsReturnTotalOnly = b; return this; } - bool? WantsReturnPlaytimeStats; - public QueryType WithPlaytimeStats( bool b ) { WantsReturnPlaytimeStats = b; return this; } int? maxCacheAge; public QueryType AllowCachedResponse( int maxSecondsAge ) { maxCacheAge = maxSecondsAge; return this; } string language; @@ -194,6 +184,13 @@ namespace Steamworks.Ugc return this; } + public QueryType AddRequiredKeyValueTag(string key, string value) + { + if (requiredKv == null) requiredKv = new Dictionary(); + requiredKv.Add(key, value); + return this; + } + public QueryType WithoutTag( string tag ) { if ( excludedTags == null ) excludedTags = new List(); @@ -237,7 +234,70 @@ namespace Steamworks.Ugc } } - #endregion + #endregion - } + #region ReturnValues + + bool? WantsReturnOnlyIDs; + public QueryType WithOnlyIDs(bool b) { WantsReturnOnlyIDs = b; return this; } + bool? WantsReturnKeyValueTags; + public QueryType WithKeyValueTag(bool b) { WantsReturnKeyValueTags = b; return this; } + bool? WantsReturnLongDescription; + public QueryType WithLongDescription(bool b) { WantsReturnLongDescription = b; return this; } + bool? WantsReturnMetadata; + public QueryType WithMetadata(bool b) { WantsReturnMetadata = b; return this; } + bool? WantsReturnChildren; + public QueryType WithChildren(bool b) { WantsReturnChildren = b; return this; } + bool? WantsReturnAdditionalPreviews; + public QueryType WithAdditionalPreviews(bool b) { WantsReturnAdditionalPreviews = b; return this; } + bool? WantsReturnTotalOnly; + public QueryType WithTotalOnly(bool b) { WantsReturnTotalOnly = b; return this; } + uint? WantsReturnPlaytimeStats; + public QueryType WithPlaytimeStats(uint unDays) { WantsReturnPlaytimeStats = unDays; return this; } + + private void ApplyReturns(UGCQueryHandle_t handle) + { + if (WantsReturnOnlyIDs.HasValue) + { + SteamUGC.Internal.SetReturnOnlyIDs(handle, WantsReturnOnlyIDs.Value); + } + + if (WantsReturnKeyValueTags.HasValue) + { + SteamUGC.Internal.SetReturnKeyValueTags(handle, WantsReturnKeyValueTags.Value); + } + + if (WantsReturnLongDescription.HasValue) + { + SteamUGC.Internal.SetReturnLongDescription(handle, WantsReturnLongDescription.Value); + } + + if (WantsReturnMetadata.HasValue) + { + SteamUGC.Internal.SetReturnMetadata(handle, WantsReturnMetadata.Value); + } + + if (WantsReturnChildren.HasValue) + { + SteamUGC.Internal.SetReturnChildren(handle, WantsReturnChildren.Value); + } + + if (WantsReturnAdditionalPreviews.HasValue) + { + SteamUGC.Internal.SetReturnAdditionalPreviews(handle, WantsReturnAdditionalPreviews.Value); + } + + if (WantsReturnTotalOnly.HasValue) + { + SteamUGC.Internal.SetReturnTotalOnly(handle, WantsReturnTotalOnly.Value); + } + + if (WantsReturnPlaytimeStats.HasValue) + { + SteamUGC.Internal.SetReturnPlaytimeStats(handle, WantsReturnPlaytimeStats.Value); + } + } + + #endregion + } } \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/UserItemVote.cs b/Facepunch.Steamworks/Structs/UserItemVote.cs new file mode 100644 index 0000000..191faed --- /dev/null +++ b/Facepunch.Steamworks/Structs/UserItemVote.cs @@ -0,0 +1,21 @@ +using Steamworks.Data; + +namespace Steamworks.Ugc +{ + public struct UserItemVote + { + public bool VotedUp; + public bool VotedDown; + public bool VoteSkipped; + + internal static UserItemVote? From(GetUserItemVoteResult_t result) + { + return new UserItemVote + { + VotedUp = result.VotedUp, + VotedDown = result.VotedDown, + VoteSkipped = result.VoteSkipped + }; + } + } +}