95% bound SteamParties, even though I am doubting its usefulness

This commit is contained in:
Garry Newman 2019-05-01 22:29:42 +01:00
parent 93c4de7eda
commit 068beddc04
3 changed files with 158 additions and 0 deletions

View File

@ -42,6 +42,7 @@ public static void Init( uint appid )
SteamInventory.InstallEvents();
SteamNetworking.InstallEvents();
SteamMatchmaking.InstallEvents();
SteamParties.InstallEvents();
RunCallbacksAsync();
}
@ -82,6 +83,7 @@ public static void Shutdown()
SteamInventory.Shutdown();
SteamNetworking.Shutdown();
SteamMatchmaking.Shutdown();
SteamParties.Shutdown();
SteamAPI.Shutdown();
}

View File

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Steamworks.Data;
namespace Steamworks
{
public static class SteamParties
{
static ISteamParties _internal;
internal static ISteamParties Internal
{
get
{
if ( _internal == null )
_internal = new ISteamParties();
return _internal;
}
}
internal static void Shutdown()
{
_internal = null;
}
internal static void InstallEvents()
{
AvailableBeaconLocationsUpdated_t.Install( x => OnBeaconLocationsUpdated?.Invoke() );
ActiveBeaconsUpdated_t.Install( x => OnBeaconLocationsUpdated?.Invoke() );
}
/// <summary>
/// The list of possible Party beacon locations has changed
/// </summary>
public static event Action OnBeaconLocationsUpdated;
/// <summary>
/// The list of active beacons may have changed
/// </summary>
public static event Action OnActiveBeaconsUpdated;
public static int ActiveBeaconCount => (int) Internal.GetNumActiveBeacons();
public static IEnumerable<PartyBeacon> ActiveBeacons
{
get
{
for ( uint i = 0; i < ActiveBeaconCount; i++ )
{
yield return new PartyBeacon
{
Id = Internal.GetBeaconByIndex( i )
};
}
}
}
/// <summary>
/// Create a new party beacon and activate it in the selected location.
/// When people begin responding to your beacon, Steam will send you
/// OnPartyReservation callbacks to let you know who is on the way.
/// </summary>
//public async Task<PartyBeacon?> CreateBeacon( int slots, string connectString, string meta )
//{
// var result = await Internal.CreateBeacon( (uint)slots, null, connectString, meta );
// if ( !result.HasValue ) return null;
//}
// TODO - is this useful to anyone, or is it a load of shit?
}
}

View File

@ -0,0 +1,82 @@
using System.Threading.Tasks;
using Steamworks.Data;
namespace Steamworks
{
public struct PartyBeacon
{
static ISteamParties Internal => SteamParties.Internal;
internal PartyBeaconID_t Id;
/// <summary>
/// Creator of the beacon
/// </summary>
public SteamId Owner
{
get
{
var owner = default( SteamId );
var location = default( SteamPartyBeaconLocation_t );
var sb = Helpers.TakeStringBuilder();
Internal.GetBeaconDetails( Id, ref owner, ref location, sb, sb.Capacity );
return owner;
}
}
/// <summary>
/// Creator of the beacon
/// </summary>
public string MetaData
{
get
{
var owner = default( SteamId );
var location = default( SteamPartyBeaconLocation_t );
var sb = Helpers.TakeStringBuilder();
Internal.GetBeaconDetails( Id, ref owner, ref location, sb, sb.Capacity );
return sb.ToString();
}
}
/// <summary>
/// Will attempt to join the party. If successful will return a connection string.
/// If failed, will return null
/// </summary>
public async Task<string> JoinAsync()
{
var result = await Internal.JoinParty( Id );
if ( !result.HasValue || result.Value.Result != Result.OK )
return null;
return result.Value.ConnectString;
}
/// <summary>
/// When a user follows your beacon, Steam will reserve one of the open party slots for them, and send your game a ReservationNotification callback.
/// When that user joins your party, call OnReservationCompleted to notify Steam that the user has joined successfully
/// </summary>
public void OnReservationCompleted( SteamId steamid )
{
Internal.OnReservationCompleted( Id, steamid );
}
/// <summary>
/// To cancel a reservation (due to timeout or user input), call this.
/// Steam will open a new reservation slot.
/// Note: The user may already be in-flight to your game, so it's possible they will still connect and try to join your party.
/// </summary>
public void CancelReservation( SteamId steamid )
{
Internal.CancelReservation( Id, steamid );
}
/// <summary>
/// Turn off the beacon
/// </summary>
public bool Destroy()
{
return Internal.DestroyBeacon( Id );
}
}
}