Merge pull request #321 from alexcodejammer/master

Added missing workshop features
This commit is contained in:
Garry Newman 2019-11-11 08:55:36 +00:00 committed by GitHub
commit 8ceecd7350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 176 additions and 30 deletions

View File

@ -64,5 +64,23 @@ namespace Steamworks
return item;
}
public static async Task<bool> StartPlaytimeTracking(PublishedFileId fileId)
{
var result = await Internal.StartPlaytimeTracking(new[] {fileId}, 1);
return result.Value.Result == Result.OK;
}
public static async Task<bool> StopPlaytimeTracking(PublishedFileId fileId)
{
var result = await Internal.StopPlaytimeTracking(new[] {fileId}, 1);
return result.Value.Result == Result.OK;
}
public static async Task<bool> StopPlaytimeTrackingForAllItems()
{
var result = await Internal.StopPlaytimeTrackingForAllItems();
return result.Value.Result == Result.OK;
}
}
}
}

View File

@ -69,6 +69,8 @@ namespace Steamworks.Ugc
public Editor WithPrivateVisibility() { Visibility = RemoteStoragePublishedFileVisibility.Private; return this; }
List<string> Tags;
Dictionary<string, string> KeyValueTags;
public Editor WithTag( string tag )
{
if ( Tags == null ) Tags = new List<string>();
@ -78,6 +80,13 @@ namespace Steamworks.Ugc
return this;
}
public Editor AddKeyValueTag(string key, string value)
{
if (KeyValueTags == null) KeyValueTags = new Dictionary<string, string>();
KeyValueTags.Add(key, value);
return this;
}
public async Task<PublishResult> SubmitAsync( IProgress<float> 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:

View File

@ -263,19 +263,48 @@ namespace Steamworks.Ugc
return result?.Result == Result.OK;
}
/// <summary>
/// Adds item to user favorite list
/// </summary>
public async Task<bool> AddFavorite()
{
var result = await SteamUGC.Internal.AddItemToFavorites(details.ConsumerAppID, _id);
return result?.Result == Result.OK;
}
/// <summary>
/// Removes item from user favorite list
/// </summary>
public async Task<bool> RemoveFavorite()
{
var result = await SteamUGC.Internal.RemoveItemFromFavorites(details.ConsumerAppID, _id);
return result?.Result == Result.OK;
}
/// <summary>
/// Allows the user to rate a workshop item up or down.
/// </summary>
public async Task<bool> Vote( bool up )
public async Task<Result?> Vote( bool up )
{
var r = await SteamUGC.Internal.SetUserItemVote( Id, up );
return r?.Result == Result.OK;
return r?.Result;
}
/// <summary>
/// Return a URL to view this item online
/// </summary>
public string Url => $"http://steamcommunity.com/sharedfiles/filedetails/?source=Facepunch.Steamworks&id={Id}";
/// <summary>
/// Gets the current users vote on the item
/// </summary>
public async Task<UserItemVote?> GetUserVote()
{
var result = await SteamUGC.Internal.GetUserItemVote(_id);
if (!result.HasValue)
return null;
return UserItemVote.From(result.Value);
}
/// <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
@ -323,6 +352,7 @@ namespace Steamworks.Ugc
{
return new Ugc.Editor( Id );
}
public Result Result => details.Result;
}
}
}

View File

@ -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<string, string>();
requiredKv.Add(key, value);
return this;
}
public QueryType WithoutTag( string tag )
{
if ( excludedTags == null ) excludedTags = new List<string>();
@ -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
}
}

View File

@ -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
};
}
}
}