public mode(ConfigNode node, Part part) { maxEC = 10; foreach (ConfigNode.Value nodeValue in node.values ?? new ConfigNode.ValueList()) { switch (nodeValue.name) { case "MaxEC": { maxEC = double.Parse(nodeValue.value); break; } } } ConfigNode.ValueList nodeValues = node.GetNode("FUELS").values; // No null coalescing intentional here fuels = new Fuel[nodeValues.Count]; for (byte n = 0; n < nodeValues.Count; n++) { fuels[n] = new Fuel(nodeValues[n]); } nodeValues = (node.GetNode("BYPRODUCTS") ?? new ConfigNode()).values; byproducts = new Fuel[nodeValues.Count]; for (byte n = 0; n < nodeValues.Count; n++) { byproducts[n] = new Fuel(nodeValues[n], true); } }
private static void loadDifficulties() { ImpactMonitor.Log("Loading difficulties from " + configFile); ConfigNode node = ConfigNode.Load(configFile); if (node.HasValue("use_spectrum_biomes")) { useBiomes = bool.Parse(node.GetValue("use_spectrum_biomes")); } if (node.HasNode("BIOMES_LIST")) { biomeDifficulties = new Dictionary <CelestialBody, Dictionary <string, int> >(); foreach (ConfigNode bodyNode in node.GetNodes()) { String bodyName = bodyNode.GetValue("body"); CelestialBody body = FlightGlobals.Bodies.Find(b => b.name == bodyName); Dictionary <string, int> difficulties = new Dictionary <string, int>(); ConfigNode.ValueList values = bodyNode.values; foreach (ConfigNode.Value s in values) { if (s.name == "body") { continue; } difficulties.Add(s.name, int.Parse(s.value)); } biomeDifficulties.Add(body, difficulties); } } }
public ConfigNodeWrapper(ConfigNode node) { name = node.name; values = node.values; foreach (ConfigNode n in node.nodes) { nodes.Add(new ConfigNodeWrapper(n)); } }
public mode(ConfigNode cn, Part p) { maxec = 10; foreach (ConfigNode.Value cnv in cn.values ?? new ConfigNode.ValueList()) { switch (cnv.name) { case "MaxEC": { maxec = float.Parse(cnv.value); break; } } } ConfigNode.ValueList vl = cn.GetNode("FUELS").values; // No null coalescing intentional here fuels = new fuel[vl.Count]; for (byte n = 0; n < vl.Count; n++) { fuels[n] = new fuel(vl[n]); } vl = (cn.GetNode("BYPRODUCTS") ?? new ConfigNode()).values; bypr = new fuel[vl.Count]; for (byte n = 0; n < vl.Count; n++) { bypr[n] = new fuel(vl[n], true); } tanks = (cn.GetNode("TANKS") ?? new ConfigNode()).values; vl = (cn.GetNode("EMITTERS") ?? new ConfigNode()).values; emttrs = new emttr[vl.Count]; for (byte n = 0; n < vl.Count; n++) { emttrs[n] = new emttr(vl[n]); } foreach (ConfigNode.Value cnv in (cn.GetNode("EMITSCALE") ?? new ConfigNode()).values) { Array.Find(emttrs, x => x.name == cnv.name).scale = float.Parse(cnv.value); } vl = (cn.GetNode("LIGHTS") ?? new ConfigNode()).values; lights = new light[vl.Count]; for (byte n = 0; n < vl.Count; n++) { lights[n] = new light(vl[n], p); } }
//汉化参数 public void HzValues(ConfigNode.ValueList valueList, List <Value> values) { foreach (ConfigNode.Value kspValue in valueList) { var hzValue = GetValue(values, kspValue.name); if (hzValue != null) { kspValue.value = hzValue.value; values.Remove(hzValue); } } }
private void configLoadKeyBinds(ConfigNode cn) { string logCaller = "Settings.configCreateOrUpdateKeyBinds(ConfigNode)"; Log.Trace("method start", logCaller); string kb = "KeyBinds"; ConfigNode keyBindsNode; if (!config.HasNode(kb)) { string message = "No KeyBinds node found in config. This error is not fatal to the load process. Default keybinds will be used instead."; Log.Trace(message, logCaller); return; } keyBindsNode = config.GetNode(kb); ConfigNode.ValueList vl = keyBindsNode.values; foreach (TCKeyBinding k in KeyBinds) { string userAction = k.TCUserAction.ToString(); if (vl.Contains(userAction)) { string keycombo = vl.GetValue(userAction); List <KeyCode> iekc = KeyboardInputManager.GetKeyCombinationFromString(keycombo); if (iekc == null) { Log.Warning("Key combination is not defined correctly: " + keycombo + " - Using default for user action " + userAction, logCaller); continue; } if (iekc.Contains(KeyCode.None)) { k.KeyCombination = new List <KeyCode>(); } else { k.KeyCombination = new List <KeyCode>(iekc); k.KeyCombinationString = keycombo; } } } Log.Trace("method end", logCaller); }
protected override void OnParameterLoad(ConfigNode node) { try { base.OnParameterLoad(node); minCount = Convert.ToInt32(node.GetValue("minCount")); maxCount = Convert.ToInt32(node.GetValue("maxCount")); filters = new List <Filter>(); foreach (ConfigNode child in node.GetNodes("FILTER")) { Filter filter = new Filter(); filter.type = ConfigNodeUtil.ParseValue <ParameterDelegateMatchType>(child, "type"); filter.parts = ConfigNodeUtil.ParseValue <List <AvailablePart> >(child, "part", new List <AvailablePart>()); filter.partModules = child.GetValues("partModule").ToList(); filter.partModuleTypes = child.GetValues("partModuleType").ToList(); filter.category = ConfigNodeUtil.ParseValue <PartCategories?>(child, "category", (PartCategories?)null); filter.manufacturer = ConfigNodeUtil.ParseValue <string>(child, "manufacturer", (string)null); filter.minCount = ConfigNodeUtil.ParseValue <int>(child, "minCount", 1); filter.maxCount = ConfigNodeUtil.ParseValue <int>(child, "maxCount", int.MaxValue); foreach (ConfigNode moduleNode in child.GetNodes("MODULE")) { ConfigNode.ValueList tmp = new ConfigNode.ValueList(); foreach (ConfigNode.Value v in moduleNode.values) { tmp.Add(new ConfigNode.Value(v.name, v.value)); } filter.partModuleExtended.Add(tmp); } filters.Add(filter); } CreateDelegates(); } finally { ParameterDelegate <Part> .OnDelegateContainerLoad(node); } }
protected override void OnParameterLoad(ConfigNode node) { try { base.OnParameterLoad(node); minCount = Convert.ToInt32(node.GetValue("minCount")); maxCount = Convert.ToInt32(node.GetValue("maxCount")); filters = new List<Filter>(); foreach (ConfigNode child in node.GetNodes("FILTER")) { Filter filter = new Filter(); filter.type = ConfigNodeUtil.ParseValue<ParameterDelegateMatchType>(child, "type"); filter.parts = ConfigNodeUtil.ParseValue<List<AvailablePart>>(child, "part", new List<AvailablePart>()); filter.partModules = child.GetValues("partModule").ToList(); filter.partModuleTypes = child.GetValues("partModuleType").ToList(); filter.category = ConfigNodeUtil.ParseValue<PartCategories?>(child, "category", (PartCategories?)null); filter.manufacturer = ConfigNodeUtil.ParseValue<string>(child, "manufacturer", (string)null); filter.minCount = ConfigNodeUtil.ParseValue<int>(child, "minCount", 1); filter.maxCount = ConfigNodeUtil.ParseValue<int>(child, "maxCount", int.MaxValue); foreach (ConfigNode moduleNode in child.GetNodes("MODULE")) { ConfigNode.ValueList tmp = new ConfigNode.ValueList(); foreach (ConfigNode.Value v in moduleNode.values) { tmp.Add(new ConfigNode.Value(v.name, v.value)); } filter.partModuleExtended.Add(tmp); } filters.Add(filter); } CreateDelegates(); } finally { ParameterDelegate<Part>.OnDelegateContainerLoad(node); } }
private void SanitizeNode(string partName, ConfigNode module, ConfigNode[] templates) { string name = module.GetValue("name"); if (module.HasNode("ScienceData")) { module.RemoveNodes("ScienceData"); } if (name == "Log") { module.ClearValues(); } ConfigNode template = templates.FirstOrDefault(t => t.GetValue("name") == name && (!t.HasValue("parts") || t.GetValue("parts").Split(',').Contains(partName))); if (template == null) { return; } ConfigNode.ValueList values = template.values; foreach (ConfigNode.Value val in values) { module.SetValue(val.name, val.value); } foreach (ConfigNode node in template.GetNodes()) //This should account for nested nodes, like RealChutes' PARACHUTE node { if (module.HasNode(node.name)) { foreach (ConfigNode.Value val in node.values) { module.GetNode(node.name).SetValue(val.name, val.value); } } } foreach (ConfigNode node in module.GetNodes("MODULE")) { SanitizeNode(partName, node, templates); } /* * if (name.Contains("ModuleEngines")) * { * module.SetValue("staged", "False"); * module.SetValue("flameout", "False"); * module.SetValue("EngineIgnited", "False"); * module.SetValue("engineShutdown", "False"); * module.SetValue("currentThrottle", "0"); * module.SetValue("manuallyOverridden", "False"); * } * else if (name == "ModuleScienceExperiment") * { * module.SetValue("Deployed", "False"); * module.SetValue("Inoperable", "False"); * } * else if (name == "ModuleParachute") * { * module.SetValue("staged", "False"); * module.SetValue("persistentState", "STOWED"); * } * else if (name == "Log") * { * module.ClearValues(); * } * * if (module.HasNode("ScienceData")) * { * module.RemoveNodes("ScienceData"); * } */ }
public override bool Load(ConfigNode configNode) { // Load base class bool valid = base.Load(configNode); // Read min/max first valid &= ConfigNodeUtil.ParseValue <int?>(configNode, "minCount", x => minCount = x, this, configNode.HasNode("VALIDATE") || configNode.HasNode("VALIDATE_ALL") || configNode.HasNode("NONE") ? (int?)null : 1, x => x == null || Validation.GE(x.Value, 0)); valid &= ConfigNodeUtil.ParseValue <int>(configNode, "maxCount", x => maxCount = x, this, minCount != null && minCount.Value == 0 ? 0 : int.MaxValue, x => Validation.GE(x, 0)); // Set the default match type ParameterDelegateMatchType defaultMatch = ParameterDelegateMatchType.FILTER; if (maxCount == 0) { defaultMatch = ParameterDelegateMatchType.NONE; } // Standard definition if (configNode.HasValue("part") || configNode.HasValue("partModule") || configNode.HasValue("partModuleType") || configNode.HasValue("category") || configNode.HasValue("manufacturer")) { PartValidation.Filter filter = new PartValidation.Filter(defaultMatch); valid &= ConfigNodeUtil.ParseValue <List <AvailablePart> >(configNode, "part", x => filter.parts = x, this, new List <AvailablePart>()); valid &= ConfigNodeUtil.ParseValue <List <string> >(configNode, "partModule", x => filter.partModules = x, this, new List <string>(), x => x.All(Validation.ValidatePartModule)); valid &= ConfigNodeUtil.ParseValue <List <string> >(configNode, "partModuleType", x => filter.partModuleTypes = x, this, new List <string>(), x => x.All(Validation.ValidatePartModuleType)); valid &= ConfigNodeUtil.ParseValue <PartCategories?>(configNode, "category", x => filter.category = x, this, (PartCategories?)null); valid &= ConfigNodeUtil.ParseValue <string>(configNode, "manufacturer", x => filter.manufacturer = x, this, (string)null); // Add modules foreach (ConfigNode moduleNode in configNode.GetNodes("MODULE")) { ConfigNode.ValueList tmp = new ConfigNode.ValueList(); foreach (ConfigNode.Value v in moduleNode.values) { tmp.Add(new ConfigNode.Value(v.name, v.value)); } filter.partModuleExtended.Add(tmp); } filters.Add(filter); } // Extended definition foreach (ConfigNode child in ConfigNodeUtil.GetChildNodes(configNode)) { ParameterDelegateMatchType matchType; if (child.name == "FILTER") { matchType = ParameterDelegateMatchType.FILTER; } else if (child.name == "VALIDATE") { matchType = ParameterDelegateMatchType.VALIDATE; } else if (child.name == "VALIDATE_ALL") { matchType = ParameterDelegateMatchType.VALIDATE_ALL; } else if (child.name == "NONE") { matchType = ParameterDelegateMatchType.NONE; } else { LoggingUtil.LogError(this, ErrorPrefix() + ": unexpected node '" + child.name + "'."); valid = false; continue; } if (defaultMatch == ParameterDelegateMatchType.NONE) { matchType = ParameterDelegateMatchType.NONE; } PartValidation.Filter filter = new PartValidation.Filter(matchType); valid &= ConfigNodeUtil.ParseValue <List <AvailablePart> >(child, "part", x => filter.parts = x, this, new List <AvailablePart>()); valid &= ConfigNodeUtil.ParseValue <List <string> >(child, "partModule", x => filter.partModules = x, this, new List <string>(), x => x.All(Validation.ValidatePartModule)); valid &= ConfigNodeUtil.ParseValue <List <string> >(child, "partModuleType", x => filter.partModuleTypes = x, this, new List <string>()); valid &= ConfigNodeUtil.ParseValue <PartCategories?>(child, "category", x => filter.category = x, this, (PartCategories?)null); valid &= ConfigNodeUtil.ParseValue <string>(child, "manufacturer", x => filter.manufacturer = x, this, (string)null); foreach (ConfigNode moduleNode in child.GetNodes("MODULE")) { ConfigNode.ValueList tmp = new ConfigNode.ValueList(); foreach (ConfigNode.Value v in moduleNode.values) { tmp.Add(new ConfigNode.Value(v.name, v.value)); } filter.partModuleExtended.Add(tmp); } if (matchType == ParameterDelegateMatchType.VALIDATE) { valid &= ConfigNodeUtil.ParseValue <int>(child, "minCount", x => filter.minCount = x, this, 1, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue <int>(child, "maxCount", x => filter.maxCount = x, this, int.MaxValue, x => Validation.GE(x, 0)); } filters.Add(filter); } return(valid); }
public override bool Load(ConfigNode configNode) { // Load base class bool valid = base.Load(configNode); // Read min/max first valid &= ConfigNodeUtil.ParseValue<int>(configNode, "minCount", x => minCount = x, this, configNode.HasNode("VALIDATE") || configNode.HasNode("VALIDATE_ALL") || configNode.HasNode("NONE") ? 0 : 1, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxCount", x => maxCount = x, this, int.MaxValue, x => Validation.GE(x, 0)); // Set the default match type ParameterDelegateMatchType defaultMatch = ParameterDelegateMatchType.FILTER; if (maxCount == 0) { defaultMatch = ParameterDelegateMatchType.NONE; } // Standard definition if (configNode.HasValue("part") || configNode.HasValue("partModule") || configNode.HasValue("category") || configNode.HasValue("manufacturer")) { PartValidation.Filter filter = new PartValidation.Filter(defaultMatch); valid &= ConfigNodeUtil.ParseValue<List<AvailablePart>>(configNode, "part", x => filter.parts = x, this, new List<AvailablePart>()); valid &= ConfigNodeUtil.ParseValue<List<string>>(configNode, "partModule", x => filter.partModules = x, this, new List<string>(), x => x.All(Validation.ValidatePartModule)); valid &= ConfigNodeUtil.ParseValue<PartCategories?>(configNode, "category", x => filter.category = x, this, (PartCategories?)null); valid &= ConfigNodeUtil.ParseValue<string>(configNode, "manufacturer", x => filter.manufacturer = x, this, (string)null); filters.Add(filter); } // Extended definition foreach (ConfigNode child in ConfigNodeUtil.GetChildNodes(configNode)) { ParameterDelegateMatchType matchType; if (child.name == "FILTER") { matchType = ParameterDelegateMatchType.FILTER; } else if (child.name == "VALIDATE") { matchType = ParameterDelegateMatchType.VALIDATE; } else if (child.name == "VALIDATE_ALL") { matchType = ParameterDelegateMatchType.VALIDATE_ALL; } else if (child.name == "NONE") { matchType = ParameterDelegateMatchType.NONE; } else { LoggingUtil.LogError(this, ErrorPrefix() + ": unexpected node '" + child.name + "'."); valid = false; continue; } if (defaultMatch == ParameterDelegateMatchType.NONE) { matchType = ParameterDelegateMatchType.NONE; } PartValidation.Filter filter = new PartValidation.Filter(matchType); valid &= ConfigNodeUtil.ParseValue<List<AvailablePart>>(child, "part", x => filter.parts = x, this, new List<AvailablePart>()); valid &= ConfigNodeUtil.ParseValue<List<string>>(child, "partModule", x => filter.partModules = x, this, new List<string>(), x => x.All(Validation.ValidatePartModule)); valid &= ConfigNodeUtil.ParseValue<PartCategories?>(child, "category", x => filter.category = x, this, (PartCategories?)null); valid &= ConfigNodeUtil.ParseValue<string>(child, "manufacturer", x => filter.manufacturer = x, this, (string)null); foreach (ConfigNode moduleNode in child.GetNodes("MODULE")) { ConfigNode.ValueList tmp = new ConfigNode.ValueList(); foreach (ConfigNode.Value v in moduleNode.values) { tmp.Add(new ConfigNode.Value(v.name, v.value)); } filter.partModuleExtended.Add(tmp); } if (matchType == ParameterDelegateMatchType.VALIDATE) { valid &= ConfigNodeUtil.ParseValue<int>(child, "minCount", x => filter.minCount = x, this, 1, x => Validation.GE(x, 0)); valid &= ConfigNodeUtil.ParseValue<int>(child, "maxCount", x => filter.maxCount = x, this, int.MaxValue, x => Validation.GE(x, 0)); } filters.Add(filter); } return valid; }