Esempio n. 1
0
        public static void AddPodInventories(Part part, int crewCapacity)
        {
            for (var i = 0; i < crewCapacity; i++)
            {
                var moduleInventory =
                    part.AddModule(typeof(ModuleKISInventory).Name) as ModuleKISInventory;
                KIS_Shared.AwakePartModule(moduleInventory);
                moduleInventory.invType = ModuleKISInventory.InventoryType.Pod;
                DebugEx.Fine("{0}: Add pod inventory to match the capacity", part);
            }
            var podInventories = part.Modules.OfType <ModuleKISInventory>()
                                 .Where(m => m.invType == ModuleKISInventory.InventoryType.Pod)
                                 .ToArray();

            for (var i = 0; i < podInventories.Length; i++)
            {
                try {
                    var baseFields = new BaseFieldList(podInventories[i]);
                    baseFields.Load(evaInventory);
                    podInventories[i].podSeat = i;
                    DebugEx.Fine("{0}: Pod inventory for seat {1} loaded successfully", part, i);
                } catch {
                    DebugEx.Error("{0}: Pod inventory module for seat {1} can't be loaded!", part, i);
                }
            }
        }
Esempio n. 2
0
 void SetInventoryConfig(Component moduleInventory, ConfigNode nodeSettings)
 {
     var nodeEvaInventory = nodeSettings.GetNode("EvaInventory");
     if (nodeEvaInventory != null) {
       var baseFields = new BaseFieldList(moduleInventory);
       baseFields.Load(nodeEvaInventory);
     }
 }
Esempio n. 3
0
        void SetInventoryConfig(Component moduleInventory, ConfigNode nodeSettings)
        {
            var nodeEvaInventory = nodeSettings.GetNode("EvaInventory");

            if (nodeEvaInventory != null)
            {
                var baseFields = new BaseFieldList(moduleInventory);
                baseFields.Load(nodeEvaInventory);
            }
        }
Esempio n. 4
0
        public void Awake()
        {
            ConfigAccessor.ReadFieldsInType(GetType(), this);
            ConfigAccessor.ReadFieldsInType(typeof(ModuleKISInventory), instance: null);

            // Set inventory module for every eva kerbal
            Debug.Log("Set KIS config...");
            ConfigNode nodeSettings = GameDatabase.Instance.GetConfigNode("KIS/settings/KISConfig");

            if (nodeSettings == null)
            {
                Debug.LogError("KIS settings.cfg not found or invalid !");
                return;
            }

            // Kerbal parts.
            UpdateEvaPrefab(MaleKerbalEva, nodeSettings);
            UpdateEvaPrefab(FemaleKerbalEva, nodeSettings);

            // Set inventory module for every pod with crew capacity.
            Debug.Log("Loading pod inventories...");
            foreach (AvailablePart avPart in PartLoader.LoadedPartsList)
            {
                if (avPart.name == MaleKerbalEva || avPart.name == FemaleKerbalEva ||
                    avPart.name == RdKerbalEva ||
                    !avPart.partPrefab || avPart.partPrefab.CrewCapacity < 1)
                {
                    continue;
                }

                Debug.LogFormat("Found part with CrewCapacity: {0}", avPart.name);
                for (int i = 0; i < avPart.partPrefab.CrewCapacity; i++)
                {
                    try {
                        var moduleInventory =
                            avPart.partPrefab.AddModule(typeof(ModuleKISInventory).Name) as ModuleKISInventory;
                        KIS_Shared.AwakePartModule(moduleInventory);
                        var baseFields = new BaseFieldList(moduleInventory);
                        baseFields.Load(nodeSettings.GetNode("EvaInventory"));
                        moduleInventory.podSeat = i;
                        moduleInventory.invType = ModuleKISInventory.InventoryType.Pod;
                        Debug.LogFormat("Pod inventory module(s) for seat {0} loaded successfully", i);
                    } catch {
                        Debug.LogErrorFormat("Pod inventory module(s) for seat {0} can't be loaded!", i);
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>Loads config values for the part's module fro the provided config node.</summary>
        /// <returns><c>true</c> if loaded successfully.</returns>
        static bool LoadModuleConfig(Part p, Type moduleType, ConfigNode node)
        {
            var module = p.GetComponent(moduleType);

            if (module == null)
            {
                DebugEx.Warning(
                    "Config node for module {0} in part {1} is NULL. Nothing to load!", moduleType, p);
                return(false);
            }
            if (node == null)
            {
                DebugEx.Warning("Cannot find module {0} on part {1}. Config not loaded!", moduleType, p);
                return(false);
            }
            var baseFields = new BaseFieldList(module);

            baseFields.Load(node);
            DebugEx.Info("Loaded config for {0} on part {1}", moduleType, p);
            return(true);
        }
Esempio n. 6
0
        void UpdateEvaPrefab(AvailablePart avPart, ConfigNode nodeSettings)
        {
            var prefab = avPart.partPrefab;

            // Adding module to EVA may cause an NPE but module update will still work.
            try {
                prefab.AddModule(typeof(ModuleKISInventory).Name);
            } catch (Exception ex) {
                Logger.logInfo(
                    "NOT A BUG! Ignoring error while adding ModuleKISInventory to {0}: {1}", prefab, ex);
            }
            try {
                prefab.AddModule(typeof(ModuleKISPickup).Name);
            } catch (Exception ex) {
                Logger.logInfo("NOT A BUG! Ignoring error adding ModuleKISPickup to {0}: {1}", prefab, ex);
            }

            // Setup inventory module for eva.
            var evaInventory = prefab.GetComponent <ModuleKISInventory>();

            CallAwakeMethod(evaInventory);
            if (evaInventory)
            {
                SetInventoryConfig(evaInventory, nodeSettings);
                evaInventory.invType = ModuleKISInventory.InventoryType.Eva;
                Logger.logInfo("Eva inventory module loaded successfully");
            }

            // Load KSP fields for ModuleKISPickup module.
            var nodeEvaPickup = nodeSettings.GetNode("EvaPickup");
            var evaPickup     = prefab.GetComponent <ModuleKISPickup>();

            CallAwakeMethod(evaPickup);
            if (evaPickup && nodeEvaPickup != null)
            {
                var fields = new BaseFieldList(evaPickup);
                fields.Load(nodeEvaPickup);
                Logger.logInfo("Eva pickup module loaded successfully");
            }
        }
Esempio n. 7
0
        void UpdateEvaPrefab(AvailablePart avPart, ConfigNode nodeSettings)
        {
            var prefab = avPart.partPrefab;
            // Adding module to EVA may cause an NPE but module update will still work.
            try {
              prefab.AddModule(typeof(ModuleKISInventory).Name);
            } catch (Exception ex) {
              Logger.logInfo(
              "NOT A BUG! Ignoring error while adding ModuleKISInventory to {0}: {1}", prefab, ex);
            }
            try {
              prefab.AddModule(typeof(ModuleKISPickup).Name);
            } catch (Exception ex) {
              Logger.logInfo("NOT A BUG! Ignoring error adding ModuleKISPickup to {0}: {1}", prefab, ex);
            }

            // Setup inventory module for eva.
            var evaInventory = prefab.GetComponent<ModuleKISInventory>();
            KIS_Shared.AwakePartModule(evaInventory);
            if (evaInventory) {
              SetInventoryConfig(evaInventory, nodeSettings);
              evaInventory.invType = ModuleKISInventory.InventoryType.Eva;
              Logger.logInfo("Eva inventory module loaded successfully");
            }

            // Load KSP fields for ModuleKISPickup module.
            var nodeEvaPickup = nodeSettings.GetNode("EvaPickup");
            var evaPickup = prefab.GetComponent<ModuleKISPickup>();
            KIS_Shared.AwakePartModule(evaPickup);
            if (evaPickup && nodeEvaPickup != null) {
              var fields = new BaseFieldList(evaPickup);
              fields.Load(nodeEvaPickup);
              Logger.logInfo("Eva pickup module loaded successfully");
            }
        }