Private session field of proper type
Project Setup
This commit is contained in:
@@ -176,6 +176,7 @@
|
||||
<Compile Include="ServerState.cs" />
|
||||
<Compile Include="ModAPI\TorchAPI.cs" />
|
||||
<Compile Include="Session\ITorchSession.cs" />
|
||||
<Compile Include="Session\ITorchSessionManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
@@ -12,14 +12,15 @@ using Torch.Session;
|
||||
|
||||
namespace Torch.Session
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Manages the creation and destruction of <see cref="TorchSession"/> instances for each <see cref="MySession"/> created by Space Engineers.
|
||||
/// </summary>
|
||||
public class TorchSessionManager : Manager, ITorchSessionManager
|
||||
{
|
||||
private TorchSession _currentSession;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ITorchSession CurrentSession { get; private set; }
|
||||
public ITorchSession CurrentSession => _currentSession;
|
||||
|
||||
private readonly HashSet<SessionManagerFactory> _factories = new HashSet<SessionManagerFactory>();
|
||||
|
||||
@@ -45,8 +46,8 @@ namespace Torch.Session
|
||||
|
||||
private void SessionLoaded()
|
||||
{
|
||||
(CurrentSession as TorchSession)?.Detach();
|
||||
CurrentSession = new TorchSession(Torch, MySession.Static);
|
||||
_currentSession?.Detach();
|
||||
_currentSession = new TorchSession(Torch, MySession.Static);
|
||||
foreach (SessionManagerFactory factory in _factories)
|
||||
{
|
||||
IManager manager = factory(CurrentSession);
|
||||
@@ -58,8 +59,8 @@ namespace Torch.Session
|
||||
|
||||
private void SessionUnloaded()
|
||||
{
|
||||
(CurrentSession as TorchSession)?.Detach();
|
||||
CurrentSession = null;
|
||||
_currentSession?.Detach();
|
||||
_currentSession = null;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -72,6 +73,8 @@ namespace Torch.Session
|
||||
/// <inheritdoc/>
|
||||
public override void Detach()
|
||||
{
|
||||
_currentSession?.Detach();
|
||||
_currentSession = null;
|
||||
MySession.AfterLoading -= SessionLoaded;
|
||||
MySession.OnUnloaded -= SessionUnloaded;
|
||||
}
|
||||
|
@@ -151,7 +151,6 @@
|
||||
<Compile Include="Collections\ObservableList.cs" />
|
||||
<Compile Include="DispatcherExtensions.cs" />
|
||||
<Compile Include="Managers\DependencyManager.cs" />
|
||||
<Compile Include="Managers\SessionManager.cs" />
|
||||
<Compile Include="SaveGameStatus.cs" />
|
||||
<Compile Include="Collections\KeyTree.cs" />
|
||||
<Compile Include="Collections\ObservableDictionary.cs" />
|
||||
@@ -181,6 +180,7 @@
|
||||
<Compile Include="Managers\ScriptingManager.cs" />
|
||||
<Compile Include="Utils\TorchAssemblyResolver.cs" />
|
||||
<Compile Include="Utils\ReflectedManager.cs" />
|
||||
<Compile Include="Session\TorchSessionManager.cs" />
|
||||
<Compile Include="TorchBase.cs" />
|
||||
<Compile Include="SteamService.cs" />
|
||||
<Compile Include="TorchPluginBase.cs" />
|
||||
|
Reference in New Issue
Block a user