Added Workshop.Editor.OnChangesSubmitted event

This commit is contained in:
James King 2018-07-16 16:35:01 +01:00
parent 46f56c24f3
commit 2e8fe41040
2 changed files with 22 additions and 9 deletions

View File

@ -4,6 +4,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using System.Diagnostics;
using Facepunch.Steamworks.Callbacks;
namespace Facepunch.Steamworks.Test
{
@ -452,6 +453,12 @@ public void CreatePublish()
Console.WriteLine(item.Folder);
item.OnChangesSubmitted += result =>
{
Console.WriteLine( "OnChangesSubmitted called: " + result );
Assert.AreEqual( Result.OK, result );
};
try
{
item.Publish();

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using SteamNative;
using Result = Facepunch.Steamworks.Callbacks.Result;
namespace Facepunch.Steamworks
{
@ -37,7 +38,10 @@ public enum VisibilityType : int
public bool NeedToAgreeToWorkshopLegal { get; internal set; }
/// <summary>
/// Called when published changes have finished being submitted.
/// </summary>
public event Action<Result> OnChangesSubmitted;
public double Progress
{
@ -119,13 +123,16 @@ private void OnItemCreated( SteamNative.CreateItemResult_t obj, bool Failed )
if ( obj.Result == SteamNative.Result.OK && !Failed )
{
Error = null;
Id = obj.PublishedFileId;
PublishChanges();
return;
}
Error = "Error creating new file: " + obj.Result.ToString() + "("+ obj.PublishedFileId+ ")";
Error = $"Error creating new file: {obj.Result} ({obj.PublishedFileId})";
Publishing = false;
OnChangesSubmitted?.Invoke( (Result) obj.Result );
}
private void PublishChanges()
@ -179,10 +186,10 @@ private void PublishChanges()
workshop.ugc.RemoveItemPreview( UpdateId, uint32 index ) = 0; // remove a preview by index starting at 0 (previews are sorted)
*/
SubmitItemUpdate = workshop.ugc.SubmitItemUpdate( UpdateHandle, ChangeNote, OnChangesSubmitted );
SubmitItemUpdate = workshop.ugc.SubmitItemUpdate( UpdateHandle, ChangeNote, OnChangesSubmittedInternal );
}
private void OnChangesSubmitted( SteamNative.SubmitItemUpdateResult_t obj, bool Failed )
private void OnChangesSubmittedInternal( SteamNative.SubmitItemUpdateResult_t obj, bool Failed )
{
if ( Failed )
throw new System.Exception( "CreateItemResult_t Failed" );
@ -192,12 +199,11 @@ private void OnChangesSubmitted( SteamNative.SubmitItemUpdateResult_t obj, bool
NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement;
Publishing = false;
if ( obj.Result == SteamNative.Result.OK )
{
return;
}
Error = obj.Result != SteamNative.Result.OK
? $"Error publishing changes: {obj.Result} ({NeedToAgreeToWorkshopLegal})"
: null;
Error = "Error publishing changes: " + obj.Result.ToString() + " ("+ NeedToAgreeToWorkshopLegal + ")";
OnChangesSubmitted?.Invoke( (Result) obj.Result );
}
public void Delete()