diff --git a/Facepunch.Steamworks.Test/Client/WorkshopTest.cs b/Facepunch.Steamworks.Test/Client/WorkshopTest.cs index 39b6b93..2e3f320 100644 --- a/Facepunch.Steamworks.Test/Client/WorkshopTest.cs +++ b/Facepunch.Steamworks.Test/Client/WorkshopTest.cs @@ -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(); diff --git a/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs b/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs index 7905a13..86525be 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs @@ -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; } - + /// + /// Called when published changes have finished being submitted. + /// + public event Action 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()