1919 * along with RasterPropMonitor. If not, see <http://www.gnu.org/licenses/>.
2020 ****************************************************************************/
2121using System ;
22+ using System . Collections . Generic ;
23+ using Log = KSPBuildTools . Log ;
2224
2325namespace JSI
2426{
@@ -28,6 +30,56 @@ namespace JSI
2830 /// </summary>
2931 public class IJSIModule
3032 {
33+ public IJSIModule ( Vessel v )
34+ {
35+ this . vessel = v ;
36+ }
37+
3138 public Vessel vessel ;
39+
40+ #region Module Registration
41+
42+ static List < Type > x_registeredTypes = new List < Type > ( ) ;
43+
44+ internal static void CreateJSIModules ( List < IJSIModule > modules , Vessel v )
45+ {
46+ foreach ( Type t in x_registeredTypes )
47+ {
48+ try
49+ {
50+ modules . Add ( ( IJSIModule ) Activator . CreateInstance ( t , v ) ) ;
51+ }
52+ catch ( Exception e )
53+ {
54+ Log . Error ( "Error creating JSI module of type " + t . Name + ": " ) ;
55+ Log . Exception ( e ) ;
56+ }
57+ }
58+ }
59+
60+ public static void RegisterModule ( Type jsiModuleType )
61+ {
62+ if ( x_registeredTypes . IndexOf ( jsiModuleType ) != - 1 ) return ;
63+ if ( ! typeof ( IJSIModule ) . IsAssignableFrom ( jsiModuleType ) )
64+ {
65+ Log . Error ( $ "Tried to register an ISJIModuleType { jsiModuleType . Name } that does not inherit from IJSIModule") ;
66+ return ;
67+ }
68+ x_registeredTypes . Add ( jsiModuleType ) ;
69+ }
70+
71+ // A place to register known modules that might not otherwise have their static constructors called
72+ static IJSIModule ( )
73+ {
74+ RegisterModule ( typeof ( JSIParachute ) ) ;
75+ RegisterModule ( typeof ( JSIInternalRPMButtons ) ) ;
76+ if ( JSIChatterer . chattererFound ) RegisterModule ( typeof ( JSIChatterer ) ) ;
77+ if ( JSIFAR . farFound ) RegisterModule ( typeof ( JSIFAR ) ) ;
78+ if ( JSIKAC . kacFound ) RegisterModule ( typeof ( JSIKAC ) ) ;
79+ if ( JSIMechJeb . IsInstalled ) RegisterModule ( typeof ( JSIMechJeb ) ) ;
80+ if ( JSIPilotAssistant . paFound ) RegisterModule ( typeof ( JSIPilotAssistant ) ) ;
81+ }
82+
83+ #endregion
3284 }
3385}
0 commit comments