Removing/replacing ugc KeyValueTags

This commit is contained in:
kamyker 2020-05-14 20:11:59 +02:00
parent 9d8a9a1e9a
commit d58d95fe38

View File

@ -69,7 +69,8 @@ public Editor( PublishedFileId fileId ) : this()
public Editor WithPrivateVisibility() { Visibility = RemoteStoragePublishedFileVisibility.Private; return this; }
List<string> Tags;
Dictionary<string, string> KeyValueTags;
Dictionary<string, List<string>> KeyValueTags;
HashSet<string> KeyValueTagsToRemove;
public Editor WithTag( string tag )
{
@ -80,10 +81,37 @@ public Editor WithTag( string tag )
return this;
}
/// <summary>
/// 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.
/// </summary>
public Editor AddKeyValueTag(string key, string value)
{
if (KeyValueTags == null) KeyValueTags = new Dictionary<string, string>();
KeyValueTags.Add(key, value);
if (KeyValueTags == null)
KeyValueTags = new Dictionary<string, List<string>>();
if ( KeyValueTags.TryGetValue( key, out var list ) )
list.Add( value );
else
KeyValueTags[key] = new List<string>() { value };
return this;
}
/// <summary>
/// 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.
/// </summary>
public Editor RemoveKeyValueTags( string key )
{
if ( KeyValueTagsToRemove == null )
KeyValueTagsToRemove = new HashSet<string>();
KeyValueTagsToRemove.Add( key );
return this;
}
@ -156,11 +184,19 @@ public async Task<PublishResult> SubmitAsync( IProgress<float> 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 );
}
}