/// <summary> /// Attempt to create Execute from the terminal control values. /// </summary> /// <param name="message">If controls are valid, null. Otherwise, an error message for the player.</param> /// <returns>If validation was successful, the action to execute, otherwise null.</returns> public bool ValidateControls(IMyCubeBlock autopilot, out string message) { string termString = TermToString(); if (termString == null) { termString = TermToString(out message); if (termString == null) { if (message == null) { Logger.AlwaysLog("TermToString is not correctly implemented by command: " + Identifier + '/' + GetType().Name, Logger.severity.ERROR); } Action = null; return(false); } } return(SetDisplayString(autopilot, termString, out message)); }
/// <summary> /// Sets DisplayString and parses to get Execute action. /// </summary> /// <param name="value">The full string that reflects this command, including identifier.</param> /// <param name="message">If Execute action could not be created, the reason. Otherwise, null.</param> /// <returns>True iff Execute action could be created by parsing value.</returns> public bool SetDisplayString(IMyCubeBlock autopilot, string value, out string message) { value = value.Replace('\n', ' ').Replace('\r', ' '); value = value.Trim(); m_displayString = value; foreach (string idOrAlias in IdAndAliases()) { Match m = Regex.Match(value, idOrAlias + @"\s*,?\s*(.*)", RegexOptions.IgnoreCase); if (m.Success) { Action = Parse(autopilot, m.Groups[1].Value, out message); return(Action != null); } } message = value + " does not start with " + Identifier + " or any alias"; Logger.AlwaysLog(message, Logger.severity.ERROR); Action = null; return(false); }