Inheritance: AbstractCommand
Ejemplo n.º 1
0
        /// <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");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Configures an ExternalAPICommand.
        /// </summary>
        /// <param name="externalData">Data passed by the Api.QueueCommandToFlightComputer</param>
        /// <returns>Configured ExternalAPICommand</returns>
        public static ExternalAPICommand FromExternal(ConfigNode externalData)
        {
            ExternalAPICommand command = new ExternalAPICommand();

            command.TimeStamp = RTUtil.GameTime;
            command.ConfigNodeToObject(command, externalData);

            return(command);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load and creates a command after saving a command. Returns null if no object
        /// has been loaded.
        /// </summary>
        /// <param name="n">Node with the command infos</param>
        /// <param name="fc">Current flightcomputer</param>
        public static ICommand LoadCommand(ConfigNode n, FlightComputer fc)
        {
            ICommand command = null;

            // switch the different commands
            switch (n.name)
            {
            case "AttitudeCommand":       { command = new AttitudeCommand(); break; }

            case "ActionGroupCommand":    { command = new ActionGroupCommand(); break; }

            case "BurnCommand":           { command = new BurnCommand(); break; }

            case "ManeuverCommand":       { command = new ManeuverCommand(); break; }

            case "CancelCommand":         { command = new CancelCommand(); break; }

            case "TargetCommand":         { command = new TargetCommand(); break; }

            case "EventCommand":          { command = new EventCommand(); break; }

            case "DriveCommand":          { command = new DriveCommand(); break; }

            case "ExternalAPICommand":    { command = new ExternalAPICommand(); break; }

            case "PartActionCommand":     { command = new PartActionCommand(); break; }

            case "StockAutopilotCommand": { command = new StockAutopilotCommand(); break; }

            case "HibernationCommand":    { command = new HibernationCommand(); break; }

            case "AxisGroupCommand":      { command = new AxisGroupCommand(); break; }

            case "PIDCommand":            { command = new PIDCommand(); break; }

            case "FlightControlCommand":  { command = new FlightControlCommand(); break; }
            }

            if (command != null)
            {
                ConfigNode.LoadObjectFromConfig(command, n);
                // additional loadings
                var result = command.Load(n, fc);
                RTLog.Verbose("Loading command {0}({1})={2}", RTLogLevel.LVL1, n.name, command.CmdGuid, result);
                // delete command if we can't load the command correctlys
                if (result == false)
                {
                    command = null;
                }
            }

            return(command);
        }
        /// <summary>
        /// Configures an ExternalAPICommand.
        /// </summary>
        /// <param name="externalData">Data passed by the Api.QueueCommandToFlightComputer</param>
        /// <returns>Configured ExternalAPICommand</returns>
        public static ExternalAPICommand FromExternal(ConfigNode externalData)
        {
            ExternalAPICommand command =  new ExternalAPICommand();
            command.TimeStamp = RTUtil.GameTime;
            command.ConfigNodeToObject(command,externalData);

            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");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Load and creates a command after saving a command. Returns null if no object
        /// has been loaded.
        /// </summary>
        /// <param name="n">Node with the command infos</param>
        /// <param name="fc">Current flightcomputer</param>
        public static ICommand LoadCommand(ConfigNode n, FlightComputer fc)
        {
            ICommand command = null;

            // switch the different commands
            switch (n.name)
            {
                case "AttitudeCommand":     { command = new AttitudeCommand(); break; }
                case "ActionGroupCommand":  { command = new ActionGroupCommand(); break; }
                case "BurnCommand":         { command = new BurnCommand(); break; }
                case "ManeuverCommand":     { command = new ManeuverCommand(); break; }
                case "CancelCommand":       { command = new CancelCommand(); break; }
                case "TargetCommand":       { command = new TargetCommand(); break; }
                case "EventCommand":        { command = new EventCommand(); break; }
                case "DriveCommand":        { command = new DriveCommand(); break; }
                case "ExternalAPICommand":  { command = new ExternalAPICommand(); break; }
            }

            if (command != null)
            {
                ConfigNode.LoadObjectFromConfig(command, n);
                // additional loadings
                var result = command.Load(n, fc);
                RTLog.Verbose("Loading command {0}({1})={2}", RTLogLevel.LVL1, n.name, command.CmdGuid, result);
                // delete command if we can't load the command correctlys
                if (result == false)
                    command = null;
            }

            return command;
        }