From d1d5810c3b56d69f6ce4dc1f7a6f3ee79cafb086 Mon Sep 17 00:00:00 2001 From: SokyranTheDragon Date: Mon, 6 Nov 2023 19:52:16 +0100 Subject: [PATCH] Slightly change how pause lock session works --- Source/Client/Comp/World/MultiplayerWorldComp.cs | 3 +++ Source/Client/Persistent/PauseLockSession.cs | 6 ++++-- Source/Client/Syncing/Sync.cs | 11 +++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Client/Comp/World/MultiplayerWorldComp.cs b/Source/Client/Comp/World/MultiplayerWorldComp.cs index c8e91a05..2e32d56c 100644 --- a/Source/Client/Comp/World/MultiplayerWorldComp.cs +++ b/Source/Client/Comp/World/MultiplayerWorldComp.cs @@ -37,6 +37,9 @@ public void ExposeData() Scribe_References.Look(ref spectatorFaction, "spectatorFaction"); sessionManager.ExposeSessions(); + // Ensure a pause lock session exists if there's any pause locks registered + if (!PauseLockSession.pauseLocks.NullOrEmpty()) + sessionManager.AddSession(new PauseLockSession()); DoBackCompat(); } diff --git a/Source/Client/Persistent/PauseLockSession.cs b/Source/Client/Persistent/PauseLockSession.cs index 0f85cc33..9a41158a 100644 --- a/Source/Client/Persistent/PauseLockSession.cs +++ b/Source/Client/Persistent/PauseLockSession.cs @@ -8,9 +8,9 @@ namespace Multiplayer.Client.Persistent; // Used for pause locks. Pause locks should become obsolete and this should become unused, // but pause locks are kept for backwards compatibility. -public class PauseLockSession : Session +public class PauseLockSession : Session, ISessionWithCreationRestrictions { - public List pauseLocks = new(); + public static List pauseLocks = new(); public override Map Map => null; @@ -18,4 +18,6 @@ public class PauseLockSession : Session // Should we add some message explaining pause locks/having a list of pausing ones? public override FloatMenuOption GetBlockingWindowOptions(ColonistBar.Entry entry) => null; + + public bool CanExistWith(ISession other) => other is not PauseLockSession; } diff --git a/Source/Client/Syncing/Sync.cs b/Source/Client/Syncing/Sync.cs index 4dc41823..f6a1c631 100644 --- a/Source/Client/Syncing/Sync.cs +++ b/Source/Client/Syncing/Sync.cs @@ -381,15 +381,10 @@ public static void RegisterPauseLock(MethodInfo method) public static void RegisterPauseLock(PauseLockDelegate pauseLock) { - var session = Multiplayer.WorldComp.sessionManager.GetFirstOfType(); - if (session == null) - { - // Only ever add pause lock session if we have any pause locks - session = new PauseLockSession(); - Multiplayer.WorldComp.sessionManager.AddSession(session); - } + if (PauseLockSession.pauseLocks.Contains(pauseLock)) + throw new Exception($"Pause lock already registered: {pauseLock}"); - session.pauseLocks.Add(pauseLock); + PauseLockSession.pauseLocks.Add(pauseLock); } public static void ValidateAll()