Moved SaveGameStatus to seperate file, guarded against null callbacks and added documentation
This commit is contained in:
@@ -25,6 +25,10 @@ namespace Torch.API
|
||||
bool IsOnGameThread();
|
||||
void Start();
|
||||
void Stop();
|
||||
/// <summary>
|
||||
/// Initializes a save of the game.
|
||||
/// </summary>
|
||||
/// <param name="callerId">Id of the player who initiated the save.</param>
|
||||
void Save(long callerId);
|
||||
void Init();
|
||||
T GetManager<T>() where T : class, IManager;
|
||||
|
@@ -222,11 +222,17 @@ namespace Torch.Server
|
||||
State = ServerState.Stopped;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Save(long callerId)
|
||||
{
|
||||
base.SaveGameAsync((statusCode) => SaveCompleted(statusCode, callerId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for when save has finished.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">Return code of the save operation</param>
|
||||
/// <param name="callerId">Caller of the save operation</param>
|
||||
private void SaveCompleted(SaveGameStatus statusCode, long callerId)
|
||||
{
|
||||
switch (statusCode)
|
||||
|
@@ -68,6 +68,10 @@ namespace Torch.Commands
|
||||
Context.Torch.Stop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a save of the game.
|
||||
/// Caller id defaults to 0 in the case of triggering the chat command from server.
|
||||
/// </summary>
|
||||
[Command("save", "Saves the game.")]
|
||||
public void Save()
|
||||
{
|
||||
|
13
Torch/SaveGameStatus.cs
Normal file
13
Torch/SaveGameStatus.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Torch
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes the possible outcomes when attempting to save the game progress.
|
||||
/// </summary>
|
||||
public enum SaveGameStatus : byte
|
||||
{
|
||||
Success = 0,
|
||||
SaveInProgress = 1,
|
||||
GameNotReady = 2,
|
||||
TimedOut = 3
|
||||
};
|
||||
}
|
@@ -144,6 +144,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ChatMessage.cs" />
|
||||
<Compile Include="SaveGameStatus.cs" />
|
||||
<Compile Include="Collections\KeyTree.cs" />
|
||||
<Compile Include="Collections\ObservableDictionary.cs" />
|
||||
<Compile Include="Collections\RollingAverage.cs" />
|
||||
|
@@ -31,14 +31,6 @@ using VRage.Utils;
|
||||
|
||||
namespace Torch
|
||||
{
|
||||
public enum SaveGameStatus : byte
|
||||
{
|
||||
Success = 0,
|
||||
SaveInProgress = 1,
|
||||
GameNotReady = 2,
|
||||
TimedOut = 3
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Base class for code shared between the Torch client and server.
|
||||
/// </summary>
|
||||
@@ -123,11 +115,11 @@ namespace Torch
|
||||
|
||||
if (!MySandboxGame.IsGameReady)
|
||||
{
|
||||
callback(SaveGameStatus.GameNotReady);
|
||||
callback?.Invoke(SaveGameStatus.GameNotReady);
|
||||
}
|
||||
else if(MyAsyncSaving.InProgress)
|
||||
{
|
||||
callback(SaveGameStatus.SaveInProgress);
|
||||
callback?.Invoke(SaveGameStatus.SaveInProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -142,10 +134,12 @@ namespace Torch
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (e.WaitOne(60000))
|
||||
callback(SaveGameStatus.Success);
|
||||
return;
|
||||
{
|
||||
callback?.Invoke(SaveGameStatus.Success);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(SaveGameStatus.TimedOut);
|
||||
callback?.Invoke(SaveGameStatus.TimedOut);
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -292,6 +286,7 @@ namespace Torch
|
||||
pluginList.Add(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void Save(long callerId)
|
||||
{
|
||||
|
||||
|
Reference in New Issue
Block a user