本文整理汇总了C#中System.ConfigNode.RemoveValue方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigNode.RemoveValue方法的具体用法?C# ConfigNode.RemoveValue怎么用?C# ConfigNode.RemoveValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ConfigNode
的用法示例。
在下文中一共展示了ConfigNode.RemoveValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public override bool Load(ConfigNode configNode)
{
bool hasTargetBody = configNode.HasValue("targetBody");
// Load base class
bool valid = base.Load(configNode);
// Base class attempts to load a default, remove it and re-load
if (!hasTargetBody)
{
configNode.RemoveValue("targetBody");
valid &= ConfigNodeUtil.ParseValue<CelestialBody>(configNode, "targetBody", x => _targetBody = x, this, (CelestialBody)null);
}
// Before loading, verify the RemoteTech version
valid &= Util.Version.VerifyRemoteTechVersion();
valid &= ConfigNodeUtil.ParseValue<int>(configNode, "minCount", x => minCount = x, this, 1, x => Validation.GE(x, 0));
valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxCount", x => maxCount = x, this, int.MaxValue, x => Validation.GE(x, 0));
valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "activeVessel", x => activeVessel = x, this, false);
valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minRange", x => minRange = x, this, 0.0, x => Validation.GE(x, 0.0));
valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxRange", x => maxRange = x, this, double.MaxValue, x => Validation.GE(x, 0.0));
valid &= ConfigNodeUtil.ParseValue<HasAntennaParameter.AntennaType?>(configNode, "antennaType", x => antennaType = x, this, (HasAntennaParameter.AntennaType?)null);
valid &= ConfigNodeUtil.MutuallyExclusive(configNode, new string[] { "activeVessel" }, new string[] { "targetBody" }, this);
return valid;
}
示例2: DoExport
public static void DoExport()
{
ConfigNode configNode = new ConfigNode("CUSTOM_WAYPOINTS");
Instance.Save(configNode);
configNode.RemoveValue("name");
configNode.RemoveValue("scene");
configNode.Save(CustomWaypointsFileName,
"Waypoint Manager Custom Waypoints File\r\n" +
"//\r\n" +
"// This file contains an extract of Waypoint Manager custom waypoints.");
int count = Instance.waypoints.Count;
ScreenMessages.PostScreenMessage("Exported " + count + " waypoint" + (count != 1 ? "s" : "") + " to " + CustomWaypointsFileName,
6.0f, ScreenMessageStyle.UPPER_CENTER);
}
示例3: WriteValue
private static void WriteValue(ConfigNode configNode, string ValueName, object value)
{
if (configNode.HasValue(ValueName))
configNode.RemoveValue(ValueName);
configNode.AddValue(ValueName, value.ToString());
}
示例4: SetConfiguration
//.........这里部分代码省略.........
ConfigNode tNode = new ConfigNode("MODULE");
eiNode.CopyTo(tNode);
tNode.SetValue("name", "ModuleEngineIgnitor");
part.Modules["ModuleEngineIgnitor"].Load(tNode);
}
else // backwards compatible with EI nodes when using RF ullage etc.
{
ConfigNode eiNode = config.GetNode("ModuleEngineIgnitor");
if (eiNode.HasValue("ignitionsAvailable") && !config.HasValue("ignitions"))
{
config.AddValue("ignitions", eiNode.GetValue("ignitionsAvailable"));
}
if (eiNode.HasValue("useUllageSimulation") && !config.HasValue("ullage"))
config.AddValue("ullage", eiNode.GetValue("useUllageSimulation"));
if (eiNode.HasValue("isPressureFed") && !config.HasValue("pressureFed"))
config.AddValue("pressureFed", eiNode.GetValue("isPressureFed"));
if (!config.HasNode("IGNITOR_RESOURCE"))
foreach (ConfigNode resNode in eiNode.GetNodes("IGNITOR_RESOURCE"))
config.AddNode(resNode);
}
}
if (config.HasValue("ignitions"))
{
int ignitions;
if ((!HighLogic.LoadedSceneIsFlight || (vessel != null && vessel.situation == Vessel.Situations.PRELAUNCH)))
{
if (int.TryParse(config.GetValue("ignitions"), out ignitions))
{
ignitions = ConfigIgnitions(ignitions);
config.SetValue("ignitions", ignitions.ToString());
}
}
else
config.RemoveValue("ignitions");
}
if (pModule is ModuleEnginesRF)
(pModule as ModuleEnginesRF).SetScale(1d);
pModule.Load(config);
}
// fix for editor NaN
if (part.Resources.Contains("ElectricCharge") && part.Resources["ElectricCharge"].maxAmount < 0.1)
{ // hacking around a KSP bug here
part.Resources["ElectricCharge"].amount = 0;
part.Resources["ElectricCharge"].maxAmount = 0.1;
}
// set gimbal
if (config.HasValue("gimbalRange"))
{
float newGimbal = float.Parse(config.GetValue("gimbalRange"));
for (int m = 0; m < part.Modules.Count; ++m)
{
if (part.Modules[m] is ModuleGimbal)
{
ModuleGimbal g = part.Modules[m] as ModuleGimbal;
if (gimbalTransform.Equals("") || g.gimbalTransformName.Equals(gimbalTransform))
{
g.gimbalRange = newGimbal;
break;
}
}
}
}
if (config.HasValue("cost"))
configCost = scale * float.Parse(config.GetValue("cost"));
示例5: OnSave
public override void OnSave(ConfigNode node)
{
//print("a");
//print("AGXFlightSave " + currentFlightNode);
if(node.HasValue("LastSave"))
{
// print("c");
lastAGXSave = Convert.ToInt32(node.GetValue("LastSave"));
// print("d");
node.RemoveValue("LastSave");
}
//print("e");
//print("scensave1 " + currentFlightNode);
ConfigNode flightToSave = AGXFlight.FlightSaveToFile(currentFlightNode);
//print("f");
lastAGXSave = lastAGXSave + 1;
while (File.Exists(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExt" + lastAGXSave.ToString("00000") + ".cfg"))
{
lastAGXSave = lastAGXSave + 1;
}
// print("g " + flightToSave);
flightToSave.Save(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExt" + lastAGXSave.ToString("00000") + ".cfg");
//print("scensave2 " + flightToSave);
node.AddValue("LastSave", lastAGXSave.ToString());
//print("i");
// print("j");
}
示例6: ExpandNode
public ConfigNode ExpandNode(ConfigNode node, int level)
{
// Handle min/max level
int minLevel = ConfigNodeUtil.ParseValue<int>(node, "minLevel", 1);
int maxLevel = ConfigNodeUtil.ParseValue<int>(node, "maxLevel", 3);
if (level < minLevel || level > maxLevel)
{
return null;
}
ConfigNode newNode = new ConfigNode(node.name);
foreach (ConfigNode.Value pair in node.values)
{
newNode.AddValue(pair.name, FormatString(pair.value));
}
foreach (ConfigNode overrideNode in node.GetNodes())
{
if (overrideNode.name == "EFFECT")
{
continue;
}
if (overrideNode.HasValue(level.ToString()))
{
if (newNode.HasValue(overrideNode.name))
{
newNode.RemoveValue(overrideNode.name);
}
if (overrideNode.HasValue(level.ToString()))
{
newNode.AddValue(overrideNode.name, FormatString(overrideNode.GetValue(level.ToString())));
}
}
}
return newNode;
}
示例7: Update
//.........这里部分代码省略.........
{
CheckListForMultipleVessels();
//RefreshCurrentActions();
}
//else //not a docking or undocking, load single node //this else closed at line 3792
//{
if (!isUndocking && !isDocking)
{
ConfigNode oldVsl = new ConfigNode();
errLine = "8c";
if (AGXRoot != null)
{
errLine = "9";
// print("Root part changed, AGX reloadinga");
oldVsl = new ConfigNode(AGXRoot.vessel.rootPart.flightID.ToString());
if (AGXFlightNode.HasNode(AGXRoot.vessel.rootPart.flightID.ToString()))
{
errLine = "10";
//print("Root part changed, AGX reloadingb");
oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.rootPart.flightID.ToString());
AGXFlightNode.RemoveNode(AGXRoot.vessel.rootPart.flightID.ToString());
}
else if (AGXFlightNode.HasNode(AGXRoot.vessel.id.ToString()))
{
errLine = "10";
//print("Root part changed, AGX reloadingb");
oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.id.ToString());
AGXFlightNode.RemoveNode(AGXRoot.vessel.id.ToString());
}
errLine = "11";
//print("Root part changed, AGX reloadingc");
if (oldVsl.HasValue("name"))
{
oldVsl.RemoveValue("name");
}
oldVsl.AddValue("name", AGXRoot.vessel.vesselName);
errLine = "12";
// errLine = "13";
if (oldVsl.HasValue("currentKeyset"))
{
oldVsl.RemoveValue("currentKeyset");
}
oldVsl.AddValue("currentKeyset", CurrentKeySetFlight.ToString());
errLine = "13";
//errLine = "14";
if (oldVsl.HasValue("groupNames"))
{
oldVsl.RemoveValue("groupNames");
}
oldVsl.AddValue("groupNames", SaveGroupNames(""));
errLine = "14";
//errLine = "15";
if (oldVsl.HasValue("groupVisibility"))
{
oldVsl.RemoveValue("groupVisibility");
}
oldVsl.AddValue("groupVisibility", SaveGroupVisibility(""));
errLine = "15";
//errLine = "16";
if (oldVsl.HasValue("groupVisibilityNames"))
{
errLine = "15b";
oldVsl.RemoveValue("groupVisibilityNames");
errLine = "15c";
}
errLine = "15d";
示例8: CheckListForMultipleVessels
//call this when part count on vessel decrease to check for actions on split vessels
public void CheckListForMultipleVessels()
{
//print("call checklistformulti");
List<Vessel> curActsVessels = new List<Vessel>(); //find out if actions exist on vessel that left
foreach (AGXAction agAct in StaticData.CurrentVesselActions)
{
if (!curActsVessels.Contains(agAct.ba.listParent.part.vessel))
{
curActsVessels.Add(agAct.ba.listParent.part.vessel); //make a list of all vessels from actions in currentVesselActions list
}
}
foreach (Vessel vsl2 in curActsVessels) //our list of vessels from actions in currentVesselActions lsit
{
if (vsl2 != FlightGlobals.ActiveVessel) //this runs only on the seperated vessel, not our focus vessel
{
ConfigNode vsl2node = new ConfigNode(vsl2.rootPart.flightID.ToString()); //make our confignode
if (AGXFlightNode.HasNode(vsl2.rootPart.flightID.ToString())) //does this vessel exist in flight node?
{
vsl2node = AGXFlightNode.GetNode(vsl2.rootPart.flightID.ToString()); //vessel exists? load existing node, this should not happend but might if the same vessel docks/undocks in the same scene multiple times
vsl2node.RemoveNodes("PART");
AGXFlightNode.RemoveNode(vsl2.rootPart.flightID.ToString());
}
else if (AGXFlightNode.HasNode(vsl2.id.ToString())) //does this vessel exist in flight node?
{
vsl2node = AGXFlightNode.GetNode(vsl2.id.ToString()); //vessel exists? load existing node, this should not happend but might if the same vessel docks/undocks in the same scene multiple times
vsl2node.RemoveNodes("PART");
AGXFlightNode.RemoveNode(vsl2.id.ToString());
}
//RootPart elseif check here
else //new vessel, copy current values
{
vsl2node.AddValue("name", FlightGlobals.ActiveVessel.vesselName);
vsl2node.AddValue("currentKeyset", CurrentKeySetFlight.ToString());
//vsl2node.AddValue("groupNames", SaveGroupNames(""));
vsl2node.AddValue("groupVisibility", SaveGroupVisibility(""));
vsl2node.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
vsl2node.AddValue("DirectActionState", SaveDirectActionState(""));
}
if (vsl2node.HasValue("groupNames"))
{
vsl2node.RemoveValue("groupNames");
}
vsl2node.AddValue("groupNames", SaveGroupNames(""));
foreach (Part p in vsl2.Parts) //cycle parts in separated vessel to find actions
{
List<AGXAction> thisPartsActions = new List<AGXAction>();
thisPartsActions.AddRange(StaticData.CurrentVesselActions.FindAll(p2 => p2.ba.listParent.part == p));
//errLine = "18";
if (thisPartsActions.Count > 0)
{
//print("acts count " + thisPartsActions.Count);
ConfigNode partTemp = new ConfigNode("PART");
//errLine = "19";
partTemp.AddValue("name", p.vessel.vesselName);
partTemp.AddValue("vesselID", p.vessel.id);
partTemp.AddValue("flightID", p.flightID.ToString());
// partTemp.AddValue("relLocX", vsl2.rootPart.transform.InverseTransformPoint(p.transform.position).x);
//partTemp.AddValue("relLocY", vsl2.rootPart.transform.InverseTransformPoint(p.transform.position).y);
//partTemp.AddValue("relLocZ", vsl2.rootPart.transform.InverseTransformPoint(p.transform.position).z);
//errLine = "20";
foreach (AGXAction agxAct in thisPartsActions)
{
//print("acts countb " + thisPartsActions.Count);
//errLine = "21";
partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
}
//errLine = "22";
vsl2node.AddNode(partTemp);
//errLine = "23";
}
}
AGXFlightNode.AddNode(vsl2node);
StaticData.CurrentVesselActions.RemoveAll(ag => ag.ba.listParent.part.vessel == vsl2);
}
}
RefreshCurrentActions();
}
示例9: VesselOnRails
public void VesselOnRails(Vessel vsl)
{
print("Vessel on rails! " + vsl.name );
partOldVessel.RemoveAll(vsl2 => vsl2.pVsl == vsl);
List<AGXAction> UnloadVslActionsCheck = new List<AGXAction>();
UnloadVslActionsCheck.AddRange(AllVesselsActions.Where(agx => agx.ba.listParent.part.vessel == vsl));
//print("count check " + UnloadVslActionsCheck.Count + vsl.id.ToString());
//foreach (AGXAction agact in UnloadVslActionsCheck)
//{
// print("actionunload " + agact.ba.listParent.part.vessel.id.ToString() + " " + agact.ba.listParent.part.ConstructID);
//}
if (UnloadVslActionsCheck.Count > 0)
{
ConfigNode vslToUnload = new ConfigNode(vsl.id.ToString());
if(AGXFlightNode.HasNode(vsl.id.ToString()))
{
vslToUnload = AGXFlightNode.GetNode(vsl.id.ToString());
vslToUnload.RemoveNodes("PART");
AGXFlightNode.RemoveNode(vsl.id.ToString());
}
if (vsl == FlightGlobals.ActiveVessel)
{
if(vslToUnload.HasValue("name"))
{
vslToUnload.RemoveValue("name");
}
vslToUnload.AddValue("name",FlightGlobals.ActiveVessel.vesselName);
if (vslToUnload.HasValue("currentKeyset"))
{
vslToUnload.RemoveValue("currentKeyset");
}
vslToUnload.AddValue("currentKeyset", CurrentKeySet.ToString());
if (vslToUnload.HasValue("groupNames"))
{
vslToUnload.RemoveValue("groupNames");
}
vslToUnload.AddValue("groupNames", SaveGroupNames(""));
if (vslToUnload.HasValue("groupVisibility"))
{
vslToUnload.RemoveValue("groupVisibility");
}
vslToUnload.AddValue("groupVisibility", SaveGroupVisibility(""));
if (vslToUnload.HasValue("groupVisibilityNames"))
{
vslToUnload.RemoveValue("groupVisibilityNames");
}
vslToUnload.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
}
foreach (Part p in vsl.Parts)
{
List<AGXAction> thisPartsActions = new List<AGXAction>();
thisPartsActions.AddRange(UnloadVslActionsCheck.FindAll(p2 => p2.ba.listParent.part == p));
//errLine = "18";
if (thisPartsActions.Count > 0)
{
ConfigNode partTemp = new ConfigNode("PART");
//errLine = "19";
partTemp.AddValue("name", p.vessel.vesselName);
partTemp.AddValue("vesselID", p.vessel.id);
partTemp.AddValue("relLocX", p.orgPos.x);
partTemp.AddValue("relLocY", p.orgPos.y);
partTemp.AddValue("relLocZ", p.orgPos.z);
//errLine = "20";
foreach (AGXAction agxAct in thisPartsActions)
{
//errLine = "21";
partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
}
// errLine = "22";
vslToUnload.AddNode(partTemp);
//errLine = "23";
}
}
AGXFlightNode.AddNode(vslToUnload);
}
AllVesselsActions.RemoveAll(act2 => act2.ba.listParent.part.vessel == vsl);
loadedVessels.Remove(vsl); //remove vessel from loaded vessels list
}
示例10: FlightSaveToFile
//.........这里部分代码省略.........
errLine = "23";
}
}
if (AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.id.ToString()))
{
AGXFlightNode.RemoveNode(FlightGlobals.ActiveVessel.id.ToString());
}
AGXFlightNode.AddNode(thisVsl);
}
actionsToSave.RemoveAll(p3 => p3.ba.listParent.part.vessel == FlightGlobals.ActiveVessel);
//print("step1");
//foreach (AGXAction agAct in actionsToSave)
//{
// print("FlightSaveFocusDone " + agAct.ba.name + " " + agAct.ba.listParent.part.ConstructID);
//}
//print("step2");
while (actionsToSave.Count > 0)
{
//print("step3");
//foreach (AGXAction agAct in actionsToSave)
//{
// print("FlightSaveWhile " + agAct.ba.name + " " + agAct.ba.listParent.part.ConstructID);
//}
//print("step4");
Vessel vslToSave = actionsToSave.First().ba.listParent.part.vessel;
if(loadedVessels.Contains(vslToSave))
{
ConfigNode thisVslNode = new ConfigNode(vslToSave.id.ToString());
if (AGXFlightNode.HasNode(vslToSave.id.ToString()))
{
thisVslNode = AGXFlightNode.GetNode(vslToSave.id.ToString());
thisVslNode.RemoveValue("name");
thisVslNode.AddValue("name", vslToSave.vesselName);
}
else
{
thisVslNode.AddValue("name", vslToSave.vesselName);
errLine = "13";
thisVslNode.AddValue("currentKeyset", "1");
errLine = "14";
thisVslNode.AddValue("groupNames", "");
errLine = "15";
thisVslNode.AddValue("groupVisibility", "");
errLine = "16";
thisVslNode.AddValue("groupVisibilityNames", "");
}
thisVslNode.RemoveNodes("PART");
foreach (Part p in vslToSave.parts)
{
List<AGXAction> thisPartsActions = new List<AGXAction>();
thisPartsActions.AddRange(actionsToSave.FindAll(p2 => p2.prt == p));
errLine = "18";
if (thisPartsActions.Count > 0)
{
ConfigNode partTemp = new ConfigNode("PART");
errLine = "19";
partTemp.AddValue("name", p.vessel.name);
partTemp.AddValue("vesselID", vslToSave.id.ToString());
partTemp.AddValue("relLocX", p.orgPos.x);
partTemp.AddValue("relLocY", p.orgPos.y);
partTemp.AddValue("relLocZ", p.orgPos.z);
errLine = "20";
示例11: Update
public void Update()
{
string errLine = "1";
try
{
bool RootPartExists = new bool();
errLine = "2";
try
{
errLine = "3";
if (FlightGlobals.ActiveVessel.parts.Count > 0)
{
errLine = "4";
}
errLine = "5";
RootPartExists = true;
}
catch
{
errLine = "6";
RootPartExists = false;
}
errLine = "7";
if (RootPartExists)
{
errLine = "8";
if (AGXRoot != FlightGlobals.ActiveVessel.rootPart && flightNodeIsLoaded) //load keyset also
{
print("Root part changed, AGX reloading");
//loadFinished = false;
if (AGXRoot != null)
{
errLine = "9";
// print("Root part changed, AGX reloadinga");
ConfigNode oldVsl = new ConfigNode(AGXRoot.vessel.id.ToString());
if(AGXFlightNode.HasNode(AGXRoot.vessel.id.ToString()))
{
errLine = "10";
//print("Root part changed, AGX reloadingb");
oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.id.ToString());
AGXFlightNode.RemoveNode(AGXRoot.vessel.id.ToString());
}
errLine = "11";
//print("Root part changed, AGX reloadingc");
if(oldVsl.HasValue("name"));
{
oldVsl.RemoveValue("name");
}
oldVsl.AddValue("name", AGXRoot.vessel.vesselName);
errLine = "12";
// errLine = "13";
if (oldVsl.HasValue("currentKeyset")) ;
{
oldVsl.RemoveValue("currentKeyset");
}
oldVsl.AddValue("currentKeyset", CurrentKeySet.ToString());
errLine = "13";
//errLine = "14";
if (oldVsl.HasValue("groupNames")) ;
{
oldVsl.RemoveValue("groupNames");
}
oldVsl.AddValue("groupNames", SaveGroupNames(""));
errLine = "14";
//errLine = "15";
if (oldVsl.HasValue("groupVisibility")) ;
{
oldVsl.RemoveValue("groupVisibility");
}
oldVsl.AddValue("groupVisibility", SaveGroupVisibility(""));
errLine = "15";
//errLine = "16";
if (oldVsl.HasValue("groupVisibilityNames")) ;
{
oldVsl.RemoveValue("groupVisibilityNames");
}
oldVsl.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
errLine = "16";
AGXFlightNode.AddNode(oldVsl);
//print("Root part changed, AGX reloadingd " + oldVsl.GetValue("groupNames"));
}
errLine = "17";
//print("Root part changed, AGX reloadinge");
if (flightNodeIsLoaded && AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.id.ToString()))
{
errLine = "18";
//print("Root part changed, AGX reloadingf");
ConfigNode currentVessel = AGXFlightNode.GetNode(FlightGlobals.ActiveVessel.id.ToString());
CurrentKeySet = Convert.ToInt32(currentVessel.GetValue("currentKeyset"));
LoadGroupNames(currentVessel.GetValue("groupNames"));
LoadGroupVisibility(currentVessel.GetValue("groupVisibility"));
LoadGroupVisibilityNames(currentVessel.GetValue("groupVisibilityNames"));
//print("Root part changed, AGX reloadingg");
errLine = "19";
}
else
{
//.........这里部分代码省略.........
示例12: ModifyNode
//ModifyNode applies the ConfigNode mod as a 'patch' to ConfigNode original, then returns the patched ConfigNode.
// it uses FindConfigNodeIn(src, nodeType, nodeName, nodeTag) to recurse.
public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
{
ConfigNode newNode = new ConfigNode(original.name);
original.CopyTo(newNode);
foreach (ConfigNode.Value val in mod.values)
{
if (val.name[0] == '@')
{
// Modifying a value: Format is @key = value or @key,index = value
string valName = val.name.Substring(1);
int index = 0;
if (valName.Contains(","))
{
int.TryParse(valName.Split(',')[1], out index);
valName = valName.Split(',')[0];
}
newNode.SetValue(valName, val.value, index);
}
else if (val.name[0] == '!')
{
// Parsing: Format is @key = value or @key,index = value
string valName = val.name.Substring(1);
int index = 0;
if (valName.Contains(","))
{
int.TryParse(valName.Split(',')[1], out index);
valName = valName.Split(',')[0];
} // index is useless right now, but some day it might not be.
newNode.RemoveValue(valName);
}
else
{
newNode.AddValue(val.name, val.value);
}
}
foreach (ConfigNode subMod in mod.nodes)
{
if (subMod.name[0] == '@')
{
// Modifying a node: Format is @NODETYPE {...}, @NODETYPE[Name] {...} or @NODETYPE[Name,Tag] {...}
ConfigNode subNode = null;
if (subMod.name.Contains("["))
{ // format @NODETYPE[Name] {...} or @NODETYPE[Name, Tag] {...}
string nodeType = subMod.name.Substring(1).Split('[')[0].Trim();
string nodeName = subMod.name.Split('[')[1].Replace("]", "").Trim();
string nodeTag = null;
if (nodeName.Contains(","))
{ //format @NODETYPE[Name, Tag] {...}
nodeTag = nodeName.Split(',')[1];
nodeName = nodeName.Split(',')[0];
}
subNode = FindConfigNodeIn(newNode, nodeType, nodeName, nodeTag);
}
else
{ // format @NODETYPE {...}
string nodeType = subMod.name.Substring(1);
subNode = newNode.GetNode(nodeType);
}
// find the original subnode to modify, modify it, remove the original and add the modified.
if (subNode == null)
{
print("Could not find node to modify: " + subMod.name);
}
else
{
ConfigNode newSubNode = ModifyNode(subNode, subMod);
newNode.nodes.Remove(subNode);
newNode.nodes.Add(newSubNode);
}
}
else if (subMod.name[0] == '!')
{
// Removing a node: Format is !NODETYPE {}, !NODETYPE[Name] {} or !NODETYPE[Name,Tag] {}
ConfigNode subNode;
if (subMod.name.Contains("["))
{ // format !NODETYPE[Name] {} or !NODETYPE[Name, Tag] {}
string nodeType = subMod.name.Substring(1).Split('[')[0].Trim();
string nodeName = subMod.name.Split('[')[1].Replace("]", "").Trim();
string nodeTag = null;
if (nodeName.Contains(","))
{ //format !NODETYPE[Name, Tag] {}
nodeTag = nodeName.Split(',')[1];
nodeName = nodeName.Split(',')[0];
}
subNode = FindConfigNodeIn(newNode, nodeType, nodeName, nodeTag);
}
else
{ // format !NODETYPE {}
string nodeType = subMod.name.Substring(1);
subNode = newNode.GetNode(nodeType);
}
if (subNode != null)
//.........这里部分代码省略.........
示例13: SetValue
private static void SetValue(ConfigNode node, string key, float value)
{
if(node == null)
throw new ArgumentNullException("node");
// key is validated by public facing methods.
if(node.HasValue(key))
{
node.RemoveValue(key);
}
node.AddValue(key, value);
}
示例14: Load
/// <summary>
/// Loads the ParameterFactory from the given ConfigNode. The base version performs the following:
/// - Loads and validates the values for
/// - rewardScience
/// - rewardReputation
/// - rewardFunds
/// - failureReputation
/// - failureFunds
/// - advanceFunds
/// - optional
/// - targetBody
/// - disableOnStateChange
/// - child PARAMETER nodes
/// </summary>
/// <param name="configNode">The ConfigNode to load</param>
/// <returns>Whether the load was successful</returns>
public virtual bool Load(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);
// Load the iterator nodes
valid &= DataNode.LoadIteratorNodes(configNode, this);
if (!configNode.HasValue("targetBody"))
{
configNode.AddValue("targetBody", "@/targetBody");
}
if (!configNode.HasValue("ignoreTargetBody"))
{
valid &= ConfigNodeUtil.ParseValue<CelestialBody>(configNode, "targetBody", x => _targetBody = x, this);
}
else
{
configNode.RemoveValue("ignoreTargetBody");
}
// Load rewards
valid &= ConfigNodeUtil.ParseValue<float>(configNode, "rewardFunds", x => rewardFunds = x, this, 0.0f, x => Validation.GE(x, 0.0f));
valid &= ConfigNodeUtil.ParseValue<float>(configNode, "rewardReputation", x => rewardReputation = x, this, 0.0f, x => Validation.GE(x, 0.0f));
valid &= ConfigNodeUtil.ParseValue<float>(configNode, "rewardScience", x => rewardScience = x, this, 0.0f, x => Validation.GE(x, 0.0f));
valid &= ConfigNodeUtil.ParseValue<float>(configNode, "failureFunds", x => failureFunds = x, this, 0.0f, x => Validation.GE(x, 0.0f));
valid &= ConfigNodeUtil.ParseValue<float>(configNode, "failureReputation", x => failureReputation = x, this, 0.0f, x => Validation.GE(x, 0.0f));
// Load flags
valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "optional", x => optional = x, this, false);
valid &= ConfigNodeUtil.ParseValue<bool?>(configNode, "disableOnStateChange", x => disableOnStateChange = x, this, (bool?)null);
valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "completeInSequence", x => completeInSequence = x, this, false);
valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "hidden", x => hidden = x, this, false);
valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "hideChildren", x => hideChildren = x, this, false);
// Get title and notes
valid &= ConfigNodeUtil.ParseValue<string>(configNode, "title", x => title = x, this, (string)null);
valid &= ConfigNodeUtil.ParseValue<string>(configNode, "notes", x => notes = x, this, (string)null);
valid &= ConfigNodeUtil.ParseValue<string>(configNode, "completedMessage", x => completedMessage = x, this, (string)null);
config = configNode.ToString();
return valid;
}