-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaunchControl.cs
More file actions
279 lines (235 loc) · 9.96 KB
/
Copy pathLaunchControl.cs
File metadata and controls
279 lines (235 loc) · 9.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
using System;
using System.Collections.Generic;
using Ostranauts.Bit.Items;
using Ostranauts.Bit.Commands;
using Ostranauts.Bit.MegaTooltip;
using Ostranauts.Bit.PersistentData;
using Ostranauts.Bit.Patches;
using Ostranauts.Bit.Interactions;
using Ostranauts.Bit.Pledges;
using Ostranauts.Bit.Tasks;
using Ostranauts.Bit.PatchSystem;
using Ostranauts.UI.MegaToolTip.Interfaces;
using UnityEngine;
namespace Ostranauts.Bit
{
/// <summary>
/// LaunchControl singleton providing command registration and utility functions
/// </summary>
public class LaunchControl : MonoBehaviour
{
private static LaunchControl _instance;
private MegaTooltipManager _megaTooltipManager;
private CommandManager _commandManager;
private ItemManager _itemManager;
private PersistentDataManager _persistentDataManager;
private InteractionManager _interactionManager;
private PledgeManager _pledgeManager;
private TaskDataProvider _taskDataProvider;
private PatchSystem.PatchManager _patchManager;
/// <summary>
/// Event fired when the game has finished loading all ships and is ready for the player.
/// This occurs after loading is complete but before the game unpauses.
/// Mods can subscribe to this to perform initialization tasks on existing saves.
/// </summary>
public static event Action OnGameReady;
/// <summary>
/// Item manager instance
/// </summary>
public ItemManager Items
{
get { return _itemManager; }
}
/// <summary>
/// Command manager instance
/// </summary>
public CommandManager Commands
{
get { return _commandManager; }
}
/// <summary>
/// Singleton instance of LaunchControl
/// </summary>
public static LaunchControl Instance
{
get { return _instance; }
private set { _instance = value; }
}
/// <summary>
/// MegaTooltip manager instance
/// </summary>
public MegaTooltipManager MegaTooltipManager
{
get { return _megaTooltipManager; }
}
/// <summary>
/// Persistent data manager instance
/// </summary>
public PersistentDataManager PersistentData
{
get { return _persistentDataManager; }
}
/// <summary>
/// Interaction manager instance for registering custom effects and managing interaction data
/// </summary>
public InteractionManager Interactions
{
get { return _interactionManager; }
}
/// <summary>
/// Pledge manager instance for registering custom pledge types
/// </summary>
public PledgeManager Pledges
{
get { return _pledgeManager; }
}
/// <summary>
/// Task data provider instance for storing custom metadata on Task2 instances
/// </summary>
public TaskDataProvider Tasks
{
get { return _taskDataProvider; }
}
/// <summary>
/// Patch manager instance for applying JSON patches to game data
/// </summary>
public PatchSystem.PatchManager PatchManager
{
get { return _patchManager; }
}
private void Awake()
{
if (_instance != null && _instance != this)
{
LaunchControlPlugin.Logger.LogWarning("Multiple LaunchControl instances detected! Destroying duplicate.");
Destroy(gameObject);
return;
}
_instance = this;
// Initialize MegaTooltipManager
_megaTooltipManager = new MegaTooltipManager(gameObject);
_itemManager = new ItemManager();
_commandManager = new CommandManager();
// Initialize InteractionManager
_interactionManager = new InteractionManager();
// Initialize PledgeManager
_pledgeManager = new PledgeManager();
_pledgeManager.SetLogger(LaunchControlPlugin.Logger);
// Initialize PersistentDataManager
try
{
_persistentDataManager = PersistentDataManager.Instance;
_persistentDataManager.SetLogger(LaunchControlPlugin.Logger);
// Initialize the persistent data load listener
PersistentDataPatches.InitializeLoadListener();
LaunchControlPlugin.Logger.LogInfo("PersistentData system initialized");
}
catch (System.Exception ex)
{
LaunchControlPlugin.Logger.LogError($"Failed to initialize PersistentData system: {ex.Message}");
LaunchControlPlugin.Logger.LogError(ex.StackTrace);
}
// Initialize TaskDataProvider and register TaskDataHandler
try
{
_taskDataProvider = TaskDataProvider.Instance;
TaskDataHandler taskHandler = new TaskDataHandler();
taskHandler.Logger = LaunchControlPlugin.Logger;
_persistentDataManager.RegisterHandler("LaunchControl.tasks", taskHandler);
LaunchControlPlugin.Logger.LogInfo("Task data system initialized");
}
catch (System.Exception ex)
{
LaunchControlPlugin.Logger.LogError($"Failed to initialize Task data system: {ex.Message}");
LaunchControlPlugin.Logger.LogError(ex.StackTrace);
}
// Initialize PatchManager
try
{
_patchManager = new PatchSystem.PatchManager(LaunchControlPlugin.Logger);
LaunchControlPlugin.Logger.LogInfo("Patch system initialized");
}
catch (System.Exception ex)
{
LaunchControlPlugin.Logger.LogError($"Failed to initialize Patch system: {ex.Message}");
LaunchControlPlugin.Logger.LogError(ex.StackTrace);
}
// Subscribe to game load complete event
try
{
CrewSim.OnGameFinishedLoading.AddListener(OnCrewSimGameFinishedLoading);
LaunchControlPlugin.Logger.LogInfo("Subscribed to game load complete event");
}
catch (System.Exception ex)
{
LaunchControlPlugin.Logger.LogError($"Failed to subscribe to game load event: {ex.Message}");
LaunchControlPlugin.Logger.LogError(ex.StackTrace);
}
LaunchControlPlugin.Logger.LogInfo("LaunchControl instance initialized");
}
/// <summary>
/// Called when CrewSim finishes loading the game
/// </summary>
private void OnCrewSimGameFinishedLoading()
{
LaunchControlPlugin.Logger.LogInfo("Game finished loading - firing OnGameReady event");
OnGameReady?.Invoke();
}
/// <summary>
/// Register a custom pledge type that can be used in the game's AI system.
/// The pledge type must inherit from Pledge2 and have a parameterless constructor.
/// </summary>
/// <param name="pledgeTypeName">The name used in JSON pledge definitions (strType field)</param>
/// <param name="pledgeClass">The C# class type that implements the pledge (must inherit from Pledge2)</param>
/// <returns>True if registered successfully, false otherwise</returns>
public static bool RegisterPledgeType(string pledgeTypeName, Type pledgeClass)
{
if (_instance == null)
{
Debug.LogError("LaunchControl.RegisterPledgeType called before LaunchControl was initialized!");
return false;
}
return _instance._pledgeManager.RegisterPledgeType(pledgeTypeName, pledgeClass);
}
/// <summary>
/// Register a custom module for item tooltips
/// </summary>
/// <param name="moduleType">Module type (must implement IDataModule and derive from MonoBehaviour)</param>
/// <param name="setupUI">Callback to programmatically create UI components</param>
/// <returns>ModuleRegistration for fluent configuration</returns>
public static ModuleRegistration RegisterItemModule(Type moduleType, UISetupCallback setupUI)
{
if (_instance == null)
{
Debug.LogError("LaunchControl.RegisterItemModule called before LaunchControl was initialized!");
return null;
}
return _instance._megaTooltipManager.RegisterItemModule(moduleType, setupUI);
}
/// <summary>
/// Register a custom module for person/crew tooltips
/// </summary>
/// <param name="moduleType">Module type (must implement IDataModule and derive from MonoBehaviour)</param>
/// <param name="setupUI">Callback to programmatically create UI components</param>
/// <returns>ModuleRegistration for fluent configuration</returns>
public static ModuleRegistration RegisterPersonModule(Type moduleType, UISetupCallback setupUI)
{
if (_instance == null)
{
Debug.LogError("LaunchControl.RegisterPersonModule called before LaunchControl was initialized!");
return null;
}
return _instance._megaTooltipManager.RegisterPersonModule(moduleType, setupUI);
}
private void OnDestroy()
{
// Unsubscribe from game load complete event
if (CrewSim.OnGameFinishedLoading != null)
{
CrewSim.OnGameFinishedLoading.RemoveListener(OnCrewSimGameFinishedLoading);
}
// Cleanup the persistent data load listener
PersistentDataPatches.CleanupLoadListener();
}
}
}