Add IGameLifecycle (#1287)

This commit is contained in:
MidoriKami 2023-06-24 23:36:58 -07:00 committed by GitHub
parent 8a6269c178
commit 0ac5c240f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 10 deletions

View file

@ -2,6 +2,7 @@
using Dalamud.IoC;
using Dalamud.IoC.Internal;
using Dalamud.Plugin.Services;
namespace Dalamud.Game;
@ -11,7 +12,10 @@ namespace Dalamud.Game;
[PluginInterface]
[InterfaceVersion("1.0")]
[ServiceManager.BlockingEarlyLoadedService]
public class GameLifecycle : IServiceType
#pragma warning disable SA1015
[ResolveVia<IGameLifecycle>]
#pragma warning restore SA1015
public class GameLifecycle : IServiceType, IGameLifecycle
{
private readonly CancellationTokenSource dalamudUnloadCts = new();
private readonly CancellationTokenSource gameShutdownCts = new();
@ -26,19 +30,13 @@ public class GameLifecycle : IServiceType
{
}
/// <summary>
/// Gets a token that is cancelled when Dalamud is unloading.
/// </summary>
/// <inheritdoc/>
public CancellationToken DalamudUnloadingToken => this.dalamudUnloadCts.Token;
/// <summary>
/// Gets a token that is cancelled when the game is shutting down.
/// </summary>
/// <inheritdoc/>
public CancellationToken GameShuttingDownToken => this.gameShutdownCts.Token;
/// <summary>
/// Gets a token that is cancelled when a character is logging out.
/// </summary>
/// <inheritdoc/>
public CancellationToken LogoutToken => this.logoutCts.Token;
/// <summary>

View file

@ -0,0 +1,24 @@
using System.Threading;
namespace Dalamud.Plugin.Services;
/// <summary>
/// Class offering cancellation tokens for common gameplay events.
/// </summary>
public interface IGameLifecycle
{
/// <summary>
/// Gets a token that is cancelled when Dalamud is unloading.
/// </summary>
public CancellationToken DalamudUnloadingToken { get; }
/// <summary>
/// Gets a token that is cancelled when the game is shutting down.
/// </summary>
public CancellationToken GameShuttingDownToken { get; }
/// <summary>
/// Gets a token that is cancelled when a character is logging out.
/// </summary>
public CancellationToken LogoutToken { get; }
}