protected override void OnLoadFromConfig(ConfigNode node)
 {
     level  = ConfigNodeUtil.ParseValue <int>(node, "level", 0);
     gender = ConfigNodeUtil.ParseValue <ProtoCrewMember.Gender?>(node, "gender", null);
     trait  = ConfigNodeUtil.ParseValue <string>(node, "trait", (string)null);
 }
 public override void OnLoad(ConfigNode configNode)
 {
     basename = ConfigNodeUtil.ParseValue <String>(configNode, "basename");
 }
Exemple #3
0
        /// <summary>
        /// Parses the child DATA nodes out of the given config node, and returns the parsed values back in dataValues.
        /// </summary>
        /// <param name="configNode">The ConfigNode to load child DATA nodes from.</param>
        /// <param name="obj">The ContractConfigurator object to load from.</param>
        /// <param name="dataValues"></param>
        /// <param name="uniquenessChecks"></param>
        /// <returns></returns>
        public bool ParseDataNodes(ConfigNode configNode, IContractConfiguratorFactory obj,
                                   Dictionary <string, ContractType.DataValueInfo> dataValues, Dictionary <string, UniquenessCheck> uniquenessChecks)
        {
            bool valid = true;

            foreach (ConfigNode data in ConfigNodeUtil.GetChildNodes(configNode, "DATA"))
            {
                Type   type          = null;
                bool   requiredValue = true;
                bool   hidden        = true;
                string title         = "";

                ConfigNodeUtil.SetCurrentDataNode(null);
                valid &= ConfigNodeUtil.ParseValue <Type>(data, "type", x => type = x, obj);
                valid &= ConfigNodeUtil.ParseValue <bool>(data, "requiredValue", x => requiredValue = x, obj, true);
                valid &= ConfigNodeUtil.ParseValue <string>(data, "title", x => title = x, obj, "");
                valid &= ConfigNodeUtil.ParseValue <bool>(data, "hidden", x => hidden = x, obj, false);

                bool doneTitleWarning = false;

                UniquenessCheck uniquenessCheck = UniquenessCheck.NONE;
                // Backwards compatibility for Contract Configurator 1.8.3
                if (data.HasValue("uniqueValue") || data.HasValue("activeUniqueValue"))
                {
                    LoggingUtil.LogWarning(this, "The use of uniqueValue and activeUniqueValue is obsolete since Contract Configurator 1.9.0, use uniquenessCheck instead.");

                    bool uniqueValue       = false;
                    bool activeUniqueValue = false;
                    valid &= ConfigNodeUtil.ParseValue <bool>(data, "uniqueValue", x => uniqueValue = x, obj, false);
                    valid &= ConfigNodeUtil.ParseValue <bool>(data, "activeUniqueValue", x => activeUniqueValue = x, obj, false);

                    uniquenessCheck = activeUniqueValue ? UniquenessCheck.CONTRACT_ACTIVE : uniqueValue ? UniquenessCheck.CONTRACT_ALL : UniquenessCheck.NONE;
                }
                else
                {
                    valid &= ConfigNodeUtil.ParseValue <UniquenessCheck>(data, "uniquenessCheck", x => uniquenessCheck = x, obj, UniquenessCheck.NONE);
                }

                ConfigNodeUtil.SetCurrentDataNode(this);

                if (type != null)
                {
                    foreach (ConfigNode.Value pair in data.values)
                    {
                        string name = pair.name;
                        if (name != "type" && name != "title" && name != "hidden" && name != "requiredValue" && name != "uniqueValue" && name != "activeUniqueValue" && name != "uniquenessCheck")
                        {
                            if (uniquenessCheck != UniquenessCheck.NONE)
                            {
                                uniquenessChecks[name] = uniquenessCheck;
                            }

                            object value = null;

                            // Create the setter function
                            Type     actionType = typeof(Action <>).MakeGenericType(type);
                            Delegate del        = Delegate.CreateDelegate(actionType, value, typeof(DataNode).GetMethod("NullAction"));

                            // Set the ParseValue method generic
                            MethodInfo method = methodParseValue.MakeGenericMethod(new Type[] { type });

                            // Invoke the ParseValue method
                            valid &= (bool)method.Invoke(null, new object[] { data, name, del, obj });

                            dataValues[name] = new ContractType.DataValueInfo(title, requiredValue, hidden, type);

                            // Recommend a title
                            if (!data.HasValue("title") && requiredValue && !IsDeterministic(name) && !hidden && !doneTitleWarning && !dataValues[name].IsIgnoredType())
                            {
                                doneTitleWarning = true;

                                LoggingUtil.Log(obj.minVersion >= ContractConfigurator.ENHANCED_UI_VERSION ? LoggingUtil.LogLevel.ERROR : LoggingUtil.LogLevel.WARNING, this,
                                                obj.ErrorPrefix() + ": " + name + ": The field 'title' is required in for data node values where 'requiredValue' is true.  Alternatively, the attribute 'hidden' can be set to true (but be careful - this can cause player confusion if all lines for the contract type show as 'Met' and the contract isn't generating).");

                                // Error on newer versions of contract packs
                                if (obj.minVersion >= ContractConfigurator.ENHANCED_UI_VERSION)
                                {
                                    valid = false;
                                }
                            }
                        }
                    }
                }
            }

            return(valid);
        }
 protected override void OnParameterLoad(ConfigNode node)
 {
     base.OnParameterLoad(node);
     vessels  = ConfigNodeUtil.ParseValue <List <string> >(node, "vessel", new List <string>());
     distance = ConfigNodeUtil.ParseValue <double>(node, "distance");
 }
Exemple #5
0
        protected override void OnParameterLoad(ConfigNode node)
        {
            base.OnParameterLoad(node);

            staged = new HashSet <Vessel>(ConfigNodeUtil.ParseValue <List <Vessel> >(node.GetNode("STAGED_VESSELS"), "vessel", new List <Vessel>()));
        }
        public static SpawnVessel Create(ConfigNode configNode, CelestialBody defaultBody, SpawnVesselFactory factory)
        {
            SpawnVessel spawnVessel = new SpawnVessel();

            bool valid = true;
            int  index = 0;

            foreach (ConfigNode child in ConfigNodeUtil.GetChildNodes(configNode, "VESSEL"))
            {
                DataNode dataNode = new DataNode("VESSEL_" + index++, factory.dataNode, factory);
                try
                {
                    ConfigNodeUtil.SetCurrentDataNode(dataNode);

                    VesselData vessel = new VesselData();

                    // Get name
                    if (child.HasValue("name"))
                    {
                        vessel.name = child.GetValue("name");
                    }

                    // Get paths
                    vessel.craftURL   = ConfigNodeUtil.ParseValue <string>(child, "craftURL");
                    vessel.flagURL    = ConfigNodeUtil.ParseValue <string>(child, "flagURL", (string)null);
                    vessel.vesselType = ConfigNodeUtil.ParseValue <VesselType>(child, "vesselType", VesselType.Ship);

                    // Get celestial body
                    valid &= ConfigNodeUtil.ParseValue <CelestialBody>(child, "targetBody", x => vessel.body = x, factory, defaultBody, Validation.NotNull);

                    // Get landed stuff
                    if (child.HasValue("lat") && child.HasValue("lon"))
                    {
                        valid        &= ConfigNodeUtil.ParseValue <double>(child, "lat", x => vessel.latitude = x, factory);
                        valid        &= ConfigNodeUtil.ParseValue <double>(child, "lon", x => vessel.longitude = x, factory);
                        valid        &= ConfigNodeUtil.ParseValue <double?>(child, "alt", x => vessel.altitude = x, factory, (double?)null);
                        vessel.landed = true;
                    }
                    // Get orbit
                    else
                    {
                        valid       &= ConfigNodeUtil.ValidateMandatoryChild(child, "ORBIT", factory);
                        vessel.orbit = new OrbitSnapshot(ConfigNodeUtil.GetChildNode(child, "ORBIT")).Load();
                        vessel.orbit.referenceBody = vessel.body;
                    }

                    // Get additional flags
                    valid &= ConfigNodeUtil.ParseValue <bool>(child, "owned", x => vessel.owned = x, factory, false);

                    // Handle the CREW nodes
                    foreach (ConfigNode crewNode in ConfigNodeUtil.GetChildNodes(child, "CREW"))
                    {
                        int count = 1;
                        valid &= ConfigNodeUtil.ParseValue <int>(crewNode, "count", x => count = x, factory, 1);
                        for (int i = 0; i < count; i++)
                        {
                            CrewData cd = new CrewData();

                            // Read crew details
                            valid &= ConfigNodeUtil.ParseValue <string>(crewNode, "name", x => cd.name = x, factory, (string)null);
                            valid &= ConfigNodeUtil.ParseValue <bool>(crewNode, "addToRoster", x => cd.addToRoster = x, factory, true);

                            // Add the record
                            vessel.crew.Add(cd);
                        }
                    }

                    // Add to the list
                    spawnVessel.vessels.Add(vessel);
                }
                finally
                {
                    ConfigNodeUtil.SetCurrentDataNode(factory.dataNode);
                }
            }

            return(valid ? spawnVessel : null);
        }
Exemple #7
0
 public override void OnLoad(ConfigNode configNode)
 {
     range = ConfigNodeUtil.ParseValue <double>(configNode, "range", 0.0);
 }
Exemple #8
0
        public static SpawnVessel Create(ConfigNode configNode, SpawnVesselFactory factory)
        {
            SpawnVessel spawnVessel = new SpawnVessel();

            ConfigNodeUtil.ParseValue <bool>(configNode, "deferVesselCreation", x => spawnVessel.deferVesselCreation = x, factory, false);

            bool valid = true;
            int  index = 0;

            foreach (ConfigNode child in ConfigNodeUtil.GetChildNodes(configNode, "VESSEL"))
            {
                DataNode dataNode = new DataNode("VESSEL_" + index++, factory.dataNode, factory);
                try
                {
                    ConfigNodeUtil.SetCurrentDataNode(dataNode);

                    VesselData vessel = new VesselData();

                    // Get name
                    if (child.HasValue("name"))
                    {
                        valid &= ConfigNodeUtil.ParseValue <string>(child, "name", x => vessel.name = x, factory);
                    }

                    // Get craft details
                    if (child.HasValue("craftURL"))
                    {
                        valid &= ConfigNodeUtil.ParseValue <string>(child, "craftURL", x => vessel.craftURL = x, factory);
                    }
                    if (child.HasValue("craftPart"))
                    {
                        valid &= ConfigNodeUtil.ParseValue <AvailablePart>(child, "craftPart", x => vessel.craftPart = x, factory);
                    }
                    valid &= ConfigNodeUtil.AtLeastOne(child, new string[] { "craftURL", "craftPart" }, factory);

                    valid &= ConfigNodeUtil.ParseValue <string>(child, "flagURL", x => vessel.flagURL = x, factory, (string)null);
                    valid &= ConfigNodeUtil.ParseValue <VesselType>(child, "vesselType", x => vessel.vesselType = x, factory, VesselType.Ship);

                    // Use an expression to default - then it'll work for dynamic contracts
                    if (!child.HasValue("targetBody"))
                    {
                        child.AddValue("targetBody", "@/targetBody");
                    }
                    valid &= ConfigNodeUtil.ParseValue <CelestialBody>(child, "targetBody", x => vessel.body = x, factory);

                    // Get landed stuff
                    if (child.HasValue("pqsCity"))
                    {
                        string pqsCityStr = null;
                        valid &= ConfigNodeUtil.ParseValue <string>(child, "pqsCity", x => pqsCityStr = x, factory);
                        if (pqsCityStr != null)
                        {
                            try
                            {
                                vessel.pqsCity = vessel.body.GetComponentsInChildren <PQSCity>(true).Where(pqs => pqs.name == pqsCityStr).First();
                            }
                            catch (Exception e)
                            {
                                LoggingUtil.LogError(typeof(WaypointGenerator), "Couldn't load PQSCity with name '{0}'", pqsCityStr);
                                LoggingUtil.LogException(e);
                                valid = false;
                            }
                        }
                        valid &= ConfigNodeUtil.ParseValue <Vector3d>(child, "pqsOffset", x => vessel.pqsOffset = x, factory, new Vector3d());

                        // Don't expect these to load anything, but do it to mark as initialized
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "lat", x => vessel.latitude = x, factory, 0.0);
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "lon", x => vessel.longitude = x, factory, 0.0);

                        // Do load alt and height
                        valid &= ConfigNodeUtil.ParseValue <double?>(child, "alt", x => vessel.altitude = x, factory, (double?)null);
                        valid &= ConfigNodeUtil.ParseValue <float>(child, "height", x => vessel.height = x, factory,
                                                                   !string.IsNullOrEmpty(vessel.craftURL) ? 0.0f : 2.5f);
                        vessel.orbiting = false;
                    }
                    else if (child.HasValue("lat") && child.HasValue("lon"))
                    {
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "lat", x => vessel.latitude = x, factory);
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "lon", x => vessel.longitude = x, factory);
                        valid &= ConfigNodeUtil.ParseValue <double?>(child, "alt", x => vessel.altitude = x, factory, (double?)null);
                        valid &= ConfigNodeUtil.ParseValue <float>(child, "height", x => vessel.height = x, factory,
                                                                   !string.IsNullOrEmpty(vessel.craftURL) ? 0.0f : 2.5f);
                        vessel.orbiting = false;
                    }
                    // Get orbit
                    else
                    {
                        valid          &= ConfigNodeUtil.ParseValue <Orbit>(child, "ORBIT", x => vessel.orbit = x, factory);
                        vessel.orbiting = true;
                    }

                    valid &= ConfigNodeUtil.ParseValue <float>(child, "heading", x => vessel.heading = x, factory, 0.0f);
                    valid &= ConfigNodeUtil.ParseValue <float>(child, "pitch", x => vessel.pitch = x, factory, 0.0f);
                    valid &= ConfigNodeUtil.ParseValue <float>(child, "roll", x => vessel.roll = x, factory, 0.0f);

                    // Get additional flags
                    valid &= ConfigNodeUtil.ParseValue <bool>(child, "owned", x => vessel.owned = x, factory, false);

                    // Handle the CREW nodes
                    foreach (ConfigNode crewNode in ConfigNodeUtil.GetChildNodes(child, "CREW"))
                    {
                        int count = 1;
                        valid &= ConfigNodeUtil.ParseValue <int>(crewNode, "count", x => count = x, factory, 1);
                        for (int i = 0; i < count; i++)
                        {
                            CrewData cd = new CrewData();

                            // Read crew details
                            valid &= ConfigNodeUtil.ParseValue <string>(crewNode, "name", x => cd.name = x, factory, (string)null);
                            valid &= ConfigNodeUtil.ParseValue <bool>(crewNode, "addToRoster", x => cd.addToRoster = x, factory, true);

                            // Check for unexpected values
                            valid &= ConfigNodeUtil.ValidateUnexpectedValues(crewNode, factory);

                            // Add the record
                            vessel.crew.Add(cd);
                        }
                    }

                    // Check for unexpected values
                    valid &= ConfigNodeUtil.ValidateUnexpectedValues(child, factory);

                    // Add to the list
                    spawnVessel.vessels.Add(vessel);
                }
                finally
                {
                    ConfigNodeUtil.SetCurrentDataNode(factory.dataNode);
                }
            }

            if (!configNode.HasNode("VESSEL"))
            {
                valid = false;
                LoggingUtil.LogError(factory, "SpawnVessel requires at least one VESSEL node.");
            }

            return(valid ? spawnVessel : null);
        }
 protected override void OnLoad(ConfigNode node)
 {
     base.OnLoad(node);
     title       = node.GetValue("title");
     destination = ConfigNodeUtil.ParseValue <CelestialBody>(node, "destination");
 }
 protected override void OnLoad(ConfigNode node)
 {
     validVessel = ConfigNodeUtil.ParseValue <Vessel>(node, "validVessel", null);
 }
Exemple #11
0
 protected override void OnLoadFromConfig(ConfigNode node)
 {
     group = ConfigNodeUtil.ParseValue <string>(node, "group");
     text  = ConfigNodeUtil.ParseValue <string>(node, "text");
 }
        protected override void OnLoadFromConfig(ConfigNode node)
        {
            base.OnLoadFromConfig(node);

            description = ConfigNodeUtil.ParseValue <string>(node, "description");
        }
Exemple #13
0
 protected override void OnParameterLoad(ConfigNode node)
 {
     base.OnParameterLoad(node);
     destination = ConfigNodeUtil.ParseValue <CelestialBody>(node, "destination");
     entryType   = (FlightLog.EntryType)Enum.Parse(typeof(FlightLog.EntryType), node.GetValue("entryType"));
 }
Exemple #14
0
        protected override void OnParameterLoad(ConfigNode node)
        {
            base.OnParameterLoad(node);

            hasConnectivity = ConfigNodeUtil.ParseValue <bool>(node, "hasConnectivity");
        }
 public override void OnLoad(ConfigNode configNode)
 {
     base.OnLoad(configNode);
     imageURL = ConfigNodeUtil.ParseValue <string>(configNode, "imageURL");
 }
Exemple #16
0
 protected override void OnLoadFromConfig(ConfigNode node)
 {
     KSCScienceMultiplier    = ConfigNodeUtil.ParseValue <float>(node, "KSCScienceMultiplier", 0.0f);
     nonKSCScienceMultiplier = ConfigNodeUtil.ParseValue <float>(node, "nonKSCScienceMultiplier", 0.0f);
 }
 public override void OnLoad(ConfigNode configNode)
 {
     base.OnLoad(configNode);
     name      = ConfigNodeUtil.ParseValue <string>(configNode, "name");
     animation = ConfigNodeUtil.ParseValue <Animation?>(configNode, "animation", (Animation?)null);
 }
Exemple #18
0
 protected override void OnLoadFromConfig(ConfigNode node)
 {
     currency   = ConfigNodeUtil.ParseValue <Currency>(node, "currency");
     multiplier = ConfigNodeUtil.ParseValue <float>(node, "multiplier");
 }
Exemple #19
0
 protected override void OnParameterLoad(ConfigNode node)
 {
     hiddenParameters           = ConfigNodeUtil.ParseValue <List <string> >(node, "hiddenParameter", new List <string>());
     failWhenCompleteOutOfOrder = ConfigNodeUtil.ParseValue <bool?>(node, "failWhenCompleteOutOfOrder", (bool?)false).Value;
 }
Exemple #20
0
        public static WaypointGenerator Create(ConfigNode configNode, CelestialBody defaultBody, WaypointGeneratorFactory factory)
        {
            WaypointGenerator wpGenerator = new WaypointGenerator();

            bool valid = true;
            int  index = 0;

            foreach (ConfigNode child in ConfigNodeUtil.GetChildNodes(configNode))
            {
                double?      altitude = null;
                WaypointData wpData   = new WaypointData(child.name);

                valid &= ConfigNodeUtil.ParseValue <string>(child, "targetBody", x => wpData.waypoint.celestialName = x, factory, defaultBody != null ? defaultBody.name : null, Validation.NotNull);
                valid &= ConfigNodeUtil.ParseValue <string>(child, "name", x => wpData.waypoint.name = x, factory, (string)null);
                valid &= ConfigNodeUtil.ParseValue <double?>(child, "altitude", x => altitude = x, factory, (double?)null);
                valid &= ConfigNodeUtil.ParseValue <string>(child, "parameter", x => wpData.parameter = x, factory, "");
                valid &= ConfigNodeUtil.ParseValue <bool>(child, "hidden", x => wpData.hidden = x, factory, false);
                if (wpData.hidden)
                {
                    valid &= ConfigNodeUtil.ParseValue <string>(child, "icon", x => wpData.waypoint.id = x, factory, "");
                }
                else
                {
                    valid &= ConfigNodeUtil.ParseValue <string>(child, "icon", x => wpData.waypoint.id = x, factory);
                }

                // The FinePrint logic is such that it will only look in Squad/Contracts/Icons for icons.
                // Cheat this by hacking the path in the game database.
                if (wpData.waypoint.id.Contains("/"))
                {
                    GameDatabase.TextureInfo texInfo = GameDatabase.Instance.databaseTexture.Where(t => t.name == wpData.waypoint.id).FirstOrDefault();
                    if (texInfo != null)
                    {
                        texInfo.name = "Squad/Contracts/Icons/" + wpData.waypoint.id;
                    }
                }

                // Track the index
                wpData.waypoint.index = index++;

                // Get altitude
                if (altitude == null)
                {
                    wpData.waypoint.altitude = 0.0;
                    wpData.randomAltitude    = true;
                }
                else
                {
                    wpData.waypoint.altitude = altitude.Value;
                }

                DataNode dataNode = new DataNode("WAYPOINT_" + (index - 1), factory.dataNode, factory);
                try
                {
                    ConfigNodeUtil.SetCurrentDataNode(dataNode);

                    // Get settings that differ by type
                    if (child.name == "WAYPOINT")
                    {
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "latitude", x => wpData.waypoint.latitude = x, factory);
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "longitude", x => wpData.waypoint.longitude = x, factory);
                    }
                    else if (child.name == "RANDOM_WAYPOINT")
                    {
                        // Get settings for randomization
                        valid &= ConfigNodeUtil.ParseValue <bool>(child, "waterAllowed", x => wpData.waterAllowed = x, factory, true);
                        valid &= ConfigNodeUtil.ParseValue <bool>(child, "forceEquatorial", x => wpData.forceEquatorial = x, factory, false);
                        valid &= ConfigNodeUtil.ParseValue <int>(child, "count", x => wpData.count = x, factory, 1, x => Validation.GE(x, 1));
                    }
                    else if (child.name == "RANDOM_WAYPOINT_NEAR")
                    {
                        // Get settings for randomization
                        valid &= ConfigNodeUtil.ParseValue <bool>(child, "waterAllowed", x => wpData.waterAllowed = x, factory, true);

                        // Get near waypoint details
                        valid &= ConfigNodeUtil.ParseValue <int>(child, "nearIndex", x => wpData.nearIndex = x, factory, x => Validation.GE(x, 0));
                        valid &= ConfigNodeUtil.ParseValue <int>(child, "count", x => wpData.count = x, factory, 1, x => Validation.GE(x, 1));

                        // Get distances
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "minDistance", x => wpData.minDistance = x, factory, 0.0, x => Validation.GE(x, 0.0));

                        // To be deprecated
                        if (child.HasValue("nearDistance"))
                        {
                            valid &= ConfigNodeUtil.ParseValue <double>(child, "nearDistance", x => wpData.maxDistance = x, factory, x => Validation.GT(x, 0.0));
                            LoggingUtil.LogWarning(factory, "The 'nearDistance' attribute is obsolete as of Contract Configurator 0.7.4.  It will be removed in 1.0.0 in favour of minDistance/maxDistance.");
                        }
                        else
                        {
                            valid &= ConfigNodeUtil.ParseValue <double>(child, "maxDistance", x => wpData.maxDistance = x, factory, x => Validation.GT(x, wpData.minDistance));
                        }
                    }
                    else if (child.name == "PQS_CITY")
                    {
                        wpData.randomAltitude = false;
                        string pqsCity = null;
                        valid &= ConfigNodeUtil.ParseValue <string>(child, "pqsCity", x => pqsCity = x, factory);
                        if (pqsCity != null)
                        {
                            try
                            {
                                CelestialBody body = FlightGlobals.Bodies.Where(b => b.name == wpData.waypoint.celestialName).First();
                                wpData.pqsCity = body.GetComponentsInChildren <PQSCity>(true).Where(pqs => pqs.name == pqsCity).First();
                            }
                            catch (Exception e)
                            {
                                LoggingUtil.LogError(typeof(WaypointGenerator), "Couldn't load PQSCity with name '" + pqsCity + "'");
                                LoggingUtil.LogException(e);
                                valid = false;
                            }
                        }
                        valid &= ConfigNodeUtil.ParseValue <Vector3d>(child, "pqsOffset", x => wpData.pqsOffset = x, factory, new Vector3d());
                    }
                    else
                    {
                        LoggingUtil.LogError(factory, "Unrecognized waypoint node: '" + child.name + "'");
                        valid = false;
                    }
                }
                finally
                {
                    ConfigNodeUtil.SetCurrentDataNode(factory.dataNode);
                }

                // Add to the list
                wpGenerator.waypoints.Add(wpData);
            }

            return(valid ? wpGenerator : null);
        }
 protected override void OnLoad(ConfigNode configNode)
 {
     parts  = ConfigNodeUtil.ParseValue <List <AvailablePart> >(configNode, "part");
     add    = ConfigNodeUtil.ParseValue <bool>(configNode, "add");
     remove = ConfigNodeUtil.ParseValue <bool>(configNode, "remove");
 }
Exemple #22
0
 protected override void OnParameterLoad(ConfigNode node)
 {
     base.OnParameterLoad(node);
     minCapacity = ConfigNodeUtil.ParseValue <int>(node, "minCapacity");
     maxCapacity = ConfigNodeUtil.ParseValue <int>(node, "maxCapacity");
 }
 public override void OnLoad(ConfigNode configNode)
 {
     //Get host
     host = ConfigNodeUtil.ParseValue <string>(configNode, "host", "Observatory");
 }
 public virtual void OnLoad(ConfigNode configNode)
 {
     name = ConfigNodeUtil.ParseValue <string>(configNode, "name");
 }
        public static OrbitGenerator Create(ConfigNode configNode, OrbitGeneratorFactory factory)
        {
            OrbitGenerator obGenerator = new OrbitGenerator();

            bool valid = true;
            int  index = 0;

            foreach (ConfigNode child in ConfigNodeUtil.GetChildNodes(configNode))
            {
                DataNode dataNode = new DataNode("ORBIT_" + index++, factory.dataNode, factory);
                try
                {
                    ConfigNodeUtil.SetCurrentDataNode(dataNode);

                    OrbitData obData = new OrbitData(child.name);

                    // Get settings that differ by type
                    if (child.name == "FIXED_ORBIT")
                    {
                        valid &= ConfigNodeUtil.ParseValue <Orbit>(child, "ORBIT", x => obData.orbit = x, factory);
                    }
                    else if (child.name == "RANDOM_ORBIT")
                    {
                        valid &= ConfigNodeUtil.ParseValue <OrbitType>(child, "type", x => obData.orbitType = x, factory);
                        valid &= ConfigNodeUtil.ParseValue <int>(child, "count", x => obData.count = x, factory, 1, x => Validation.GE(x, 1));
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "altitudeFactor", x => obData.altitudeFactor = x, factory, 0.8, x => Validation.Between(x, 0.0, 1.0));
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "inclinationFactor", x => obData.inclinationFactor = x, factory, 0.8, x => Validation.Between(x, 0.0, 1.0));
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "eccentricity", x => obData.eccentricity = x, factory, 0.0, x => Validation.GE(x, 0.0));
                        valid &= ConfigNodeUtil.ParseValue <double>(child, "deviationWindow", x => obData.deviationWindow = x, factory, 10.0, x => Validation.GE(x, 0.0));
                    }
                    else
                    {
                        throw new ArgumentException("Unrecognized orbit node: '" + child.name + "'");
                    }

                    // Use an expression to default - then it'll work for dynamic contracts
                    if (!child.HasValue("targetBody"))
                    {
                        child.AddValue("targetBody", "@/targetBody");
                    }
                    valid &= ConfigNodeUtil.ParseValue <CelestialBody>(child, "targetBody", x => obData.targetBody = x, factory);

                    // Check for unexpected values
                    valid &= ConfigNodeUtil.ValidateUnexpectedValues(child, factory);

                    // Add to the list
                    obGenerator.orbits.Add(obData);

                    if (dataNode.IsInitialized("targetBody") && dataNode.IsInitialized("type"))
                    {
                        valid &= obGenerator.ValidateOrbitType(obData, factory);
                    }
                }
                finally
                {
                    ConfigNodeUtil.SetCurrentDataNode(factory.dataNode);
                }
            }

            return(valid ? obGenerator : null);
        }
 public override void OnLoad(ConfigNode configNode)
 {
     text      = ConfigNodeUtil.ParseValue <string>(configNode, "text");
     textColor = ConfigNodeUtil.ParseValue <Color>(configNode, "textColor");
     fontSize  = ConfigNodeUtil.ParseValue <int>(configNode, "fontSize");
 }
 protected override void OnParameterLoad(ConfigNode node)
 {
     targetBody = ConfigNodeUtil.ParseValue <CelestialBody>(node, "targetBody");
 }
 public override void OnLoad(ConfigNode configNode)
 {
     showName      = ConfigNodeUtil.ParseValue <bool>(configNode, "showName");
     characterName = ConfigNodeUtil.ParseValue <string>(configNode, "characterName", "");
     textColor     = ConfigNodeUtil.ParseValue <Color>(configNode, "textColor");
 }
Exemple #29
0
        /// <summary>
        /// Loads the ITERATOR nodes.
        /// </summary>
        /// <param name="node"></param>
        /// <returns>Whether the load was successful</returns>
        public static bool LoadIteratorNodes(ConfigNode node, IContractConfiguratorFactory obj)
        {
            bool valid = true;

            IEnumerable <ConfigNode> iteratorNodes = ConfigNodeUtil.GetChildNodes(node, "ITERATOR");

            if (!iteratorNodes.Any())
            {
                return(true);
            }
            else if (iteratorNodes.Count() > 1)
            {
                LoggingUtil.LogError(obj, "Multiple ITERATOR nodes found - only one iterator node allowed.");
                return(false);
            }

            ConfigNode iteratorNode     = iteratorNodes.First();
            DataNode   iteratorDataNode = new DataNode("ITERATOR", obj.dataNode, obj);

            try
            {
                ConfigNodeUtil.SetCurrentDataNode(iteratorDataNode);

                valid &= ConfigNodeUtil.ParseValue <Type>(iteratorNode, "type", x => obj.iteratorType = x, obj);
                if (obj.iteratorType != null)
                {
                    foreach (ConfigNode.Value pair in iteratorNode.values)
                    {
                        string name = pair.name;
                        if (name != "type")
                        {
                            if (!string.IsNullOrEmpty(obj.iteratorKey))
                            {
                                LoggingUtil.LogError(obj, "Multiple key values found in ITERATOR node - only one key allowed.");
                                return(false);
                            }

                            // Create the list type
                            Type listType = typeof(List <>);
                            listType = listType.MakeGenericType(new Type[] { obj.iteratorType });

                            // Create the setter function
                            object   value          = null;
                            Type     listActionType = typeof(Action <>).MakeGenericType(listType);
                            Delegate listDelegate   = Delegate.CreateDelegate(listActionType, value, typeof(DataNode).GetMethod("NullAction"));

                            // Get the ParseValue method
                            MethodInfo parseListMethod = parseMethodGeneric.MakeGenericMethod(new Type[] { listType });

                            // Invoke the ParseValue method
                            valid &= (bool)parseListMethod.Invoke(null, new object[] { iteratorNode, name, listDelegate, obj });

                            // Store the iterator key for later
                            obj.iteratorKey = name;
                        }
                    }
                }

                // Load didn't get us a key
                if (string.IsNullOrEmpty(obj.iteratorKey))
                {
                    LoggingUtil.LogError(obj, "No key field was defined for the ITERATOR!.");
                    return(false);
                }
            }
            finally
            {
                ConfigNodeUtil.SetCurrentDataNode(obj.dataNode);
            }

            // Add a dummy value to the parent data node
            node.AddValue(obj.iteratorKey, "@ITERATOR/" + obj.iteratorKey + ".ElementAt(IteratorCurrentIndex())");
            node.AddValue("iteratorCount", "@ITERATOR/" + obj.iteratorKey + ".Count()");

            return(valid);
        }
Exemple #30
0
 public override void OnLoad(ConfigNode configNode)
 {
     minCoverage = ConfigNodeUtil.ParseValue <double>(configNode, "minCoverage", 0.0);
     maxCoverage = ConfigNodeUtil.ParseValue <double>(configNode, "maxCoverage", 1.0);
 }