Esempio n. 1
0
        /// <summary>
        /// Create an InventoryPart from an origin ConfigNode, extracting the name, dry cost, and relevant MODULEs
        /// </summary>
        /// <param name="originPartConfigNode">The <see cref="ConfigNode"/> to use as the basis of the <see cref="InventoryPart"/>.</param>
        public InventoryPart(ConfigNode originPartConfigNode)
        {
            _name = ConfigNodeUtils.PartNameFromNode(originPartConfigNode);
            float         fuelCost;
            AvailablePart availablePartForNode = ConfigNodeUtils.AvailablePartFromNode(originPartConfigNode);

            if (availablePartForNode != null)
            {
                float dryMass, fuelMass;
                ShipConstruction.GetPartCostsAndMass(originPartConfigNode, availablePartForNode, out _dryCost, out fuelCost, out dryMass, out fuelMass);
            }

            if (originPartConfigNode.HasNode("MODULE"))
            {
                foreach (ConfigNode module in originPartConfigNode.GetNodes("MODULE"))
                {
                    foreach (string trackedModuleName in ScrapYard.Instance.Settings.TrackedModules)
                    {
                        if (module.GetValue("name").ToUpper().Contains(trackedModuleName))
                        {
                            savedModules.Add(module);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create an InventoryPart from an origin ConfigNode, extracting the name, dry cost, and relevant MODULEs
        /// </summary>
        /// <param name="originPartConfigNode">The <see cref="ConfigNode"/> to use as the basis of the <see cref="InventoryPart"/>.</param>
        public InventoryPart(ConfigNode originPartConfigNode)
        {
            //if the ConfigNode given is already an InventoryPart, just load it instead
            if (originPartConfigNode.name == typeof(InventoryPart).FullName)
            {
                State = originPartConfigNode;
            }
            else
            {
                _name = ConfigNodeUtils.PartNameFromNode(originPartConfigNode);
                if (ScrapYard.Instance.Settings.PartBlacklist.Contains(Name))
                {
                    DoNotStore = true;
                }
                AvailablePart availablePartForNode = ConfigNodeUtils.AvailablePartFromNode(originPartConfigNode);
                if (availablePartForNode != null)
                {
                    float dryMass, fuelMass, fuelCost;
                    ShipConstruction.GetPartCostsAndMass(originPartConfigNode, availablePartForNode, out _dryCost, out fuelCost, out dryMass, out fuelMass);
                }

                if (originPartConfigNode.HasNode("MODULE"))
                {
                    foreach (ConfigNode module in originPartConfigNode.GetNodes("MODULE"))
                    {
                        string name      = module.GetValue("name");
                        bool   isTracker = name.Equals("ModuleSYPartTracker");
                        _allModules.Add(module);
                        if (isTracker)
                        {
                            TrackerModule = new TrackerModuleWrapper(module);
                        }
                    }
                }

                uint id = 0;
                if (originPartConfigNode.TryGetValue("persistentId", ref id))
                {
                    ID = id;
                }
                else
                {
                    Logging.Log($"Could not find a persistent ID for part {_name}", Logging.LogType.ERROR);
                }
            }
        }