Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions HKMP/Api/Addon/AddonLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ protected List<TAddon> LoadAddons<TAddon>() {
}

addons.Add(addon);
// We only allow a single class extending the addon subclass
break;
}
}

Expand Down
7 changes: 6 additions & 1 deletion HKMP/Api/Client/IClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ public interface IClientManager {
/// Class that manages player locations on the in-game map.
/// </summary>
IMapManager MapManager { get; }


/// <summary>
/// Class that manages pause-related operations.
/// </summary>
IPauseManager PauseManager { get; }

/// <summary>
/// The current username of the local player.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions HKMP/Api/Client/IPauseManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Hkmp.Api.Client;

/// <summary>
/// Client-side class that handles pause-related operations.
/// </summary>
public interface IPauseManager {
/// <summary>
/// Event that is called when HKMP modifies the game's timescale.
/// </summary>
event Action<float> SetTimeScaleEvent;
}
16 changes: 13 additions & 3 deletions HKMP/Game/Client/ClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ internal class ClientManager : IClientManager {
/// </summary>
private readonly EntityManager _entityManager;

/// <summary>
/// The pause manager instance.
/// </summary>
private readonly PauseManager _pauseManager;

/// <summary>
/// The client addon manager instance.
/// </summary>
Expand All @@ -96,6 +101,9 @@ internal class ClientManager : IClientManager {
/// <inheritdoc />
public IMapManager MapManager => _mapManager;

/// <inheritdoc />
public IPauseManager PauseManager => _pauseManager;

/// <inheritdoc />
public string Username {
get {
Expand Down Expand Up @@ -180,7 +188,9 @@ ModSettings modSettings

_entityManager = new EntityManager(netClient);

new PauseManager(netClient).RegisterHooks();
_pauseManager = new PauseManager(netClient);
_pauseManager.RegisterHooks();

new FsmPatcher().RegisterHooks();

_commandManager = new ClientCommandManager();
Expand Down Expand Up @@ -327,7 +337,7 @@ private void InternalDisconnect() {

// Check whether the game is in the pause menu and reset timescale to 0 in that case
if (UIManager.instance.uiState.Equals(UIState.PAUSED)) {
PauseManager.SetTimeScale(0);
_pauseManager.SetTimeScale(0);
}

try {
Expand Down Expand Up @@ -485,7 +495,7 @@ private void OnClientConnect(LoginResponse loginResponse) {

// Since we are probably in the pause menu when we connect, set the timescale so the game
// is running while paused
PauseManager.SetTimeScale(1.0f);
_pauseManager.SetTimeScale(1.0f);

UiManager.InternalChatBox.AddMessage("You are connected to the server");
}
Expand Down
13 changes: 10 additions & 3 deletions HKMP/Game/Client/PauseManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections;
using System.Reflection;
using GlobalEnums;
using Hkmp.Api.Client;
using Hkmp.Networking.Client;
using Modding;
using UnityEngine;
Expand All @@ -10,11 +12,14 @@ namespace Hkmp.Game.Client;
/// <summary>
/// Handles pause related things to prevent player being invincible in pause menu while connected to a server.
/// </summary>
internal class PauseManager {
internal class PauseManager : IPauseManager {
/// <summary>
/// The net client instance.
/// </summary>
private readonly NetClient _netClient;

/// <inheritdoc />
public event Action<float> SetTimeScaleEvent;

public PauseManager(NetClient netClient) {
_netClient = netClient;
Expand Down Expand Up @@ -194,7 +199,9 @@ private static void ImmediateUnpauseIfPaused() {
/// Sets the time scale similarly to the method GameManager#SetTimeScale.
/// </summary>
/// <param name="timeScale">The new time scale.</param>
public static void SetTimeScale(float timeScale) {
TimeController.GenericTimeScale = timeScale > 0.00999999977648258 ? timeScale : 0.0f;
public void SetTimeScale(float timeScale) {
timeScale = timeScale > 0.00999999977648258 ? timeScale : 0.0f;
TimeController.GenericTimeScale = timeScale;
SetTimeScaleEvent?.Invoke(timeScale);
}
}
Loading