From 79fe93e804fdd364adbb12215b1d1a0dd3a3e0a9 Mon Sep 17 00:00:00 2001 From: rio <2745352+jason-e@users.noreply.github.com> Date: Sat, 14 Oct 2023 21:49:56 -0400 Subject: [PATCH] fix: Don't do cgaz updates on modes that aren't defrag --- scripts/hud/cgaz.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/scripts/hud/cgaz.js b/scripts/hud/cgaz.js index 89dc17b7..647efd61 100644 --- a/scripts/hud/cgaz.js +++ b/scripts/hud/cgaz.js @@ -121,17 +121,28 @@ class Cgaz { static snapAccel = 0; static bShouldUpdateStyles = false; + static updateHandle = null; + static onLoad() { - if (GameModeAPI.GetCurrentGameMode() !== GameMode.DEFRAG) return; - - this.onAccelConfigChange(); - this.onSnapConfigChange(); - this.onPrimeConfigChange(); - this.onProjectionChange(); - this.onHudFovChange(); - this.onSnapConfigChange(); - this.onWindicatorConfigChange(); - this.onCompassConfigChange(); + if (GameModeAPI.GetCurrentGameMode() === GameMode.DEFRAG) { + this.updateHandle = $.RegisterEventHandler( + 'ChaosHudProcessInput', + $.GetContextPanel(), + this.onUpdate.bind(this) + ); + + this.onAccelConfigChange(); + this.onSnapConfigChange(); + this.onPrimeConfigChange(); + this.onProjectionChange(); + this.onHudFovChange(); + this.onSnapConfigChange(); + this.onWindicatorConfigChange(); + this.onCompassConfigChange(); + } else if (this.updateHandle) { + $.UnregisterEventHandler('ChaosHudProcessInput', $.GetContextPanel(), this.updateHandle); + this.updateHandle = null; + } } static onProjectionChange() { @@ -1333,8 +1344,6 @@ class Cgaz { } static { - $.RegisterEventHandler('ChaosHudProcessInput', $.GetContextPanel(), this.onUpdate.bind(this)); - $.RegisterForUnhandledEvent('ChaosLevelInitPostEntity', this.onLoad.bind(this)); $.RegisterForUnhandledEvent('OnDefragHUDProjectionChange', this.onProjectionChange.bind(this)); $.RegisterForUnhandledEvent('OnDefragHUDFOVChange', this.onHudFovChange.bind(this));