From 586f4ee6f2a6bd21c0ea2958c219674391ba0eca Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Fri, 10 May 2019 10:43:03 +0100 Subject: [PATCH] Added Ugc.Item.Edit() --- Facepunch.Steamworks.Test/UgcEditor.cs | 53 +++++++++++++++++++++++ Facepunch.Steamworks.Test/UgcTest.cs | 2 + Facepunch.Steamworks/Structs/Socket.cs | 1 - Facepunch.Steamworks/Structs/UgcEditor.cs | 16 ++++--- Facepunch.Steamworks/Structs/UgcItem.cs | 9 +++- 5 files changed, 73 insertions(+), 8 deletions(-) diff --git a/Facepunch.Steamworks.Test/UgcEditor.cs b/Facepunch.Steamworks.Test/UgcEditor.cs index 801e8d4..1151601 100644 --- a/Facepunch.Steamworks.Test/UgcEditor.cs +++ b/Facepunch.Steamworks.Test/UgcEditor.cs @@ -90,6 +90,59 @@ namespace Steamworks } } + + + [TestMethod] + public async Task CreateAndThenEditFile() + { + PublishedFileId fileid = default; + + // + // Make a file + // + { + var result = await Ugc.Editor.NewCommunityFile + .WithTitle( "Unedited File" ) + .SubmitAsync(); + + Assert.IsTrue( result.Success ); + Assert.AreNotEqual( result.FileId.Value, 0 ); + + fileid = result.FileId; + } + + await Task.Delay( 1000 ); + + // + // Edit it + // + { + var editor = new Ugc.Editor( fileid ); + editor = editor.WithTitle( "An Edited File" ); + var result = await editor.SubmitAsync(); + + Assert.IsTrue( result.Success ); + Assert.AreEqual( result.FileId, fileid ); + } + + await Task.Delay( 1000 ); + + // + // Make sure the edited file matches + // + { + var details = await SteamUGC.QueryFileAsync( fileid ) ?? throw new Exception( "Somethign went wrong" ); + Assert.AreEqual( details.Id, fileid ); + Assert.AreEqual( details.Title, "An Edited File" ); + } + + // + // Clean up + // + var deleted = await SteamUGC.DeleteFileAsync( fileid ); + Assert.IsTrue( deleted ); + + } } } diff --git a/Facepunch.Steamworks.Test/UgcTest.cs b/Facepunch.Steamworks.Test/UgcTest.cs index 6a75284..4cb0832 100644 --- a/Facepunch.Steamworks.Test/UgcTest.cs +++ b/Facepunch.Steamworks.Test/UgcTest.cs @@ -32,6 +32,8 @@ namespace Steamworks Console.WriteLine( $"IsSubscribed: {itemInfo?.IsSubscribed}" ); Console.WriteLine( $"NeedsUpdate: {itemInfo?.NeedsUpdate}" ); Console.WriteLine( $"Description: {itemInfo?.Description}" ); + Console.WriteLine( $"Owner: {itemInfo?.Owner}" ); + Console.WriteLine( $"Score: {itemInfo?.Score}" ); } } } diff --git a/Facepunch.Steamworks/Structs/Socket.cs b/Facepunch.Steamworks/Structs/Socket.cs index f968978..d589acb 100644 --- a/Facepunch.Steamworks/Structs/Socket.cs +++ b/Facepunch.Steamworks/Structs/Socket.cs @@ -3,7 +3,6 @@ public struct Socket { internal uint Id; - public override string ToString() => Id.ToString(); /// diff --git a/Facepunch.Steamworks/Structs/UgcEditor.cs b/Facepunch.Steamworks/Structs/UgcEditor.cs index a4ff755..a97c153 100644 --- a/Facepunch.Steamworks/Structs/UgcEditor.cs +++ b/Facepunch.Steamworks/Structs/UgcEditor.cs @@ -19,8 +19,13 @@ namespace Steamworks.Ugc internal Editor( WorkshopFileType filetype ) : this() { - creatingNew = true; - creatingType = filetype; + this.creatingNew = true; + this.creatingType = filetype; + } + + public Editor( PublishedFileId fileId ) : this() + { + this.fileId = fileId; } /// @@ -35,7 +40,6 @@ namespace Steamworks.Ugc public Editor ForAppId( AppId id ) { this.consumerAppId = id; return this; } - string Title; public Editor WithTitle( string t ) { this.Title = t; return this; } @@ -80,14 +84,14 @@ namespace Steamworks.Ugc progress?.Report( 0 ); + if ( consumerAppId == 0 ) + consumerAppId = SteamClient.AppId; + // // Item Create // if ( creatingNew ) { - if ( consumerAppId == 0 ) - consumerAppId = SteamClient.AppId; - result.Result = Steamworks.Result.Fail; var created = await SteamUGC.Internal.CreateItem( consumerAppId, creatingType ); diff --git a/Facepunch.Steamworks/Structs/UgcItem.cs b/Facepunch.Steamworks/Structs/UgcItem.cs index 4c4b0ec..a6bcae3 100644 --- a/Facepunch.Steamworks/Structs/UgcItem.cs +++ b/Facepunch.Steamworks/Structs/UgcItem.cs @@ -18,7 +18,6 @@ namespace Steamworks.Ugc _id = id; } - /// /// The actual ID of this file /// @@ -206,6 +205,14 @@ namespace Steamworks.Ugc /// The URL to the preview image for this item /// public string PreviewImageUrl { get; internal set; } + + /// + /// Edit this item + /// + public Ugc.Editor Edit() + { + return new Ugc.Editor( Id ); + } } } \ No newline at end of file