mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-24 04:28:00 +03:00
Setting Rich Presence
This commit is contained in:
parent
b92fba15ec
commit
3752e75316
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
namespace Facepunch.Steamworks.Test
|
namespace Facepunch.Steamworks.Test
|
||||||
|
56
Facepunch.Steamworks.Test/Client/RichPresence.cs
Normal file
56
Facepunch.Steamworks.Test/Client/RichPresence.cs
Normal 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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -94,6 +94,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Client\Achievements.cs" />
|
<Compile Include="Client\Achievements.cs" />
|
||||||
<Compile Include="Client\Client.cs" />
|
<Compile Include="Client\Client.cs" />
|
||||||
|
<Compile Include="Client\RichPresence.cs" />
|
||||||
<Compile Include="Client\Leaderboard.cs" />
|
<Compile Include="Client\Leaderboard.cs" />
|
||||||
<Compile Include="Client\App.cs" />
|
<Compile Include="Client\App.cs" />
|
||||||
<Compile Include="Client\RemoteStorage.cs" />
|
<Compile Include="Client\RemoteStorage.cs" />
|
||||||
|
@ -59,6 +59,7 @@ namespace Facepunch.Steamworks
|
|||||||
public Achievements Achievements { get; private set; }
|
public Achievements Achievements { get; private set; }
|
||||||
public Stats Stats { get; private set; }
|
public Stats Stats { get; private set; }
|
||||||
public MicroTransactions MicroTransactions { get; private set; }
|
public MicroTransactions MicroTransactions { get; private set; }
|
||||||
|
public User User { get; private set; }
|
||||||
|
|
||||||
public Client( uint appId )
|
public Client( uint appId )
|
||||||
{
|
{
|
||||||
@ -89,6 +90,7 @@ namespace Facepunch.Steamworks
|
|||||||
Stats = new Stats( this );
|
Stats = new Stats( this );
|
||||||
Achievements = new Achievements( this );
|
Achievements = new Achievements( this );
|
||||||
MicroTransactions = new MicroTransactions( this );
|
MicroTransactions = new MicroTransactions( this );
|
||||||
|
User = new User( this );
|
||||||
|
|
||||||
Workshop.friends = Friends;
|
Workshop.friends = Friends;
|
||||||
|
|
||||||
@ -178,6 +180,12 @@ namespace Facepunch.Steamworks
|
|||||||
MicroTransactions = null;
|
MicroTransactions = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( User != null )
|
||||||
|
{
|
||||||
|
User.Dispose();
|
||||||
|
User = null;
|
||||||
|
}
|
||||||
|
|
||||||
if ( Instance == this )
|
if ( Instance == this )
|
||||||
{
|
{
|
||||||
Instance = null;
|
Instance = null;
|
||||||
|
50
Facepunch.Steamworks/Client/User.cs
Normal file
50
Facepunch.Steamworks/Client/User.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user