mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 14:15:47 +03:00
RichPresence
This commit is contained in:
parent
e4ddd1fe6c
commit
b134c8708f
@ -1,56 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Facepunch.Steamworks.Test
|
||||
{
|
||||
[TestClass]
|
||||
[DeploymentItem( "steam_api64.dll" )]
|
||||
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 ) )
|
||||
{
|
||||
var success = client.User.SetRichPresence( "One", "Two" );
|
||||
Assert.IsTrue( success );
|
||||
|
||||
var value = client.User.GetRichPresence( "One" );
|
||||
Assert.IsNotNull( value );
|
||||
Assert.AreEqual( value, "Two" );
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClearingKeys()
|
||||
{
|
||||
using ( var client = new Steamworks.Client( 252490 ) )
|
||||
{
|
||||
var success = client.User.SetRichPresence( "One", "Two" );
|
||||
Assert.IsTrue( success );
|
||||
|
||||
var value = client.User.GetRichPresence( "One" );
|
||||
Assert.IsNotNull( value );
|
||||
Assert.AreEqual( value, "Two" );
|
||||
|
||||
client.User.ClearRichPresence();
|
||||
|
||||
value = client.User.GetRichPresence( "One" );
|
||||
Assert.IsNull( value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -93,7 +93,6 @@
|
||||
<Compile Include="Client\UtilsTest.cs" />
|
||||
<Compile Include="Client\ClientTest.cs" />
|
||||
<Compile Include="Client\LobbyTest.cs" />
|
||||
<Compile Include="Client\RichPresenceTest.cs" />
|
||||
<Compile Include="Client\LeaderboardTest.cs" />
|
||||
<Compile Include="Client\AppTest.cs" />
|
||||
<Compile Include="Client\RemoteStorageTest.cs" />
|
||||
|
@ -63,7 +63,6 @@ public partial class Client : BaseSteamworks
|
||||
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 RemoteStorage RemoteStorage { get; private set; }
|
||||
|
||||
public Client( uint appId ) : base( appId )
|
||||
@ -106,7 +105,6 @@ public Client( uint appId ) : base( appId )
|
||||
Stats = new Stats( this );
|
||||
Achievements = new Achievements( this );
|
||||
MicroTransactions = new MicroTransactions( this );
|
||||
User = new User( this );
|
||||
RemoteStorage = new RemoteStorage( this );
|
||||
|
||||
Workshop.friends = Friends;
|
||||
@ -201,12 +199,6 @@ public override void Dispose()
|
||||
MicroTransactions = null;
|
||||
}
|
||||
|
||||
if ( User != null )
|
||||
{
|
||||
User.Dispose();
|
||||
User = null;
|
||||
}
|
||||
|
||||
if ( RemoteStorage != null )
|
||||
{
|
||||
RemoteStorage.Dispose();
|
||||
|
@ -1,57 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a rich presence value by key for current user. Will be null if not found.
|
||||
/// </summary>
|
||||
public string GetRichPresence( string key )
|
||||
{
|
||||
if ( richPresence.TryGetValue( key, out var val ) )
|
||||
return val;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a rich presence value by key for current user.
|
||||
/// </summary>
|
||||
public bool SetRichPresence( string key, string value )
|
||||
{
|
||||
richPresence[key] = value;
|
||||
return client.native.friends.SetRichPresence( key, value );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all of the current user's rich presence data.
|
||||
/// </summary>
|
||||
public void ClearRichPresence()
|
||||
{
|
||||
richPresence.Clear();
|
||||
client.native.friends.ClearRichPresence();
|
||||
}
|
||||
}
|
||||
}
|
@ -19,12 +19,18 @@ internal static Internal.ISteamFriends Internal
|
||||
get
|
||||
{
|
||||
if ( _internal == null )
|
||||
{
|
||||
_internal = new Internal.ISteamFriends();
|
||||
|
||||
richPresence = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
return _internal;
|
||||
}
|
||||
}
|
||||
|
||||
static Dictionary<string, string> richPresence;
|
||||
|
||||
internal static void InstallEvents()
|
||||
{
|
||||
//new Event<BroadcastUploadStart_t>( x => OnBroadcastStarted?.Invoke() );
|
||||
@ -161,5 +167,34 @@ static async Task CacheUserInformationAsync( CSteamID steamid, bool nameonly )
|
||||
return Utils.GetImage( imageid );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a rich presence value by key for current user. Will be null if not found.
|
||||
/// </summary>
|
||||
public static string GetRichPresence( string key )
|
||||
{
|
||||
if ( richPresence.TryGetValue( key, out var val ) )
|
||||
return val;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a rich presence value by key for current user.
|
||||
/// </summary>
|
||||
public static bool SetRichPresence( string key, string value )
|
||||
{
|
||||
richPresence[key] = value;
|
||||
return Internal.SetRichPresence( key, value );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all of the current user's rich presence data.
|
||||
/// </summary>
|
||||
public static void ClearRichPresence()
|
||||
{
|
||||
richPresence.Clear();
|
||||
Internal.ClearRichPresence();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user