Skip to content

Commit

Permalink
Module.IsPaused module tick override
Browse files Browse the repository at this point in the history
  • Loading branch information
marchellc committed Aug 6, 2024
1 parent 91d2885 commit d739d84
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 1 addition & 2 deletions LabExtended/API/Hints/HintModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class HintModule : GenericModule<ExPlayer>
private int _idClock = 0;

internal string _globalText;
internal bool _paused;

public IReadOnlyList<HintElement> Elements => _activeElements;

Expand Down Expand Up @@ -213,7 +212,7 @@ public void ClearElements()

internal void InternalTick()
{
if (_paused)
if (IsPaused)
return;

_temporaryElement.CheckDuration();
Expand Down
10 changes: 7 additions & 3 deletions LabExtended/API/Modules/Module.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using LabExtended.Core;
using LabExtended.Core.Ticking;
using LabExtended.Extensions;
using LabExtended.Core.Ticking;

namespace LabExtended.API.Modules
{
Expand Down Expand Up @@ -29,6 +28,11 @@ public class Module
/// </summary>
public bool IsActive { get; internal set; }

/// <summary>
/// Gets or sets a value indicating whether or not this module's tick method is paused.
/// </summary>
public bool IsPaused { get; set; }

/// <summary>
/// Gets the module's parent.
/// </summary>
Expand Down Expand Up @@ -243,7 +247,7 @@ public virtual bool ValidateAdd(Module module)

internal void TickModule()
{
if (TickTimer is null || TickInfo is null || !IsActive)
if (TickTimer is null || TickInfo is null || !IsActive || IsPaused)
return;

OnTick();
Expand Down
6 changes: 3 additions & 3 deletions LabExtended/Patches/Functions/HintPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public static bool Prefix(HintDisplay __instance, Hint hint)
if (HintDisplay.SuppressedReceivers.Contains(__instance.connectionToClient))
return false;

if (!ExPlayer.TryGet(__instance.connectionToClient, out var player) || player.Hints._paused)
if (!ExPlayer.TryGet(__instance.connectionToClient, out var player) || player.Hints.IsPaused)
return true;

player.Hints._paused = true;
player.Hints.IsPaused = true;
player.Connection.Send(new HintMessage(hint));

Timing.CallDelayed(hint.DurationScalar + (player.Ping * 10), () => player.Hints._paused = false);
Timing.CallDelayed(hint.DurationScalar + 0.1f, () => player.Hints.IsPaused = false);
return false;
}
}
Expand Down

0 comments on commit d739d84

Please sign in to comment.