Skip to content

Commit

Permalink
Slightly change how pause lock session works
Browse files Browse the repository at this point in the history
  • Loading branch information
SokyranTheDragon committed Nov 6, 2023
1 parent a3438f8 commit d1d5810
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Source/Client/Comp/World/MultiplayerWorldComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 4 additions & 2 deletions Source/Client/Persistent/PauseLockSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ 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<PauseLockDelegate> pauseLocks = new();
public static List<PauseLockDelegate> pauseLocks = new();

public override Map Map => null;

public override bool IsCurrentlyPausing(Map map) => pauseLocks.Any(x => x(map));

// 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;
}
11 changes: 3 additions & 8 deletions Source/Client/Syncing/Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,10 @@ public static void RegisterPauseLock(MethodInfo method)

public static void RegisterPauseLock(PauseLockDelegate pauseLock)
{
var session = Multiplayer.WorldComp.sessionManager.GetFirstOfType<PauseLockSession>();
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()
Expand Down

0 comments on commit d1d5810

Please sign in to comment.