Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/RemoteTech/FlightComputer/Commands/AbstractCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ public int CompareTo(ICommand dc)
/// <summary>
/// Save the basic informations for every command.
/// </summary>
/// <param name="n">Node to save in</param>
/// <param name="fc">Current flightcomputer</param>
public virtual void Save(ConfigNode n, FlightComputer fc)
/// <param name="node">Node to save in</param>
/// <param name="computer">Current flightcomputer</param>
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) {}

Expand All @@ -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);
}

/// <summary>
Expand Down
95 changes: 63 additions & 32 deletions src/RemoteTech/FlightComputer/Commands/ExternalAPICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ namespace RemoteTech.FlightComputer.Commands
{
public class ExternalAPICommand : AbstractCommand
{
/// <summary>original ConfigNode object passed from the api</summary>
private ConfigNode externalData;
/// <summary>Name of the mod who passed this command</summary>
[Persistent] private string Executor;
private string Executor;
/// <summary>Label for this command on the queue</summary>
[Persistent] private string QueueLabel;
private string QueueLabel;
/// <summary>Label for this command if its active</summary>
[Persistent] private string ActiveLabel;
private string ActiveLabel;
/// <summary>Label for alert on no power</summary>
[Persistent] private string ShortLabel;
private string ShortLabel;
/// <summary>The ReflectionType for the methods to invoke</summary>
[Persistent] private string ReflectionType;
private string ReflectionType;
/// <summary>Name of the Pop-method on the ReflectionType</summary>
[Persistent] private string ReflectionPopMethod = "";
private string ReflectionPopMethod = "";
/// <summary>Name of the Execution-method on the ReflectionType</summary>
[Persistent] private string ReflectionExecuteMethod = "";
private string ReflectionExecuteMethod = "";
/// <summary>Name of the Abort-method on the ReflectionType</summary>
[Persistent] private string ReflectionAbortMethod = "";
private string ReflectionAbortMethod = "";
/// <summary>GUID of the vessel</summary>
[Persistent] private string GUIDString;
private string GUIDString;
/// <summary>true - when this command will be aborted</summary>
private bool AbortCommand = false;

Expand Down Expand Up @@ -127,45 +129,73 @@ 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;
}

/// <summary>
/// Maps the ConfigNode object passed from the api or loading to an ExternalAPICommand.
/// </summary>
/// <param name="command">Map the data to this object</param>
/// <param name="data">Data to map onto the command</param>
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");
/// <summary>
/// Saves the original configNode <see cref="externalData"/> passed from the api
/// to the persistent
/// </summary>
/// <param name="node">Node with the command infos to save in</param>
/// <param name="computer">Current flightcomputer</param>
public override void Save(ConfigNode node, FlightComputer computer)
{
base.Save(node, computer);

return command;
node.AddNode("ExternalData");
node.SetNode("ExternalData", this.externalData);
}

/// <summary>
/// Loads the ExternalAPICommand from the persistent file. If the loading
/// can't find the <see cref="ReflectionType"/> we'll notify a ScreenMessage
/// and remove the command.
/// </summary>
/// <param name="n">Node with the command infos</param>
/// <param name="node">Node with the command infos to load</param>
/// <param name="computer">Current flightcomputer</param>
/// <returns>true - loaded successfull</returns>
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)
Expand All @@ -181,7 +211,8 @@ public override bool Load(ConfigNode n, FlightComputer computer)
/// <returns>ConfigNode to pass over to the reflection methods</returns>
private ConfigNode prepareDataForExternalMod()
{
ConfigNode externalData = ConfigNode.CreateConfigFromObject(this);
ConfigNode externalData = new ConfigNode();
this.externalData.CopyTo(externalData);
externalData.AddValue("AbortCommand",this.AbortCommand);

return externalData;
Expand Down
12 changes: 10 additions & 2 deletions src/RemoteTech/FlightComputer/FlightComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,19 @@ public void Save(ConfigNode n)

foreach (KeyValuePair<int, ICommand> 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);
Expand Down
2 changes: 2 additions & 0 deletions src/RemoteTech/UI/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down