From 5e0abacd54b78f2122a6e70364b6dacb7af1a918 Mon Sep 17 00:00:00 2001 From: James King Date: Mon, 11 Nov 2019 19:54:45 +0000 Subject: [PATCH] Added Workshop.Item.GetUserItemVote --- .../Interfaces/Workshop.Item.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Facepunch.Steamworks/Interfaces/Workshop.Item.cs b/Facepunch.Steamworks/Interfaces/Workshop.Item.cs index 0a55aea..615b38c 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.Item.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.Item.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Facepunch.Steamworks.Callbacks; using SteamNative; +using Result = SteamNative.Result; namespace Facepunch.Steamworks { @@ -13,7 +15,7 @@ namespace Facepunch.Steamworks internal Workshop workshop; public string Description { get; private set; } - public ulong Id { get; private set; } + public ulong Id { get; } public ulong OwnerId { get; private set; } public float Score { get; private set; } public string[] Tags { get; private set; } @@ -204,6 +206,39 @@ namespace Facepunch.Steamworks YourVote = -1; } + public struct UserItemVoteResult + { + public readonly bool VotedUp; + public readonly bool VotedDown; + public readonly bool VoteSkipped; + + internal UserItemVoteResult( GetUserItemVoteResult_t result ) + { + VotedUp = result.VotedUp; + VotedDown = result.VotedDown; + VoteSkipped = result.VoteSkipped; + } + } + + public delegate void GetUserVoteCallback( UserItemVoteResult result ); + + public bool GetUserItemVote( GetUserVoteCallback onSuccess, FailureCallback onFailure = null ) + { + workshop.ugc.GetUserItemVote( Id, ( result, error ) => + { + if ( !error && result.Result == Result.OK ) + { + onSuccess?.Invoke( new UserItemVoteResult( result ) ); + } + else + { + onFailure?.Invoke( result.Result == 0 ? Callbacks.Result.IOFailure : (Callbacks.Result) result.Result ); + } + } ); + + return true; + } + public Editor Edit() { return workshop.EditItem( Id );