Skip to content

Commit

Permalink
Apply TS uprades without needing a scene change (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav authored Jun 19, 2024
1 parent ae4a376 commit eaab977
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/RealAntennasProject/Network/RACommNetNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected virtual void Start()
ResetNetwork();
}

protected new void ResetNetwork()
internal new void ResetNetwork()
{
Debug.Log($"{ModTag} ResetNetwork()");

Expand Down
21 changes: 21 additions & 0 deletions src/RealAntennasProject/RACommNetScenario.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using CommNet;
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using Upgradeables;

namespace RealAntennas
{
Expand Down Expand Up @@ -40,6 +42,7 @@ protected override void Start()

ApplyGameSettings();
GameEvents.OnGameSettingsApplied.Add(ApplyGameSettings);
GameEvents.OnKSCFacilityUpgraded.Add(OnKSCFacilityUpgraded);
}
else StartCoroutine(NotifyDisabled());
}
Expand Down Expand Up @@ -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()
Expand All @@ -114,6 +118,23 @@ private void ApplyGameSettings()
debugWalkInterval = HighLogic.CurrentGame.Parameters.CustomParams<RAParameters>().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)
Expand Down

0 comments on commit eaab977

Please sign in to comment.