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();
|
bool IsOnGameThread();
|
||||||
void Start();
|
void Start();
|
||||||
void Stop();
|
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 Save(long callerId);
|
||||||
void Init();
|
void Init();
|
||||||
T GetManager<T>() where T : class, IManager;
|
T GetManager<T>() where T : class, IManager;
|
||||||
|
@@ -222,11 +222,17 @@ namespace Torch.Server
|
|||||||
State = ServerState.Stopped;
|
State = ServerState.Stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public override void Save(long callerId)
|
public override void Save(long callerId)
|
||||||
{
|
{
|
||||||
base.SaveGameAsync((statusCode) => SaveCompleted(statusCode, 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)
|
private void SaveCompleted(SaveGameStatus statusCode, long callerId)
|
||||||
{
|
{
|
||||||
switch (statusCode)
|
switch (statusCode)
|
||||||
|
@@ -68,6 +68,10 @@ namespace Torch.Commands
|
|||||||
Context.Torch.Stop();
|
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.")]
|
[Command("save", "Saves the game.")]
|
||||||
public void Save()
|
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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ChatMessage.cs" />
|
<Compile Include="ChatMessage.cs" />
|
||||||
|
<Compile Include="SaveGameStatus.cs" />
|
||||||
<Compile Include="Collections\KeyTree.cs" />
|
<Compile Include="Collections\KeyTree.cs" />
|
||||||
<Compile Include="Collections\ObservableDictionary.cs" />
|
<Compile Include="Collections\ObservableDictionary.cs" />
|
||||||
<Compile Include="Collections\RollingAverage.cs" />
|
<Compile Include="Collections\RollingAverage.cs" />
|
||||||
|
@@ -31,14 +31,6 @@ using VRage.Utils;
|
|||||||
|
|
||||||
namespace Torch
|
namespace Torch
|
||||||
{
|
{
|
||||||
public enum SaveGameStatus : byte
|
|
||||||
{
|
|
||||||
Success = 0,
|
|
||||||
SaveInProgress = 1,
|
|
||||||
GameNotReady = 2,
|
|
||||||
TimedOut = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for code shared between the Torch client and server.
|
/// Base class for code shared between the Torch client and server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -123,11 +115,11 @@ namespace Torch
|
|||||||
|
|
||||||
if (!MySandboxGame.IsGameReady)
|
if (!MySandboxGame.IsGameReady)
|
||||||
{
|
{
|
||||||
callback(SaveGameStatus.GameNotReady);
|
callback?.Invoke(SaveGameStatus.GameNotReady);
|
||||||
}
|
}
|
||||||
else if(MyAsyncSaving.InProgress)
|
else if(MyAsyncSaving.InProgress)
|
||||||
{
|
{
|
||||||
callback(SaveGameStatus.SaveInProgress);
|
callback?.Invoke(SaveGameStatus.SaveInProgress);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -142,10 +134,12 @@ namespace Torch
|
|||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
if (e.WaitOne(60000))
|
if (e.WaitOne(60000))
|
||||||
callback(SaveGameStatus.Success);
|
{
|
||||||
return;
|
callback?.Invoke(SaveGameStatus.Success);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
callback(SaveGameStatus.TimedOut);
|
callback?.Invoke(SaveGameStatus.TimedOut);
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,6 +286,7 @@ namespace Torch
|
|||||||
pluginList.Add(this);
|
pluginList.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
public virtual void Save(long callerId)
|
public virtual void Save(long callerId)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user