コード例 #1
0
        /// <summary>
        /// Loads the ContractRequirement from the given ConfigNode.  The base version loads the following:
        ///     - child nodes
        ///     - invertRequirement
        /// </summary>
        /// <param name="configNode">Config node to load from</param>
        /// <returns>Whether the load was successful or not.</returns>
        public virtual bool LoadFromConfig(ConfigNode configNode)
        {
            bool valid = true;

            ConfigNodeUtil.SetCurrentDataNode(dataNode);

            // Get name and type
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "type", x => type = x, this);
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "name", x => name = x, this, type);

            // Override needsTitle if a child of a parameter
            if (needsTitle && dataNode.Parent.Factory is ParameterFactory)
            {
                needsTitle = false;
            }

            // Allow reading of a custom title
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "title", x => title = x, this, (string)null);

            // Whether to hide child requirements in the mission control display
            valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "hideChildren", x => hideChildren = x, this, false);

            if (!configNode.HasValue("targetBody"))
            {
                configNode.AddValue("targetBody", "@/targetBody");
            }
            valid &= ConfigNodeUtil.ParseValue <CelestialBody>(configNode, "targetBody", x => _targetBody = x, this, (CelestialBody)null,
                                                               x => allowKerbin || Validation.NE(x.name, FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).FirstOrDefault().name));

            // By default, do not check the requirement for active contracts
            valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "checkOnActiveContract", x => checkOnActiveContract = x, this, false);

            // Load invertRequirement flag
            valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "invertRequirement", x => invertRequirement = x, this, false);

            config = configNode.ToString();
            return(valid);
        }