Merge pull request #423 from kamyker/key-value-tags

Ugc item key value tags
This commit is contained in:
Garry Newman 2020-05-15 07:31:24 +01:00 committed by GitHub
commit 9101b82450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 10 deletions

View File

@ -69,7 +69,8 @@ namespace Steamworks.Ugc
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 @@ namespace Steamworks.Ugc
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 @@ namespace Steamworks.Ugc
}
}
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 )
{
SteamUGC.Internal.AddItemKeyValueTag(handle, keyValueTag.Key, keyValueTag.Value);
foreach ( var keyWithValues in KeyValueTags )
{
var key = keyWithValues.Key;
foreach ( var value in keyWithValues.Value )
SteamUGC.Internal.AddItemKeyValueTag( handle, key, value );
}
}

View File

@ -39,6 +39,11 @@ namespace Steamworks.Ugc
/// </summary>
public string[] Tags { get; internal set; }
/// <summary>
/// A dictionary of key value tags for this item, only available from queries WithKeyValueTags(true)
/// </summary>
public Dictionary<string,string> KeyValueTags { get; internal set; }
/// <summary>
/// App Id of the app that created this item
/// </summary>

View File

@ -148,7 +148,8 @@ namespace Steamworks.Ugc
Handle = result.Value.Handle,
ResultCount = (int) result.Value.NumResultsReturned,
TotalCount = (int)result.Value.TotalMatchingResults,
CachedData = result.Value.CachedData
CachedData = result.Value.CachedData,
ReturnsKeyValueTags = WantsReturnKeyValueTags ?? false,
};
}
@ -241,6 +242,8 @@ namespace Steamworks.Ugc
bool? WantsReturnOnlyIDs;
public QueryType WithOnlyIDs(bool b) { WantsReturnOnlyIDs = b; return this; }
bool? WantsReturnKeyValueTags;
public QueryType WithKeyValueTags(bool b) { WantsReturnKeyValueTags = b; return this; }
[Obsolete( "Renamed to WithKeyValueTags" )]
public QueryType WithKeyValueTag(bool b) { WantsReturnKeyValueTags = b; return this; }
bool? WantsReturnLongDescription;
public QueryType WithLongDescription(bool b) { WantsReturnLongDescription = b; return this; }

View File

@ -12,6 +12,7 @@ namespace Steamworks.Ugc
public bool CachedData;
internal bool ReturnsKeyValueTags;
public IEnumerable<Item> Entries
{
get
@ -43,9 +44,21 @@ namespace Steamworks.Ugc
item.PreviewImageUrl = preview;
}
if ( ReturnsKeyValueTags )
{
var keyValueTagsCount = SteamUGC.Internal.GetQueryUGCNumKeyValueTags( Handle, i );
item.KeyValueTags = new Dictionary<string, string>( (int)keyValueTagsCount );
for ( uint j = 0; j < keyValueTagsCount; j++ )
{
string key, value;
if ( SteamUGC.Internal.GetQueryUGCKeyValueTag( Handle, i, j, out key, out value ) )
item.KeyValueTags[key] = value;
}
}
// TODO GetQueryUGCAdditionalPreview
// TODO GetQueryUGCChildren
// TODO GetQueryUGCKeyValueTag
// TODO GetQueryUGCMetadata