From eaab977c631c4b6c8ccf3181aaa154c64b813108 Mon Sep 17 00:00:00 2001 From: siimav <1120038+siimav@users.noreply.github.com> Date: Thu, 20 Jun 2024 01:15:29 +0300 Subject: [PATCH] Apply TS uprades without needing a scene change (#19) --- .../Network/RACommNetNetwork.cs | 2 +- src/RealAntennasProject/RACommNetScenario.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/RealAntennasProject/Network/RACommNetNetwork.cs b/src/RealAntennasProject/Network/RACommNetNetwork.cs index 5d8ae77..a31d54e 100644 --- a/src/RealAntennasProject/Network/RACommNetNetwork.cs +++ b/src/RealAntennasProject/Network/RACommNetNetwork.cs @@ -57,7 +57,7 @@ protected virtual void Start() ResetNetwork(); } - protected new void ResetNetwork() + internal new void ResetNetwork() { Debug.Log($"{ModTag} ResetNetwork()"); diff --git a/src/RealAntennasProject/RACommNetScenario.cs b/src/RealAntennasProject/RACommNetScenario.cs index a685568..f0201c2 100644 --- a/src/RealAntennasProject/RACommNetScenario.cs +++ b/src/RealAntennasProject/RACommNetScenario.cs @@ -1,7 +1,9 @@ using CommNet; +using System; using System.Collections.Generic; using System.Reflection; using UnityEngine; +using Upgradeables; namespace RealAntennas { @@ -40,6 +42,7 @@ protected override void Start() ApplyGameSettings(); GameEvents.OnGameSettingsApplied.Add(ApplyGameSettings); + GameEvents.OnKSCFacilityUpgraded.Add(OnKSCFacilityUpgraded); } else StartCoroutine(NotifyDisabled()); } @@ -94,6 +97,7 @@ public void OnDestroy() if (Network) Destroy(Network); if (UI) Destroy(UI); GameEvents.OnGameSettingsApplied.Remove(ApplyGameSettings); + GameEvents.OnKSCFacilityUpgraded.Remove(OnKSCFacilityUpgraded); } public void RebuildHomes() @@ -114,6 +118,23 @@ private void ApplyGameSettings() debugWalkInterval = HighLogic.CurrentGame.Parameters.CustomParams().debugWalkInterval; } + private void OnKSCFacilityUpgraded(UpgradeableFacility facility, int lvl) + { + string tsFacId = ScenarioUpgradeableFacilities.SlashSanitize(nameof(SpaceCenterFacility.TrackingStation)); + if (string.Equals(facility.id, tsFacId, StringComparison.OrdinalIgnoreCase)) + { + ApplyTSLevelChange(); + } + } + + private void ApplyTSLevelChange() + { + Debug.LogFormat($"{ModTag} Applying TS level change"); + float fTSLvl = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation); + GroundStationTechLevel = Mathf.RoundToInt(MaxTL * (HighLogic.CurrentGame.Mode == Game.Modes.CAREER ? fTSLvl : 1)); + Network.ResetNetwork(); + } + private void Initialize() { if (!staticInit && GameDatabase.Instance.GetConfigNode("RealAntennas/RealAntennasCommNetParams/RealAntennasCommNetParams") is ConfigNode RAParamNode)