From 455a9f895691e582e32211f275ac3a305775c417 Mon Sep 17 00:00:00 2001 From: Alex Mein Date: Wed, 16 Oct 2019 14:41:57 +0100 Subject: [PATCH] Added missing public methods for various functions in ISteamUGC. Fixed UGC Submit process reporting invalid progress value. --- Facepunch.Steamworks/Structs/UgcEditor.cs | 19 +++++++++- Facepunch.Steamworks/Structs/UgcItem.cs | 37 +++++++++++++++++--- Facepunch.Steamworks/Structs/UgcQuery.cs | 7 ++++ Facepunch.Steamworks/Structs/UserItemVote.cs | 21 +++++++++++ 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 Facepunch.Steamworks/Structs/UserItemVote.cs 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 @@ public Editor( PublishedFileId fileId ) : this() 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 @@ public Editor WithTag( string tag ) 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 @@ public async Task SubmitAsync( IProgress progress = null ) } } + 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 @@ public async Task SubmitAsync( IProgress progress = null ) } 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..09c1a61 100644 --- a/Facepunch.Steamworks/Structs/UgcItem.cs +++ b/Facepunch.Steamworks/Structs/UgcItem.cs @@ -263,6 +263,24 @@ public async Task Unsubscribe () 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. /// @@ -272,10 +290,21 @@ public async Task Vote( bool up ) return r?.Result == Result.OK; } - /// - /// 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 diff --git a/Facepunch.Steamworks/Structs/UgcQuery.cs b/Facepunch.Steamworks/Structs/UgcQuery.cs index e69ef1c..6bfd5ce 100644 --- a/Facepunch.Steamworks/Structs/UgcQuery.cs +++ b/Facepunch.Steamworks/Structs/UgcQuery.cs @@ -194,6 +194,13 @@ public QueryType WithTag( string tag ) 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(); diff --git a/Facepunch.Steamworks/Structs/UserItemVote.cs b/Facepunch.Steamworks/Structs/UserItemVote.cs new file mode 100644 index 0000000..f757443 --- /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 + }; + } + } +} \ No newline at end of file