Skip to content

Commit

Permalink
Fix crew xfer window nullref issue
Browse files Browse the repository at this point in the history
  • Loading branch information
T.J. Deckard committed Oct 4, 2021
1 parent 0bca9e5 commit 29b61b8
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions Source/WOLF/WOLF/Modules/WOLF_CrewTransferScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ namespace WOLF
public class WOLF_CrewTransferScenario : ScenarioModule, ICrewTransferController
{
private const float TERMINAL_RANGE = 500f;
private static readonly List<PrefabDefinition> _prefabDefs = new List<PrefabDefinition>
{
new PrefabDefinition<FlightSelector>(PrefabType.Prefab),
new PrefabDefinition<KerbalSelector>(PrefabType.Prefab),
new PrefabDefinition<WarningPanel>(PrefabType.Prefab),
new PrefabDefinition<TerminalWindow>(PrefabType.Window),
};

private readonly ArrivalWarnings _arrivalWarnings = new ArrivalWarnings();
private readonly Dictionary<string, WarningMetadata> _activeWarnings
Expand Down Expand Up @@ -729,7 +736,10 @@ public override void OnAwake()
base.OnAwake();

GetLocalizedTextValues();
}

private void Start()
{
var wolfScenario = FindObjectOfType<WOLF_ScenarioModule>();
_wolf = wolfScenario.ServiceManager.GetService<IRegistryCollection>();

Expand All @@ -738,30 +748,16 @@ public override void OnAwake()
{
var serviceManager = usiTools.ServiceManager;
var windowManager = serviceManager.GetService<WindowManager>();
var prefabManager = serviceManager.GetService<PrefabManager>();

try
{
// Setup UI prefabs
// Load and register UI prefabs
var filepath = Path.Combine(KSPUtil.ApplicationRootPath,
"GameData/UmbraSpaceIndustries/WOLF/Assets/UI/CrewTransferWindow.prefabs");
var prefabs = AssetBundle.LoadFromFile(filepath);
var flightSelectorPrefab = prefabs.LoadAsset<GameObject>("FlightSelector");
var kerbalSelectorPrefab = prefabs.LoadAsset<GameObject>("KerbalSelector");
var terminalWindowPrefab = prefabs.LoadAsset<GameObject>("TerminalWindow");
var warningPanelPrefab = prefabs.LoadAsset<GameObject>("WarningPanel");

// Register prefabs with window manager
windowManager
.RegisterPrefab<FlightSelector>(flightSelectorPrefab)
.RegisterPrefab<KerbalSelector>(kerbalSelectorPrefab)
.RegisterPrefab<WarningPanel>(warningPanelPrefab)
.RegisterWindow<TerminalWindow>(terminalWindowPrefab);
prefabManager.LoadAssetBundle(filepath, _prefabDefs);
}
catch (ServiceAlreadyRegisteredException) { }
catch (NullReferenceException)
{
// TODO - Create an asset bundle loader service in USITools
}
catch (Exception ex)
{
Debug.LogError($"[WOLF] {ClassName}: {ex.Message}");
Expand Down

0 comments on commit 29b61b8

Please sign in to comment.