public override bool Load(ConfigNode configNode) { // Load base class bool valid = base.Load(configNode); valid &= ConfigNodeUtil.ParseValue<List<VesselIdentifier>>(configNode, "vessel", x => vessels = x, this, new List<VesselIdentifier>()); valid &= ConfigNodeUtil.ParseValue<VesselIdentifier>(configNode, "defineDockedVessel", x => defineDockedVessel = x, this, (VesselIdentifier)null); // Validate using the config node instead of the list as it may undergo deferred loading if (parent is VesselParameterGroupFactory) { if (configNode.GetValues("vessel").Count() > 1) { LoggingUtil.LogError(this, ErrorPrefix() + ": When used under a VesselParameterGroup, no more than one vessel may be specified for the Docking parameter."); valid = false; } } else { if (configNode.GetValues("vessel").Count() == 0) { LoggingUtil.LogError(this, ErrorPrefix() + ": Need at least one vessel specified for the Docking parameter."); valid = false; } if (configNode.GetValues("vessel").Count() > 2) { LoggingUtil.LogError(this, ErrorPrefix() + ": Cannot specify more than two vessels for the Docking parameter."); valid = false; } } return valid; }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); //Load all the drill info drillResources = node.GetValues("drillResource"); }
public VariableHandler(ConfigNode node, RasterPropMonitorComputer ourComp) { handlerName = node.GetValue("name"); foreach (string variableRecord in node.GetValues("variable")) { var record = new VariableRecord(); string[] tokens = variableRecord.Split(','); if (tokens.Length >= 2) { double defaultDouble; if (double.TryParse(tokens[1], out defaultDouble)) { record.defaultValue = defaultDouble; } else { if (tokens[1].Trim() == "fallback") { record.fallback = true; } else { record.defaultString = tokens[1]; } } } if (tokens.Length >= 3) { record.cacheable = bool.Parse(tokens[2]); } handledVariables.Add(tokens[0], record); } active = InstantiateHandler(node, ourComp, out handlerFunction); }
public void Load(ConfigNode node) { if (!HighLogic.LoadedSceneIsFlight || FlightGlobals.ActiveVessel == null || parent.vessel == null) { return; } string[] values = node.GetValues("node"); int max = values.Length; for (int k = 0; k < max; k++) { string[] info = values[k].Split(delimiter, StringSplitOptions.RemoveEmptyEntries); Vector3d deltav = new Vector3d(); double d = 0.0; if (info.Length == 4) { double.TryParse(info[0], out d); deltav.x = d; d = 0.0; double.TryParse(info[1], out d); deltav.y = d; d = 0.0; double.TryParse(info[2], out d); deltav.z = d; d = 0.0; double.TryParse(info[3], out d); // at the very least it'll /act/ like a proper maneuver node. nodes.Add(new NodeState(deltav, d)); } } Debug.Log("Node Saver loaded " + max + " nodes."); }
public Harddisk(ConfigNode node) { Capacity = 10000; foreach (string s in node.GetValues("capacity")) { Capacity = Int32.Parse(s); } foreach (string s in node.GetValues("volumeName")) { Name = s; } foreach (var fileNode in node.GetNodes("file")) { Files.Add(new File(fileNode)); } }
public EngineMount(ConfigNode node) { name = node.GetStringValue("name"); layoutNames = node.GetValues("layoutName"); defaultDiameter = node.GetFloatValue("size", defaultDiameter); minDiameter = node.GetFloatValue("minSize", minDiameter); maxDiameter = node.GetFloatValue("maxSize", maxDiameter); engineSpacing = node.GetFloatValue("engineSpacing", engineSpacing); canAdjustSize = node.GetBoolValue("canAdjustSize", canAdjustSize); rotateEngineModels = node.GetBoolValues("rotateEngines"); mountDefinition = SSTUEngineMountDefinition.getMountDefinition(name); }
internal MathVariable(ConfigNode node) { name = node.GetValue("name"); string[] sources = node.GetValues("sourceVariable"); for (int i = 0; i < sources.Length; ++i) { VariableOrNumber sv = VariableOrNumber.Instantiate(sources[i]); sourceVariables.Add(sv); } if (sourceVariables.Count == 0) { throw new ArgumentException("Did not find any SOURCE_VARIABLE nodes in RPM_CUSTOM_VARIABLE", name); } string oper = node.GetValue("operator"); if (oper == Operator.NONE.ToString()) { op = Operator.NONE; } else if (oper == Operator.ADD.ToString()) { op = Operator.ADD; } else if (oper == Operator.SUBTRACT.ToString()) { op = Operator.SUBTRACT; } else if (oper == Operator.MULTIPLY.ToString()) { op = Operator.MULTIPLY; } else if (oper == Operator.DIVIDE.ToString()) { op = Operator.DIVIDE; } else if (oper == Operator.MAX.ToString()) { op = Operator.MAX; } else if (oper == Operator.MIN.ToString()) { op = Operator.MIN; } else { throw new ArgumentException("Found an invalid operator type in RPM_CUSTOM_VARIABLE", oper); } }
public VariableHandler(ConfigNode node, Part ourPart) { handlerName = node.GetValue("name"); foreach (string variableRecord in node.GetValues("variable")) { var record = new VariableRecord(); string[] tokens = variableRecord.Split(','); if (tokens.Length >= 2) { double defaultDouble; if (double.TryParse(tokens[1], NumberStyles.Any, CultureInfo.InvariantCulture, out defaultDouble)) { record.defaultValue = defaultDouble; } else { if (tokens[1].Trim() == "fallback") { record.fallback = true; } else { record.defaultValue = tokens[1]; //record.defaultString = tokens[1]; } } } if (tokens.Length >= 3) { record.cacheable = bool.Parse(tokens[2]); } handledVariables.Add(tokens[0], record); } active = InstantiateHandler(node, ourPart, out handlerFunction); }
public override void LoadFromNode(ConfigNode node) { base.LoadFromNode(node); var values = node.GetValues(ConfigName); if (values.Length == 0) return; CreateListIfNecessary(); bool createNewItems = false; if (Count != values.Length) { ClearList(); createNewItems = true; } for (int i = 0; i < values.Length; i++) { object obj = null; if (!createNewItems) obj = List[i]; CFGUtil.AssignConfigObject(this, values[i], ref obj); if (createNewItems) List.Add(obj); else List[i] = obj; // This may be self-assignment under certain circumstances } }
public static AnimationCurve ParseCurve(ConfigNode node) { var values = node.GetValues("key"); int length = (int)values.Length; var curve = new AnimationCurve(); for (int i = 0; i < length; i++) { string[] strArrays = values[i].Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); curve.AddKey(float.Parse(strArrays[0]), float.Parse(strArrays[1])); } return (curve); }
private Notes_Archived_Crew_Container loadCrew(ConfigNode node) { Notes_Archived_Crew_Container c = new Notes_Archived_Crew_Container(); for (int i = 0; i < node.GetValues("KERBAL").Length; i++) { string k = node.GetValues("KERBAL")[i]; if (string.IsNullOrEmpty(k)) continue; if (HighLogic.CurrentGame.CrewRoster == null) break; ProtoCrewMember p = HighLogic.CurrentGame.CrewRoster[k]; if (p == null) continue; c.addCrewObject(p); } return c; }
// Readers List<double[]> ReadCurve(FloatCurve curve) { ConfigNode config = new ConfigNode(); List<double[]> list = new List<double[]>(); NumericCollectionParser<double> value = new NumericCollectionParser<double>(); curve.Save(config); foreach (string k in config.GetValues("key")) { value.SetFromString(k); list.Add(value.value.ToArray()); } return list; }
private static void InsertValue(ConfigNode newNode, int index, string name, string value) { string[] oldValues = newNode.GetValues(name); if (index < oldValues.Length) { newNode.RemoveValues(name); int i = 0; for (; i < index; ++i) newNode.AddValue(name, oldValues[i]); newNode.AddValue(name, value); for (; i < oldValues.Length; ++i) newNode.AddValue(name, oldValues[i]); return; } newNode.AddValue(name, value); }
public override void OnLoad(ConfigNode node) { if (!compatible) { return; } if (MFSSettings.tankDefinitions == null) { MFSSettings.Initialize (); } // Load the volume. If totalVolume is specified, use that to calc the volume // otherwise scale up the provided volume. No KSPField support for doubles if (node.HasValue ("totalVolume") && double.TryParse (node.GetValue ("totalVolume"), out totalVolume)) { ChangeTotalVolume (totalVolume); } else if (node.HasValue ("volume") && double.TryParse (node.GetValue ("volume"), out volume)) { totalVolume = volume * 100d / utilization; } if (isDatabaseLoad) { MFSSettings.SaveOverrideList(part, node.GetNodes("TANK")); ParseBaseMass(node); ParseBaseCost(node); ParseInsulationFactor(node); typesAvailable = node.GetValues ("typeAvailable"); RecordManagedResources (); } else if (isEditorOrFlight) { // The amounts initialized flag is there so that the tank type loading doesn't // try to set up any resources. They'll get loaded directly from the save. UpdateTankType (false); // Destroy any resources still hanging around from the LOADING phase for (int i = part.Resources.Count - 1; i >= 0; --i) { PartResource partResource = part.Resources[i]; if (!tankList.Contains (partResource.resourceName)) continue; part.Resources.Remove(partResource.info.id); } RaiseResourceListChanged (); // Setup the mass massDirty = true; CalculateMass(); } }
public static FloatCurve ModifyCurveKeys(FloatCurve initialCurve, float vacMult, float atmMult, bool extendToZero) { ConfigNode tempNode = new ConfigNode(); initialCurve.Save(tempNode); string[] keyStrings = tempNode.GetValues("key"); float maxTime, ispAtMaxTime, secondTime, ispAtSecondTime, maxPressure; maxTime = ispAtMaxTime = secondTime = ispAtSecondTime = maxPressure = 0; FloatCurve newAtmosphereCurve = new FloatCurve(); maxTime = initialCurve.maxTime; for (int i = 0; i < keyStrings.Length; i++) { string[] splitKey = keyStrings[i].Split(' '); float scalar = vacMult + Convert.ToSingle(splitKey[0]) * (atmMult - vacMult); if (!extendToZero) scalar = Mathf.Clamp(scalar, Mathf.Min(atmMult, vacMult), Mathf.Max(atmMult, vacMult)); if (Convert.ToSingle(splitKey[0]) != 0) newAtmosphereCurve.Add(Convert.ToSingle(splitKey[0]), Convert.ToSingle(splitKey[1]) * scalar, Convert.ToSingle(splitKey[2]) * scalar, Convert.ToSingle(splitKey[3]) * scalar); else newAtmosphereCurve.Add(Convert.ToSingle(splitKey[0]), Convert.ToSingle(splitKey[1]) * scalar, 0, 0); if (i == keyStrings.Length - 2) { secondTime = Convert.ToSingle(splitKey[0]); ispAtSecondTime = Convert.ToSingle(splitKey[1]) * scalar; } } ispAtMaxTime = newAtmosphereCurve.Evaluate(maxTime); if (extendToZero && (ispAtSecondTime - ispAtMaxTime) >= 0.0001f) { maxPressure = maxTime + (0.01f - ispAtMaxTime) / (ispAtSecondTime - ispAtMaxTime) * (secondTime - maxTime); newAtmosphereCurve.Add(maxPressure, 0.01f, 0, 0); } return newAtmosphereCurve; }
public void Load(ConfigNode node) { string[] resourceStrings = node.GetValues(nodeName); foreach (string resourceString in resourceStrings) { string[] values = resourceString.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); if (values.Length == 2) { PartResourceDefinition resource = PartResourceLibrary.Instance.GetDefinition(values[0]); double ratio; if (resource != null && double.TryParse(values[1], out ratio)) { resources.Add(new MyResourceInfo(resource, ratio)); } else { Debug.Log("TAC Converter [" + this.GetHashCode().ToString("X") + "][" + Time.time + "]: Cannot parse \"" + resourceString + "\", something went wrong."); } } else { Debug.Log("TAC Converter [" + this.GetHashCode().ToString("X") + "][" + Time.time + "]: Wrong number of tokens when parsing \"" + resourceString + "\", expected two tokens but found " + values.Length); } } Debug.Log("TAC Converter [" + this.GetHashCode().ToString("X") + "][" + Time.time + "]: ResourceList loaded " + this.ToString() + "\nfrom " + node); }
public static bool LoadObjectFromConfig(object obj, ConfigNode node) { var objfields = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic).Where( field => Attribute.IsDefined(field, typeof(ConfigItem))); foreach (FieldInfo field in objfields) { object objValue = null; bool canParse = false; try { canParse = Parse(field, ref objValue, node.GetValues(field.Name), node.GetNode(field.Name)); } catch(Exception e) { throw new UnityException("Unable to parse \"" + field.Name + "\" in \"" + node.name + "\"!", e); } if (objValue != null) { field.SetValue(obj, objValue); } if (!canParse) { throw new UnityException("Unable to parse \"" + field.Name + "\" in \"" + node.name + "\"!"); } } return true; }
/** * Read configuration and perform pre-load initialisation. */ public void readConfig(ConfigNode rootNode) { string sIsCompressionEnabled = rootNode.GetValue("isCompressionEnabled"); if (sIsCompressionEnabled != null) { switch (sIsCompressionEnabled) { case "always": isCompressionEnabled = true; break; case "never": isCompressionEnabled = false; break; case "auto": isCompressionEnabled = null; break; default: Util.log("Invalid value for isCompressionEnabled: {0}", sIsCompressionEnabled); break; } } string sIsMipmapGenEnabled = rootNode.GetValue("isMipmapGenEnabled"); if (sIsMipmapGenEnabled != null) { switch (sIsMipmapGenEnabled) { case "always": isMipmapGenEnabled = true; break; case "never": isMipmapGenEnabled = false; break; case "auto": isMipmapGenEnabled = null; break; default: Util.log("Invalid value for isMipmapGenEnabled: {0}", sIsMipmapGenEnabled); break; } } Util.addRELists(rootNode.GetValues("generateMipmaps"), generateMipmaps); string sIsUnloadingEnabled = rootNode.GetValue("isUnloadingEnabled"); if (sIsUnloadingEnabled != null) { switch (sIsUnloadingEnabled) { case "always": isUnloadingEnabled = true; break; case "never": isUnloadingEnabled = false; break; case "auto": isUnloadingEnabled = null; break; default: Util.log("Invalid value for isUnloadingEnabled: {0}", sIsUnloadingEnabled); break; } } Util.addRELists(rootNode.GetValues("keepLoaded"), keepLoaded); }
public MountModelData(ConfigNode node) : base(node) { layoutNames = node.GetValues("layoutName"); defaultDiameter = node.GetFloatValue("size", defaultDiameter); minDiameter = node.GetFloatValue("minSize", minDiameter); maxDiameter = node.GetFloatValue("maxSize", maxDiameter); engineSpacing = node.GetFloatValue("engineSpacing", engineSpacing); canAdjustSize = node.GetBoolValue("canAdjustSize", canAdjustSize); rotateEngineModels = node.GetBoolValues("rotateEngines"); singleModel = node.GetBoolValue("singleModel", singleModel); }
public ModelDefinition(ConfigNode node) { name = node.GetStringValue("name", String.Empty); modelName = node.GetStringValue("modelName", String.Empty); techLimit = node.GetStringValue("techLimit", techLimit); height = node.GetFloatValue("height", height); volume = node.GetFloatValue("volume", volume); mass = node.GetFloatValue("mass", mass); cost = node.GetFloatValue("cost", cost); diameter = node.GetFloatValue("diameter", diameter); verticalOffset = node.GetFloatValue("verticalOffset", verticalOffset); invertForTop = node.GetBoolValue("invertForTop", invertForTop); invertForBottom = node.GetBoolValue("invertForBottom", invertForBottom); fairingDisabled = node.GetBoolValue("fairingDisabled", fairingDisabled); fairingTopOffset = node.GetFloatValue("fairingTopOffset"); rcsVerticalPosition = node.GetFloatValue("rcsVerticalPosition", rcsVerticalPosition); rcsHorizontalPosition = node.GetFloatValue("rcsHorizontalPosition", rcsHorizontalPosition); rcsVerticalRotation = node.GetFloatValue("rcsVerticalRotation", rcsVerticalRotation); rcsHorizontalRotation = node.GetFloatValue("rcsHorizontalRotation", rcsHorizontalRotation); defaultTextureSet = node.GetStringValue("defaultTextureSet"); String[] attachNodeStrings = node.GetValues("node"); int len = attachNodeStrings.Length; attachNodeData = new AttachNodeBaseData[len]; for (int i = 0; i < len; i++) { attachNodeData[i] = new AttachNodeBaseData(attachNodeStrings[i]); } ConfigNode[] textureSetNodes = node.GetNodes("TEXTURESET"); len = textureSetNodes.Length; textureSets = new ModelTextureSet[len]; for (int i = 0; i < len; i++) { textureSets[i] = new ModelTextureSet(textureSetNodes[i]); } if (node.HasValue("surface")) { surfaceNode = new AttachNodeBaseData(node.GetStringValue("surface")); } else { String val = (diameter*0.5f) + ",0,0,1,0,0,2"; surfaceNode = new AttachNodeBaseData(val); } }
/** * Read configuration and perform pre-load initialisation. */ public void readConfig(ConfigNode rootNode) { Util.parse(rootNode.GetValue("isHelmetRemovalEnabled"), ref isHelmetRemovalEnabled); Util.parse(rootNode.GetValue("isAtmSuitEnabled"), ref isAtmSuitEnabled); Util.parse(rootNode.GetValue("atmSuitPressure"), ref atmSuitPressure); Util.addLists(rootNode.GetValues("atmSuitBodies"), atmSuitBodies); Util.parse(rootNode.GetValue("forceLegacyFemales"), ref forceLegacyFemales); }
public MapMarkupLine(ConfigNode node) { if (!node.HasData) throw new ArgumentException("Map markup section with no data?!"); if (node.HasValue("body")) { string bodyName = node.GetValue("body").ToLower(); foreach (CelestialBody thatBody in FlightGlobals.fetch.bodies) { if (thatBody.GetName().ToLower() == bodyName) { body = thatBody; break; } } if (body == null) throw new ArgumentException("No celestial body matching '" + bodyName + "'."); } else { throw new ArgumentException("Found a map markup section that does not say which celestial body it refers to."); } color = Color.white; if (node.HasValue("color")) color = ConfigNode.ParseColor32(node.GetValue("color")); // Now to actually load in the points... foreach (string pointData in node.GetValues("vertex")) { string[] tokens = pointData.Split(','); if (tokens.Length != 2) throw new ArgumentException("Incorrect vertex format."); double x, y; if (!(double.TryParse(tokens[0].Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out x) && double.TryParse(tokens[1].Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out y))) throw new ArgumentException("Could not parse a vertex position."); if (x > 180d || x < -180d || y > 90d || y < -90d) throw new ArgumentException("Vertex positions must be in degrees appropriate to longitude and latitude."); points.Add(new Vector2d(x, y)); } }
public override void OnLoad(ConfigNode node) { if (!compatible) { return; } if (MFSSettings.tankDefinitions == null) { MFSSettings.Initialize (); } // Load the volume. If totalVolume is specified, use that to calc the volume // otherwise scale up the provided volume. No KSPField support for doubles if (node.HasValue ("totalVolume") && double.TryParse (node.GetValue ("totalVolume"), out totalVolume)) { ChangeTotalVolume (totalVolume); } else if (node.HasValue ("volume") && double.TryParse (node.GetValue ("volume"), out volume)) { totalVolume = volume * 100d / utilization; } using (PartMessageService.Instance.Ignore(this, null, typeof(PartResourcesChanged))) { if (isDatabaseLoad) { MFSSettings.SaveOverrideList(part, node.GetNodes("TANK")); ParseBaseMass(node); ParseBaseCost(node); typesAvailable = node.GetValues ("typeAvailable"); RecordManagedResources (); } else if (isEditorOrFlight) { // The amounts initialized flag is there so that the tank type loading doesn't // try to set up any resources. They'll get loaded directly from the save. UpdateTankType (false); // Destroy any resources still hanging around from the LOADING phase for (int i = part.Resources.Count - 1; i >= 0; --i) { PartResource partResource = part.Resources[i]; if (!tankList.Contains (partResource.resourceName)) continue; part.Resources.list.RemoveAt (i); DestroyImmediate (partResource); } RaiseResourceListChanged (); // Setup the mass part.mass = mass; MassChanged (mass); // compute massDelta based on prefab, if available. if ((object)(part.partInfo) != null) if ((object)(part.partInfo.partPrefab) != null) massDelta = part.mass - part.partInfo.partPrefab.mass; } } }
public static bool WildcardMatchValues(ConfigNode node, string type, string value) { double val = 0; bool compare = value.Length > 1 && (value[0] == '<' || value[0] == '>'); compare = compare && Double.TryParse(value.Substring(1), out val); string[] values = node.GetValues(type); for (int i = 0; i < values.Length; i++) { if (!compare && WildcardMatch(values[i], value)) return true; double val2; if (compare && Double.TryParse(values[i], out val2) && ((value[0] == '<' && val2 < val) || (value[0] == '>' && val2 > val))) { return true; } } return false; }
public static AnimationCurve LoadAnimationCurve(ConfigNode node) { string[] curve = node.GetValues("key"); return LoadAnimationCurve(curve); }
void PrintCurve(FloatCurve curve, string name) { ConfigNode config = new ConfigNode(); curve.Save(config); Debug.Log(name); foreach (string key in config.GetValues("key")) { Debug.Log("key = " + key); } }