diff --git a/Facepunch.Steamworks/Structs/UgcEditor.cs b/Facepunch.Steamworks/Structs/UgcEditor.cs index 21251b1..18cb244 100644 --- a/Facepunch.Steamworks/Structs/UgcEditor.cs +++ b/Facepunch.Steamworks/Structs/UgcEditor.cs @@ -69,8 +69,9 @@ public Editor( PublishedFileId fileId ) : this() public Editor WithPrivateVisibility() { Visibility = RemoteStoragePublishedFileVisibility.Private; return this; } List Tags; - Dictionary KeyValueTags; - + Dictionary> KeyValueTags; + HashSet KeyValueTagsToRemove; + public Editor WithTag( string tag ) { if ( Tags == null ) Tags = new List(); @@ -80,10 +81,37 @@ public Editor WithTag( string tag ) return this; } + /// + /// Adds a key-value tag pair to an item. + /// Keys can map to multiple different values (1-to-many relationship). + /// Key names are restricted to alpha-numeric characters and the '_' character. + /// Both keys and values cannot exceed 255 characters in length. Key-value tags are searchable by exact match only. + /// To replace all values associated to one key use RemoveKeyValueTags then AddKeyValueTag. + /// public Editor AddKeyValueTag(string key, string value) { - if (KeyValueTags == null) KeyValueTags = new Dictionary(); - KeyValueTags.Add(key, value); + if (KeyValueTags == null) + KeyValueTags = new Dictionary>(); + + if ( KeyValueTags.TryGetValue( key, out var list ) ) + list.Add( value ); + else + KeyValueTags[key] = new List() { value }; + + return this; + } + + /// + /// Removes a key and all values associated to it. + /// You can remove up to 100 keys per item update. + /// If you need remove more tags than that you'll need to make subsequent item updates. + /// + public Editor RemoveKeyValueTags( string key ) + { + if ( KeyValueTagsToRemove == null ) + KeyValueTagsToRemove = new HashSet(); + + KeyValueTagsToRemove.Add( key ); return this; } @@ -156,11 +184,19 @@ public async Task SubmitAsync( IProgress progress = null ) } } - if (KeyValueTags != null && KeyValueTags.Count > 0) + if ( KeyValueTagsToRemove != null) { - foreach (var keyValueTag in KeyValueTags) + foreach ( var key in KeyValueTagsToRemove ) + SteamUGC.Internal.RemoveItemKeyValueTags( handle, key ); + } + + if ( KeyValueTags != null ) + { + foreach ( var keyWithValues in KeyValueTags ) { - SteamUGC.Internal.AddItemKeyValueTag(handle, keyValueTag.Key, keyValueTag.Value); + var key = keyWithValues.Key; + foreach ( var value in keyWithValues.Value ) + SteamUGC.Internal.AddItemKeyValueTag( handle, key, value ); } }