Beispiel #1
0
        /// <summary>
        /// The method that is called when a help command is read in
        /// </summary>
        /// <param name="simpit_command_args"> String array, contains arguments of help command</param>
        /// <exception cref="KerbalSimpitConsole.simpitConsoleException">
        /// Thrown when the number of passed arguments, exceededs what the help command can process</exception>
        public override void simpitCommandCall(KerbalSimpitConsole.commandArguments commandValues)
        {
            // Blank string array, used to store the help values that are to be printed
            string[] helpToPrint = new string[1];

            // If the number of arguments that are passed for the help command is above
            // 1, then an exception is thrown
            if (commandValues.arguments.Length > 1)
            {
                throw GetException(Localizer.GetStringByTag(Command_Lib.helpExtraValue("sim_help_arg_over")));
            }

            // if there is an argument present after the help command, do the following
            if (commandValues.arguments.Length == 1)
            {
                // Prints out help message if an argument is present
                // Gets key of passed commands dictionary entry. Here because the second command after the first is in string form
                var argumentCommand = KerbalSimpitConsole.simpitCommands.FirstOrDefault(x => x.Value.getSimpitCommand == commandValues.arguments[0]).Key;

                // Request help string and store
                helpToPrint[0] = helpStringGeneration(KerbalSimpitConsole.simpitCommands[argumentCommand]);
                // Print help message
                printHelpMessages(helpToPrint);
                return;
            }

            // Else if there is no argument following the command
            else
            {
                // Help to print is set to the size of the number of commands
                helpToPrint = new string[KerbalSimpitConsole.simpitCommands.Count];
                // Temp var
                int i = 0;
                // For the number of commands, run through the following
                foreach (KeyValuePair <KerbalSimpitConsole.simpitCommandCodes, KerbalSimpitConsole.SimpitConsoleCommand> entry in KerbalSimpitConsole.simpitCommands)
                {
                    // Create the help string for each command, and add it to the list
                    helpToPrint[i] = helpStringGeneration(entry.Value);
                    i++;
                }

                // Print the list of help strings
                printHelpMessages(helpToPrint);
                return;
            }
        }
        // When the command is called, what to do
        public override void simpitCommandCall(KerbalSimpitConsole.commandArguments commandArgs)
        {
            // If the command is a status request command
            // -- Maybe changed down the line, to enable the status of each port to be printed out
            if (commandArgs.arguments[0] == SERIAL_STATUS_COMMAND)
            {
                printSerialStatus();
            }

            // If the command is a serial start command
            if (commandArgs.arguments[0] == SERIAL_START_COMMAND)
            {
                Debug.Log("Serial start called");
                this.k_simpit.OpenPorts();
            }

            // If the command is a serial stop command
            if (commandArgs.arguments[0] == SERIAL_STOP_COMMAND)
            {
                this.k_simpit.ClosePorts();
            }
        }