diff --git a/src/RemoteTech/FlightComputer/Commands/AbstractCommand.cs b/src/RemoteTech/FlightComputer/Commands/AbstractCommand.cs
index d8efa8286..7e51996ff 100644
--- a/src/RemoteTech/FlightComputer/Commands/AbstractCommand.cs
+++ b/src/RemoteTech/FlightComputer/Commands/AbstractCommand.cs
@@ -39,15 +39,14 @@ public int CompareTo(ICommand dc)
///
/// Save the basic informations for every command.
///
- /// Node to save in
- /// Current flightcomputer
- public virtual void Save(ConfigNode n, FlightComputer fc)
+ /// Node to save in
+ /// Current flightcomputer
+ public virtual void Save(ConfigNode node, FlightComputer computer)
{
- ConfigNode save = new ConfigNode(this.GetType().Name);
try
{
// try to serialize 'this'
- ConfigNode.CreateConfigFromObject(this, 0, save);
+ ConfigNode.CreateConfigFromObject(this, 0, node);
}
catch (Exception) {}
@@ -58,9 +57,8 @@ public virtual void Save(ConfigNode n, FlightComputer fc)
TimeStamp = RTUtil.GameTime;
}
- save.AddValue("TimeStamp", TimeStamp);
- save.AddValue("ExtraDelay", ExtraDelay);
- n.AddNode(save);
+ node.AddValue("TimeStamp", TimeStamp);
+ node.AddValue("ExtraDelay", ExtraDelay);
}
///
diff --git a/src/RemoteTech/FlightComputer/Commands/ExternalAPICommand.cs b/src/RemoteTech/FlightComputer/Commands/ExternalAPICommand.cs
index f2773c36c..fb5ba8841 100644
--- a/src/RemoteTech/FlightComputer/Commands/ExternalAPICommand.cs
+++ b/src/RemoteTech/FlightComputer/Commands/ExternalAPICommand.cs
@@ -5,24 +5,26 @@ namespace RemoteTech.FlightComputer.Commands
{
public class ExternalAPICommand : AbstractCommand
{
+ /// original ConfigNode object passed from the api
+ private ConfigNode externalData;
/// Name of the mod who passed this command
- [Persistent] private string Executor;
+ private string Executor;
/// Label for this command on the queue
- [Persistent] private string QueueLabel;
+ private string QueueLabel;
/// Label for this command if its active
- [Persistent] private string ActiveLabel;
+ private string ActiveLabel;
/// Label for alert on no power
- [Persistent] private string ShortLabel;
+ private string ShortLabel;
/// The ReflectionType for the methods to invoke
- [Persistent] private string ReflectionType;
+ private string ReflectionType;
/// Name of the Pop-method on the ReflectionType
- [Persistent] private string ReflectionPopMethod = "";
+ private string ReflectionPopMethod = "";
/// Name of the Execution-method on the ReflectionType
- [Persistent] private string ReflectionExecuteMethod = "";
+ private string ReflectionExecuteMethod = "";
/// Name of the Abort-method on the ReflectionType
- [Persistent] private string ReflectionAbortMethod = "";
+ private string ReflectionAbortMethod = "";
/// GUID of the vessel
- [Persistent] private string GUIDString;
+ private string GUIDString;
/// true - when this command will be aborted
private bool AbortCommand = false;
@@ -127,26 +129,50 @@ public static ExternalAPICommand FromExternal(ConfigNode externalData)
{
ExternalAPICommand command = new ExternalAPICommand();
command.TimeStamp = RTUtil.GameTime;
- command.Executor = externalData.GetValue("Executor");
- command.ReflectionType = externalData.GetValue("ReflectionType");
- command.GUIDString = externalData.GetValue("GUIDString");
+ command.ConfigNodeToObject(command,externalData);
- if (externalData.HasValue("QueueLabel"))
- command.QueueLabel = externalData.GetValue("QueueLabel");
- if (externalData.HasValue("ActiveLabel"))
- command.ActiveLabel = externalData.GetValue("ActiveLabel");
- if (externalData.HasValue("ShortLabel"))
- command.ShortLabel = externalData.GetValue("ShortLabel");
+ return command;
+ }
+ ///
+ /// Maps the ConfigNode object passed from the api or loading to an ExternalAPICommand.
+ ///
+ /// Map the data to this object
+ /// Data to map onto the command
+ private void ConfigNodeToObject(ExternalAPICommand command, ConfigNode data)
+ {
+ command.externalData = new ConfigNode("ExternalData").AddNode(data);
+ command.Executor = data.GetValue("Executor");
+ command.ReflectionType = data.GetValue("ReflectionType");
+ command.GUIDString = data.GetValue("GUIDString");
+
+ if (data.HasValue("QueueLabel"))
+ command.QueueLabel = data.GetValue("QueueLabel");
+ if (data.HasValue("ActiveLabel"))
+ command.ActiveLabel = data.GetValue("ActiveLabel");
+ if (data.HasValue("ShortLabel"))
+ command.ShortLabel = data.GetValue("ShortLabel");
+
+ if (data.HasValue("ReflectionPopMethod"))
+ command.ReflectionPopMethod = data.GetValue("ReflectionPopMethod");
+ if (data.HasValue("ReflectionExecuteMethod"))
+ command.ReflectionExecuteMethod = data.GetValue("ReflectionExecuteMethod");
+ if (data.HasValue("ReflectionAbortMethod"))
+ command.ReflectionAbortMethod = data.GetValue("ReflectionAbortMethod");
+ }
- if (externalData.HasValue("ReflectionPopMethod"))
- command.ReflectionPopMethod = externalData.GetValue("ReflectionPopMethod");
- if (externalData.HasValue("ReflectionExecuteMethod"))
- command.ReflectionExecuteMethod = externalData.GetValue("ReflectionExecuteMethod");
- if (externalData.HasValue("ReflectionAbortMethod"))
- command.ReflectionAbortMethod = externalData.GetValue("ReflectionAbortMethod");
+ ///
+ /// Saves the original configNode passed from the api
+ /// to the persistent
+ ///
+ /// Node with the command infos to save in
+ /// Current flightcomputer
+ public override void Save(ConfigNode node, FlightComputer computer)
+ {
+ base.Save(node, computer);
- return command;
+ node.AddNode("ExternalData");
+ node.SetNode("ExternalData", this.externalData);
}
///
@@ -154,18 +180,22 @@ public static ExternalAPICommand FromExternal(ConfigNode externalData)
/// can't find the we'll notify a ScreenMessage
/// and remove the command.
///
- /// Node with the command infos
+ /// Node with the command infos to load
/// Current flightcomputer
/// true - loaded successfull
- public override bool Load(ConfigNode n, FlightComputer computer)
+ public override bool Load(ConfigNode node, FlightComputer computer)
{
try
{
- if(base.Load(n, computer))
+ if(base.Load(node, computer))
{
- // try loading the reflectionType
- this.getReflectionType(this.ReflectionType);
- return true;
+ if (node.HasNode("ExternalData"))
+ {
+ this.ConfigNodeToObject(this, node.GetNode("ExternalData"));
+ // try loading the reflectionType
+ this.getReflectionType(this.ReflectionType);
+ return true;
+ }
}
}
catch(Exception)
@@ -181,7 +211,8 @@ public override bool Load(ConfigNode n, FlightComputer computer)
/// ConfigNode to pass over to the reflection methods
private ConfigNode prepareDataForExternalMod()
{
- ConfigNode externalData = ConfigNode.CreateConfigFromObject(this);
+ ConfigNode externalData = new ConfigNode();
+ this.externalData.CopyTo(externalData);
externalData.AddValue("AbortCommand",this.AbortCommand);
return externalData;
diff --git a/src/RemoteTech/FlightComputer/FlightComputer.cs b/src/RemoteTech/FlightComputer/FlightComputer.cs
index 5f88f4dec..0c98d7899 100644
--- a/src/RemoteTech/FlightComputer/FlightComputer.cs
+++ b/src/RemoteTech/FlightComputer/FlightComputer.cs
@@ -489,11 +489,19 @@ public void Save(ConfigNode n)
foreach (KeyValuePair cmd in mActiveCommands)
{
- cmd.Value.Save(ActiveCommands, this);
+ // Save each active command on his own node
+ ConfigNode activeCommandNode = new ConfigNode(cmd.Value.GetType().Name);
+ cmd.Value.Save(activeCommandNode, this);
+ ActiveCommands.AddNode(activeCommandNode);
}
foreach (ICommand cmd in mCommandQueue)
- cmd.Save(Commands, this);
+ {
+ // Save each command on his own node
+ ConfigNode commandNode = new ConfigNode(cmd.GetType().Name);
+ cmd.Save(commandNode, this);
+ Commands.AddNode(commandNode);
+ }
ConfigNode FlightNode = new ConfigNode("FlightComputer");
FlightNode.AddValue("TotalDelay", TotalDelay);
diff --git a/src/RemoteTech/UI/DebugWindow.cs b/src/RemoteTech/UI/DebugWindow.cs
index a6c27e7b8..679ac00a7 100644
--- a/src/RemoteTech/UI/DebugWindow.cs
+++ b/src/RemoteTech/UI/DebugWindow.cs
@@ -433,6 +433,8 @@ private void drawAPITester()
dataNode.AddValue("ReflectionExecuteMethod", "ReceiveDataExec");
dataNode.AddValue("ReflectionAbortMethod", "ReceiveDataAbort");
dataNode.AddValue("GUIDString", this.ReceivDataVesselGuidInput);
+ dataNode.AddValue("YourData1", "RemoteTech");
+ dataNode.AddValue("YourDataN", "TechRemote");
var result = RemoteTech.API.API.QueueCommandToFlightComputer(dataNode);