Setting Rich Presence

This commit is contained in:
Garry Newman 2017-06-09 11:00:01 +01:00
parent b92fba15ec
commit 3752e75316
5 changed files with 115 additions and 1 deletions

View File

@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Facepunch.Steamworks.Test

View File

@ -0,0 +1,56 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Facepunch.Steamworks.Test
{
[TestClass]
[DeploymentItem( "steam_api.dll" )]
[DeploymentItem( "steam_api64.dll" )]
[DeploymentItem( "steam_appid.txt" )]
public class RichPresence
{
[TestMethod]
public void MissingKeyIsNull()
{
using ( var client = new Steamworks.Client( 252490 ) )
{
var key = client.User.GetRichPresence( "Missing Key" );
Assert.IsNull( key );
}
}
[TestMethod]
public void ReadBackSetKey()
{
using ( var client = new Steamworks.Client( 252490 ) )
{
client.User.SetRichPresence( "One", "Two" );
var value = client.User.GetRichPresence( "One" );
Assert.IsNotNull( value );
Assert.AreEqual( value, "Two" );
}
}
[TestMethod]
public void ClearingKeys()
{
using ( var client = new Steamworks.Client( 252490 ) )
{
client.User.SetRichPresence( "One", "Two" );
var value = client.User.GetRichPresence( "One" );
Assert.IsNotNull( value );
Assert.AreEqual( value, "Two" );
client.User.ClearRichPresence();
value = client.User.GetRichPresence( "One" );
Assert.IsNull( value );
}
}
}
}

View File

@ -94,6 +94,7 @@
<ItemGroup>
<Compile Include="Client\Achievements.cs" />
<Compile Include="Client\Client.cs" />
<Compile Include="Client\RichPresence.cs" />
<Compile Include="Client\Leaderboard.cs" />
<Compile Include="Client\App.cs" />
<Compile Include="Client\RemoteStorage.cs" />

View File

@ -59,6 +59,7 @@ namespace Facepunch.Steamworks
public Achievements Achievements { get; private set; }
public Stats Stats { get; private set; }
public MicroTransactions MicroTransactions { get; private set; }
public User User { get; private set; }
public Client( uint appId )
{
@ -89,6 +90,7 @@ namespace Facepunch.Steamworks
Stats = new Stats( this );
Achievements = new Achievements( this );
MicroTransactions = new MicroTransactions( this );
User = new User( this );
Workshop.friends = Friends;
@ -178,6 +180,12 @@ namespace Facepunch.Steamworks
MicroTransactions = null;
}
if ( User != null )
{
User.Dispose();
User = null;
}
if ( Instance == this )
{
Instance = null;

View File

@ -0,0 +1,50 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using SteamNative;
namespace Facepunch.Steamworks
{
public class User : IDisposable
{
internal Client client;
internal Dictionary<string, string> richPresence = new Dictionary<string, string>();
internal User( Client c )
{
client = c;
}
public void Dispose()
{
client = null;
}
public string GetRichPresence( string key )
{
string val = null;
if ( richPresence.TryGetValue( key, out val ) )
return val;
return null;
}
public void SetRichPresence( string key, string value )
{
richPresence[key] = value;
client.native.friends.SetRichPresence( key, value );
}
public void ClearRichPresence()
{
richPresence.Clear();
client.native.friends.ClearRichPresence();
}
}
}