Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply TS upgrades without needing a scene change #19

Merged
merged 1 commit into from
Jun 19, 2024
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: 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
Loading