void ProcessValue(string sline, AttributeElement currentActiveAttribute) { if (currentActiveAttribute != null) { if (currentActiveAttribute.Text == "hullID") { ProcessHullID(currentActiveAttribute); } else if (currentActiveAttribute.Text == "raceKeys") { ProcessRaceKeys(currentActiveAttribute); } else if (currentActiveAttribute.Text == "hullKeys") { ProcessHullKeys(currentActiveAttribute); } else { IList <XmlCompletionData> data = GetValueData(sline, currentActiveAttribute); if (data != null) { currentActiveAttribute.Values = new System.Collections.ObjectModel.ObservableCollection <XmlCompletionData>(); foreach (XmlCompletionData item in data) { currentActiveAttribute.Values.Add(item); } } } } }
void ProcessRaceKeys(AttributeElement currentActiveAttribute) { currentActiveAttribute.AttributeType = AttributeType.LimitedListString; currentActiveAttribute.Values = new System.Collections.ObjectModel.ObservableCollection <XmlCompletionData>(); //foreach (VesselDataLibrary.Xml.Vessel v in vesselData.Vessels) //{ // string race = string.Empty; List <XmlCompletionData> data = new List <XmlCompletionData>(); if (vesselData != null) { foreach (VesselDataLibrary.Xml.HullRace r in vesselData.HullRaces) { string key = string.Format(CultureInfo.InvariantCulture, "{0} {1}", r.Name, r.Keys); data.Add(new XmlCompletionData(key)); } } if (data.Count > 0) { currentActiveAttribute.Values = new System.Collections.ObjectModel.ObservableCollection <XmlCompletionData>(); foreach (XmlCompletionData value in data) { currentActiveAttribute.Values.Add(value); } } //} }
void ProcessHullID(AttributeElement currentActiveAttribute) { currentActiveAttribute.AttributeType = AttributeType.LimitedListString; currentActiveAttribute.Values = new System.Collections.ObjectModel.ObservableCollection <XmlCompletionData>(); if (vesselData != null) { foreach (VesselDataLibrary.Xml.Vessel v in vesselData.Vessels) { string race = string.Empty; foreach (VesselDataLibrary.Xml.HullRace r in vesselData.HullRaces) { if (v.Side == r.ID) { race = r.Name; break; } } string wrkD = string.Empty; if (!string.IsNullOrEmpty(v.Description.Text)) { wrkD = v.Description.Text.Replace("^", "\r\n"); } if (string.IsNullOrEmpty(wrkD)) { wrkD = string.Format(CultureInfo.InvariantCulture, "{0} {1}", v.ClassName, v.BroadType); } string de = string.Format(CultureInfo.InvariantCulture, "{2} ({0}) {1}", race, wrkD, v.UniqueID.ToString(CultureInfo.InvariantCulture)); StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; if (wrkD.Contains("\r\n")) { wrkD = wrkD.Substring(0, wrkD.IndexOf("\r\n", StringComparison.OrdinalIgnoreCase)); } TextBlock t = new TextBlock(); t.VerticalAlignment = VerticalAlignment.Center; t.Text = v.UniqueID.ToString(CultureInfo.InvariantCulture); t.Padding = new Thickness(0, 0, 4, 0); t.FontWeight = FontWeights.Bold; sp.Children.Add(t); TextBlock t2 = new TextBlock(); t2.VerticalAlignment = VerticalAlignment.Center; t2.Text = string.Format(CultureInfo.InvariantCulture, "({0}) {1}", race, wrkD); sp.Children.Add(t2); XmlCompletionData value = new XmlCompletionData(v.UniqueID.ToString(CultureInfo.InvariantCulture), de, sp); currentActiveAttribute.Values.Add(value); } } }
static IList <XmlCompletionData> GetValueData(string line, AttributeElement currentAttribute) { List <XmlCompletionData> retVal = null; //VALID: 0-360 //VALID: -100000 to 100000 //VALID: text //VALID: 0 or 1 //VALID: nebulas, asteroids, mines string wrk = line.Substring(7).Trim(); List <XmlCompletionData> wrkData = new List <XmlCompletionData>(); currentAttribute.AttributeType = AttributeType.LimitedListString; if (char.IsDigit(wrk[0]) || (wrk[0] == '-' && char.IsDigit(wrk[1])) || wrk.StartsWith("signed", StringComparison.OrdinalIgnoreCase)) { SetExpressType(currentAttribute); } else if (wrk.StartsWith("anything", StringComparison.OrdinalIgnoreCase)) { currentAttribute.AttributeType = AttributeType.FreeString; } else if (wrk.StartsWith("text", StringComparison.OrdinalIgnoreCase) || wrk.Contains(',')) { wrkData = CheckForSpecialValueString(wrk, currentAttribute); if (wrkData == null) { currentAttribute.AttributeType = AttributeType.FreeString; } else { currentAttribute.AttributeType = AttributeType.LimitedListString; } } if (wrkData != null && wrkData.Count > 0) { retVal = new List <XmlCompletionData>(wrkData); } return(retVal); }
//static readonly ILog _log = LogManager.GetLogger(typeof(Commands)); //if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); } //if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); } //Load from mission-file-docs.txt void LoadMissionDoc() { //First load special critical COMMANDS, then load from file. //LoadCreate(); //12/30/2012 string txt = Properties.Resources.mission_file_docs; bool started = false; CommandElement currentActiveCommand = null; AttributeElement currentActiveAttribute = null; foreach (string ll in txt.Split('\n')) { string sline = ll.Replace("\t", string.Empty).Replace("\r", string.Empty).Trim(); if (!started) { if (sline.StartsWith("COMMAND", StringComparison.OrdinalIgnoreCase)) { started = true; } } if (started) { switch (DetermineLineType(sline)) { case LineType.Command: case LineType.Condition: KeyValuePair <string, string> cmd = GetCommandData(sline); currentActiveCommand = new CommandElement(cmd.Key, cmd.Value); if (!CommandDictionary.ContainsKey(cmd.Key)) { CommandDictionary.Add(cmd.Key, currentActiveCommand); } else { currentActiveCommand = CommandDictionary[cmd.Key]; } break; case LineType.Attribute: if (currentActiveCommand != null) { bool foundAttrib = false; currentActiveAttribute = new AttributeElement(GetAttributeData(sline)); currentActiveAttribute.ParentCommand = currentActiveCommand.Text; foreach (AttributeElement att in currentActiveCommand.Attributes) { if (att.Text == currentActiveAttribute.Text) { foundAttrib = true; currentActiveAttribute = att; break; } } if (!foundAttrib) { currentActiveCommand.Attributes.Add(currentActiveAttribute); } } break; case LineType.ValueList: ProcessValue(sline, currentActiveAttribute); break; } } } }
static List <XmlCompletionData> CheckForSpecialValueString(string wrk, AttributeElement currentAttribute) { List <XmlCompletionData> retVal = null; List <XmlCompletionData> wrkData = new List <XmlCompletionData>(); switch (currentAttribute.ParentCommand) { //case "add_ai": // if (currentAttribute.Text == "type") // { // wrkData.Add(new XmlCompletionData("TRY_TO_BECOME_LEADER")); // wrkData.Add(new XmlCompletionData("CHASE_PLAYER")); // wrkData.Add(new XmlCompletionData("CHASE_NEUTRAL")); // wrkData.Add(new XmlCompletionData("CHASE_ENEMY")); // wrkData.Add(new XmlCompletionData("CHASE_STATION")); // wrkData.Add(new XmlCompletionData("CHASE_WHALE")); // wrkData.Add(new XmlCompletionData("AVOID_WHALE")); // wrkData.Add(new XmlCompletionData("AVOID_BLACK_HOLE")); // wrkData.Add(new XmlCompletionData("CHASE_ANGER")); // wrkData.Add(new XmlCompletionData("CHASE_FLEET")); // wrkData.Add(new XmlCompletionData("FOLLOW_LEADER")); // wrkData.Add(new XmlCompletionData("FOLLOW_COMMS_ORDERS")); // wrkData.Add(new XmlCompletionData("LEADER_LEADS")); // wrkData.Add(new XmlCompletionData("ELITE_AI")); // wrkData.Add(new XmlCompletionData("DIR_THROTTLE")); // wrkData.Add(new XmlCompletionData("POINT_THROTTLE")); // wrkData.Add(new XmlCompletionData("TARGET_THROTTLE")); // wrkData.Add(new XmlCompletionData("ATTACK")); // wrkData.Add(new XmlCompletionData("DEFEND")); // wrkData.Add(new XmlCompletionData("PROCEED_TO_EXIT")); // wrkData.Add(new XmlCompletionData("FIGHTER_BINGO")); // wrkData.Add(new XmlCompletionData("LAUNCH_FIGHTERS")); // } // else if (currentAttribute.Text == "targetName") // { // wrkData.Add(new XmlCompletionData("ATTACK")); // wrkData.Add(new XmlCompletionData("TARGET_THROTTLE")); // } // break; case "create": if (currentAttribute.Text == "type") { //station, player, enemy, neutral, anomaly, blackHole, monster, genericMesh, whale, nebulas, asteroids, mines foreach (string val in "station,player,enemy,neutral,anomaly,blackHole,monster,genericMesh,whale,nebulas,asteroids,mines".Split(',')) { wrkData.Add(new XmlCompletionData(val.Trim())); } } break; case "set_fleet_property": if (currentAttribute.Text == "property") { foreach (string val in "fleetSpacing,fleetMaxRadius".Split(',')) { wrkData.Add(new XmlCompletionData(val.Trim())); } } break; //case "set_player_grid_damage": // if (currentAttribute.Text == "systemType") // { // foreach (string val in "systemBeam,systemTorpedo,systemTactical,systemTurning,systemImpulse,systemWarp,systemFrontShield,systemBackShield".Split(',')) // { // wrkData.Add(new XmlCompletionData(val.Trim())); // } // } // break; default: if (currentAttribute.Text == "property") { wrkData.AddRange(GetPropertyList()); } if (wrk.Trim() != "text" && wrk.Trim() != "anything") { foreach (string val in wrk.Replace(" ", string.Empty).Split(',')) { wrkData.Add(new XmlCompletionData(val.Trim())); } } break; } if (wrkData.Count > 0) { retVal = new List <XmlCompletionData>(wrkData); } return(retVal); }
static void SetExpressType(AttributeElement currentAttribute) { currentAttribute.AttributeType = AttributeType.ExpressionValue; }
void ProcessHullKeys(AttributeElement currentActiveAttribute) { currentActiveAttribute.AttributeType = AttributeType.LimitedListString; currentActiveAttribute.Values = new System.Collections.ObjectModel.ObservableCollection <XmlCompletionData>(); List <string> vesselDictionary = new List <string>(); List <XmlCompletionData> items = new List <XmlCompletionData>(); if (vesselData != null) { foreach (VesselDataLibrary.Xml.Vessel v in vesselData.Vessels) { XmlCompletionData value = null; string key = v.ClassName + " " + v.BroadType; if (!vesselDictionary.Contains(key)) { string race = string.Empty; foreach (VesselDataLibrary.Xml.HullRace r in vesselData.HullRaces) { if (v.Side == r.ID) { race = r.Name; break; } } string wrkD = string.Empty; if (!string.IsNullOrEmpty(v.Description.Text)) { wrkD = v.Description.Text.Replace("^", "\r\n"); } string desc = string.Format(CultureInfo.InvariantCulture, "{0} ({1}-{2})", key, wrkD, race); StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; TextBlock t = new TextBlock(); t.VerticalAlignment = VerticalAlignment.Center; t.Text = key; t.Padding = new Thickness(0, 0, 4, 0); t.FontWeight = FontWeights.Bold; sp.Children.Add(t); TextBlock t2 = new TextBlock(); t2.VerticalAlignment = VerticalAlignment.Center; t2.Text = string.Format(CultureInfo.InvariantCulture, "({0}) {1}", race, wrkD); sp.Children.Add(t2); value = new XmlCompletionData(key, desc, sp); vesselDictionary.Add(key); items.Add(value); } if (items.Count > 0) { currentActiveAttribute.Values = new System.Collections.ObjectModel.ObservableCollection <XmlCompletionData>(); foreach (XmlCompletionData data in items) { currentActiveAttribute.Values.Add(data); } } } } }
void DoValueEntering() { //add value completion list. if (!CheckedForValueCompletion) { //if (char.IsLetterOrDigit(text[text.Length - 1]) || text[text.Length - 1] == ' ') //{ //find attribute (we are within quote) string attrib = null; int i = Content.Document.Text.LastIndexOf(" ", Content.CaretOffset, StringComparison.OrdinalIgnoreCase); if (i > -1 && XmlHelper.IsInTag(Content.Document.Text, i)) { int j = Content.Document.Text.LastIndexOf("=", Content.CaretOffset, StringComparison.OrdinalIgnoreCase); if (j > i) { attrib = Content.Document.Text.Substring(i + 1, j - i - 1).Trim(); } } string nd = XmlHelper.GetNodeName(XmlHelper.GetLastNode(Content.Document.Text, Content.CaretOffset)); if (Commands.Current.CommandDictionary.ContainsKey(nd)) { CommandElement cmd1 = Commands.Current.CommandDictionary[nd] as CommandElement; AttributeElement elem = null; foreach (AttributeElement cmd in cmd1.Attributes) { if (cmd.Text == attrib) { elem = cmd; break; } } if (elem != null) { if (elem.AttributeType == AttributeType.ExpressionValue) { List <string> variables = GetVariables(); variables.Sort(); List <ICompletionData> data = new List <ICompletionData>(); string lastVar = string.Empty; foreach (string v in variables) { if (v != lastVar) { data.Add(new XmlCompletionData(v)); lastVar = v; } } AddCompletionData(data); } else { //If the attribute starts "name", get list of names from <create. if (elem.Text.StartsWith("name", StringComparison.OrdinalIgnoreCase)) { List <string> variables = GetNames(); variables.Sort(); List <ICompletionData> data = new List <ICompletionData>(); string lastVar = string.Empty; foreach (string v in variables) { if (v != lastVar) { data.Add(new XmlCompletionData(v)); lastVar = v; } } AddCompletionData(data); } else if (elem.Values != null) { List <ICompletionData> data = new List <ICompletionData>(); foreach (XmlCompletionData value in elem.Values) { data.Add(value); } AddCompletionData(data); } } } } //} CheckedForValueCompletion = true; } }