public static void updateValuesOnEvent(Event @event, ref dynamic vaProxy) { try { Logging.Debug($"Processing EDDI event {@event.type}:", @event); var startTime = DateTime.UtcNow; vaProxy.SetText("EDDI event", @event.type); // Retrieve and clear variables from prior iterations of the same event clearPriorEventValues(ref vaProxy, @event.type, currentVariables); currentVariables = currentVariables.Where(v => v.eventType != @event.type).ToList(); // Prepare and update this event's variable values var eventVariables = new MetaVariables(@event.GetType(), @event) .Results .AsVoiceAttackVariables("EDDI", @event.type); foreach (var @var in eventVariables) { @var.Set(vaProxy); } // Save the updated state of our event variables currentVariables.AddRange(eventVariables); Logging.Debug($"Processed EDDI event {@event.type} in {(DateTime.UtcNow - startTime).Milliseconds} milliseconds:", @event); } catch (Exception ex) { Logging.Error("Failed to set event variables in VoiceAttack", ex); } }
public void TestAsteroidProspectedEvent() { var entry = new KeyValuePair <string, Type>("Asteroid prospected", typeof(AsteroidProspectedEvent)); var vars = new MetaVariables(entry.Value, null).Results; var cottleVars = vars.AsCottleVariables(); Assert.AreEqual(6, cottleVars.Count); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "commodities")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "commodities[\\<index\\>].commodity")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "commodities[\\<index\\>].percentage")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "materialcontent")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "remaining")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "motherlode")); var vaVars = vars.AsVoiceAttackVariables("EDDI", entry.Key); Assert.AreEqual(6, vaVars.Count); Assert.AreEqual(typeof(string), vaVars.FirstOrDefault(k => k.key == "EDDI asteroid prospected commodities \\<index\\> commodity").variableType); Assert.AreEqual(typeof(decimal), vaVars.FirstOrDefault(k => k.key == "EDDI asteroid prospected commodities \\<index\\> percentage").variableType); Assert.AreEqual(typeof(int), vaVars.FirstOrDefault(k => k.key == "EDDI asteroid prospected commodities").variableType); Assert.AreEqual(typeof(string), vaVars.FirstOrDefault(k => k.key == "EDDI asteroid prospected materialcontent").variableType); Assert.AreEqual(typeof(decimal), vaVars.FirstOrDefault(k => k.key == "EDDI asteroid prospected remaining").variableType); Assert.AreEqual(typeof(string), vaVars.FirstOrDefault(k => k.key == "EDDI asteroid prospected motherlode").variableType); }
public void TestGalnetNewsPublishedEvent() { var entry = new KeyValuePair <string, Type>("Galnet news published", typeof(GalnetNewsPublishedEvent)); var vars = new MetaVariables(entry.Value, null).Results; var cottleVars = vars.AsCottleVariables(); Assert.AreEqual(7, cottleVars.Count); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == @"items")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == @"items[\<index\>].category")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == @"items[\<index\>].content")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == @"items[\<index\>].id")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == @"items[\<index\>].published")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == @"items[\<index\>].read")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == @"items[\<index\>].title")); Assert.IsNotNull(cottleVars.TrueForAll(v => v.value == null)); var vaVars = vars.AsVoiceAttackVariables("EDDI", entry.Key); Assert.AreEqual(7, vaVars.Count); Assert.AreEqual(typeof(string), vaVars.FirstOrDefault(k => k.key == @"EDDI galnet news published items \<index\> category")?.variableType); Assert.AreEqual(typeof(string), vaVars.FirstOrDefault(k => k.key == @"EDDI galnet news published items \<index\> content")?.variableType); Assert.AreEqual(typeof(string), vaVars.FirstOrDefault(k => k.key == @"EDDI galnet news published items \<index\> id")?.variableType); Assert.AreEqual(typeof(DateTime), vaVars.FirstOrDefault(k => k.key == @"EDDI galnet news published items \<index\> published")?.variableType); Assert.AreEqual(typeof(bool), vaVars.FirstOrDefault(k => k.key == @"EDDI galnet news published items \<index\> read")?.variableType); Assert.AreEqual(typeof(string), vaVars.FirstOrDefault(k => k.key == @"EDDI galnet news published items \<index\> title")?.variableType); Assert.AreEqual(typeof(int), vaVars.FirstOrDefault(k => k.key == @"EDDI galnet news published items")?.variableType); Assert.IsTrue(vaVars.TrueForAll(v => v.value == null)); }
public void TestVACommodityEjectedEvent() { // Test a generated variable name from overlapping strings. // The prefix "EDDI ship fsd" should be merged with the formatted child key "fsd status" to yield "EDDI ship fsd status". CommodityEjectedEvent ev = new CommodityEjectedEvent(DateTime.UtcNow, CommodityDefinition.FromEDName("Water"), 5, null, true); var vars = new MetaVariables(ev.GetType(), ev).Results; var cottleVars = vars.AsCottleVariables(); Assert.AreEqual(4, cottleVars.Count); Assert.AreEqual("Water", cottleVars.FirstOrDefault(k => k.key == "commodity").value); Assert.AreEqual(5, cottleVars.FirstOrDefault(k => k.key == "amount").value); Assert.IsNull(cottleVars.FirstOrDefault(k => k.key == "missionid").value); Assert.AreEqual(true, cottleVars.FirstOrDefault(k => k.key == "abandoned").value); var vaVars = vars.AsVoiceAttackVariables("EDDI", ev.type); foreach (var @var in vaVars) { @var.Set(vaProxy); } Assert.AreEqual(4, vaVars.Count); Assert.AreEqual("Water", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI commodity ejected commodity").Value); Assert.AreEqual(5, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI commodity ejected amount").Value); Assert.IsNull(vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI commodity ejected missionid").Value); Assert.AreEqual(true, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI commodity ejected abandoned").Value); foreach (VoiceAttackVariable variable in vaVars) { Assert.IsTrue(vaProxy.vaVars.ContainsKey(variable.key), "Unmatched key"); } }
public void TestVAAsteroidProspectedEvent() { string line = "{ \"timestamp\":\"2020-04-10T02:32:21Z\", \"event\":\"ProspectedAsteroid\", \"Materials\":[ { \"Name\":\"LowTemperatureDiamond\", \"Name_Localised\":\"Low Temperature Diamonds\", \"Proportion\":26.078022 }, { \"Name\":\"HydrogenPeroxide\", \"Name_Localised\":\"Hydrogen Peroxide\", \"Proportion\":10.189009 } ], \"MotherlodeMaterial\":\"Alexandrite\", \"Content\":\"$AsteroidMaterialContent_Low;\", \"Content_Localised\":\"Material Content: Low\", \"Remaining\":90.000000 }"; List <Event> events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); Assert.IsInstanceOfType(events[0], typeof(AsteroidProspectedEvent)); AsteroidProspectedEvent ev = events[0] as AsteroidProspectedEvent; var vars = new MetaVariables(ev.GetType(), ev).Results; var vaVars = vars.AsVoiceAttackVariables("EDDI", ev.type); foreach (var @var in vaVars) { @var.Set(vaProxy); } Assert.AreEqual(8, vaVars.Count); Assert.AreEqual(90M, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI asteroid prospected remaining").Value); Assert.AreEqual("Alexandrite", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI asteroid prospected motherlode").Value); Assert.AreEqual("Low Temperature Diamonds", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI asteroid prospected commodities 1 commodity").Value); Assert.AreEqual(26.078022M, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI asteroid prospected commodities 1 percentage").Value); Assert.AreEqual("Hydrogen Peroxide", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI asteroid prospected commodities 2 commodity").Value); Assert.AreEqual(10.189009M, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI asteroid prospected commodities 2 percentage").Value); Assert.AreEqual(2, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI asteroid prospected commodities").Value); Assert.AreEqual("Low", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI asteroid prospected materialcontent").Value); foreach (VoiceAttackVariable variable in vaVars) { Assert.IsTrue(vaProxy.vaVars.ContainsKey(variable.key), "Unmatched key"); } }
public void TestVADiscoveryScanEvent() { string line = @"{ ""timestamp"":""2019-10-26T02:15:49Z"", ""event"":""FSSDiscoveryScan"", ""Progress"":0.439435, ""BodyCount"":7, ""NonBodyCount"":3, ""SystemName"":""Outotz WO-A d1"", ""SystemAddress"":44870715523 }"; List <Event> events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); Assert.IsInstanceOfType(events[0], typeof(DiscoveryScanEvent)); DiscoveryScanEvent ev = events[0] as DiscoveryScanEvent; Assert.AreEqual(7, ev.totalbodies); Assert.AreEqual(3, ev.nonbodies); Assert.AreEqual(44, ev.progress); var vars = new MetaVariables(ev.GetType(), ev).Results; var vaVars = vars.AsVoiceAttackVariables("EDDI", ev.type); foreach (var @var in vaVars) { @var.Set(vaProxy); } Assert.AreEqual(2, vaVars.Count); Assert.AreEqual(7, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI discovery scan totalbodies").Value); Assert.AreEqual(3, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI discovery scan nonbodies").Value); Assert.IsNull(vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI discovery scan progress").Value); foreach (VoiceAttackVariable variable in vaVars) { Assert.IsTrue(vaProxy.vaVars.ContainsKey(variable.key), "Unmatched key"); } }
public void TestShipFSDEvent() { var entry = new KeyValuePair <string, Type>("Ship fsd", typeof(ShipFsdEvent)); var vars = new MetaVariables(entry.Value, null).Results; var cottleVars = vars.AsCottleVariables(); Assert.AreEqual(1, cottleVars.Count); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "fsd_status")); var vaVars = vars.AsVoiceAttackVariables("EDDI", entry.Key); Assert.AreEqual(typeof(string), vaVars.FirstOrDefault(k => k.key == "EDDI ship fsd status").variableType); }
public VariablesWindow(Script script) { InitializeComponent(); // Read Markdown and convert it to HTML string markdown; try { DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty); markdown = Files.Read(dir.FullName + @"\Variables.md"); } catch (Exception ex) { Logging.Error("Failed to find variables.md", ex); markdown = ""; } // If the user is editing an event-based script, add event-specific information var @type = Events.TYPES.SingleOrDefault(t => t.Key == script.Name).Value; if (@type != null) { var vars = new MetaVariables(@type).Results; var CottleVars = vars.AsCottleVariables(); if (CottleVars.Any()) { markdown += "Information about this event is available under the `event` object. Note that these variables are only valid for this particular script; other scripts triggered by different events will have different variables available to them.\n"; if (vars.Any(v => v.keysPath.Any(k => k.Contains(@"<index")))) { markdown += "Where values are indexed (the compartments on a ship for example), the index will be represented by '*\\<index\\>*'.\n\n"; } markdown += "\n"; foreach (var cottleVariable in CottleVars.OrderBy(i => i.key)) { var description = !string.IsNullOrEmpty(cottleVariable.description) ? $" - {cottleVariable.description}" : ""; markdown += $" - *{cottleVariable.key}* {description}\n"; } } } string html = CommonMark.CommonMarkConverter.Convert(markdown); html = "<head> <meta charset=\"UTF-8\"> </head> " + html; // Insert the HTML textBrowser.NavigateToString(html); }
public void TestSRVTurretDeployableEvent() { var entry = new KeyValuePair <string, Type>("SRV turret deployable", typeof(SRVTurretDeployableEvent)); var vars = new MetaVariables(entry.Value, null).Results; var cottleVars = vars.AsCottleVariables(); Assert.AreEqual(1, cottleVars.Count); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == @"deployable")?.key); Assert.IsTrue(cottleVars.TrueForAll(v => v.value == null)); var vaVars = vars.AsVoiceAttackVariables("EDDI", entry.Key); Assert.AreEqual(1, vaVars.Count); Assert.AreEqual(typeof(bool), vaVars.FirstOrDefault(k => k.key == @"EDDI srv turret deployable")?.variableType); Assert.IsTrue(vaVars.TrueForAll(v => v.value == null)); }
// Generates the list of keywords used by the Cottle grammar "SpeechResponder\Cottle.xshd". // Paste the output into the "Custom properties" section of that file. public void TestGenerateEventVariables() { SortedSet <string> eventVars = new SortedSet <string>(); foreach (var type in Events.TYPES) { var vars = new MetaVariables(type.Value).Results; foreach (var key in vars.SelectMany(v => v.keysPath)) { eventVars.Add(key); } } string output = " <Word>" + string.Join("</Word>\r\n <Word>", eventVars) + " </Word>\r\n"; Directory.CreateDirectory(@"Cottle\"); File.WriteAllText(@"Cottle\Custom keywords.txt", output); }
public void TestDiscoveryScanEvent() { var entry = new KeyValuePair <string, Type>("Discovery scan", typeof(DiscoveryScanEvent)); var vars = new MetaVariables(entry.Value, null).Results; var cottleVars = vars.AsCottleVariables(); Assert.AreEqual(2, cottleVars.Count); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "totalbodies")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "nonbodies")); Assert.IsNull(cottleVars.FirstOrDefault(k => k.key == "progress")); Assert.IsTrue(cottleVars.TrueForAll(v => v.value == null)); var vaVars = vars.AsVoiceAttackVariables("EDDI", entry.Key); Assert.AreEqual(2, vaVars.Count); Assert.AreEqual(typeof(int), vaVars.FirstOrDefault(k => k.key == "EDDI discovery scan totalbodies").variableType); Assert.AreEqual(typeof(int), vaVars.FirstOrDefault(k => k.key == "EDDI discovery scan nonbodies").variableType); Assert.IsNull(vaVars.FirstOrDefault(k => k.key == "EDDI discovery scan progress")?.variableType); }
public void TestVAShipFSDEvent() { // Test a generated variable name from overlapping strings. // The prefix "EDDI ship fsd" should be merged with the formatted child key "fsd status" to yield "EDDI ship fsd status". ShipFsdEvent ev = new ShipFsdEvent(DateTime.UtcNow, "ready"); var vars = new MetaVariables(ev.GetType(), ev).Results; var vaVars = vars.AsVoiceAttackVariables("EDDI", ev.type); foreach (var @var in vaVars) { @var.Set(vaProxy); } Assert.AreEqual(1, vaVars.Count); Assert.AreEqual("ready", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI ship fsd status").Value); foreach (VoiceAttackVariable variable in vaVars) { Assert.IsTrue(vaProxy.vaVars.ContainsKey(variable.key), "Unmatched key"); } }
public void TestVAExplorationDataSoldEvent() { string line = @"{ ""timestamp"":""2016-09-23T18:57:55Z"", ""event"":""SellExplorationData"", ""Systems"":[ ""Gamma Tucanae"", ""Rho Capricorni"", ""Dain"", ""Col 285 Sector BR-S b18-0"", ""LP 571-80"", ""Kawilocidi"", ""Irulachan"", ""Alrai Sector MC-M a7-0"", ""Col 285 Sector FX-Q b19-5"", ""Col 285 Sector EX-Q b19-7"", ""Alrai Sector FB-O a6-3"" ], ""Discovered"":[ ""Irulachan"" ], ""BaseValue"":63573, ""Bonus"":1445, ""TotalEarnings"":65018 }"; List <Event> events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); Assert.IsInstanceOfType(events[0], typeof(ExplorationDataSoldEvent)); var ev = events[0] as ExplorationDataSoldEvent; var vars = new MetaVariables(ev.GetType(), ev).Results; var vaVars = vars.AsVoiceAttackVariables("EDDI", ev.type); foreach (var @var in vaVars) { @var.Set(vaProxy); } Assert.AreEqual(15, vaVars.Count); Assert.AreEqual("Gamma Tucanae", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 1").Value); Assert.AreEqual("Rho Capricorni", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 2").Value); Assert.AreEqual("Dain", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 3").Value); Assert.AreEqual("Col 285 Sector BR-S b18-0", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 4").Value); Assert.AreEqual("LP 571-80", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 5").Value); Assert.AreEqual("Kawilocidi", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 6").Value); Assert.AreEqual("Irulachan", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 7").Value); Assert.AreEqual("Alrai Sector MC-M a7-0", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 8").Value); Assert.AreEqual("Col 285 Sector FX-Q b19-5", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 9").Value); Assert.AreEqual("Col 285 Sector EX-Q b19-7", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 10").Value); Assert.AreEqual("Alrai Sector FB-O a6-3", vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems 11").Value); Assert.AreEqual(11, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold systems").Value); Assert.AreEqual(63573M, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold reward").Value); Assert.AreEqual(1445M, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold bonus").Value); Assert.AreEqual(65018M, vaProxy.vaVars.FirstOrDefault(k => k.Key == "EDDI exploration data sold total").Value); foreach (VoiceAttackVariable variable in vaVars) { Assert.IsTrue(vaProxy.vaVars.ContainsKey(variable.key), "Unmatched key"); } }
public void TestExplorationDataSoldEvent() { var entry = new KeyValuePair <string, Type>("Exploration data sold", typeof(ExplorationDataSoldEvent)); var vars = new MetaVariables(entry.Value, null).Results; var cottleVars = vars.AsCottleVariables(); Assert.AreEqual(5, cottleVars.Count); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == @"systems")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == @"systems[\<index\>]")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "reward")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "bonus")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "total")); var vaVars = vars.AsVoiceAttackVariables("EDDI", entry.Key); Assert.AreEqual(5, vaVars.Count); Assert.AreEqual(typeof(string), vaVars.FirstOrDefault(k => k.key == "EDDI exploration data sold systems \\<index\\>").variableType); Assert.AreEqual(typeof(int), vaVars.FirstOrDefault(k => k.key == "EDDI exploration data sold systems").variableType); Assert.AreEqual(typeof(decimal), vaVars.FirstOrDefault(k => k.key == "EDDI exploration data sold reward").variableType); Assert.AreEqual(typeof(decimal), vaVars.FirstOrDefault(k => k.key == "EDDI exploration data sold bonus").variableType); Assert.AreEqual(typeof(decimal), vaVars.FirstOrDefault(k => k.key == "EDDI exploration data sold total").variableType); }
public void TestCommodityEjectedEvent() { var entry = new KeyValuePair <string, Type>("Commodity ejected", typeof(CommodityEjectedEvent)); var vars = new MetaVariables(entry.Value, null).Results; Assert.AreEqual(4, vars.Count); Assert.IsNotNull(vars.FirstOrDefault(k => k.keysPath.Last() == "commodity").description); Assert.IsNotNull(vars.FirstOrDefault(k => k.keysPath.Last() == "amount").description); Assert.IsNotNull(vars.FirstOrDefault(k => k.keysPath.Last() == "missionid").description); Assert.IsNotNull(vars.FirstOrDefault(k => k.keysPath.Last() == "abandoned").description); var cottleVars = vars.AsCottleVariables(); Assert.AreEqual(4, cottleVars.Count); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "commodity")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "amount")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "missionid")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "abandoned")); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "commodity").description); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "amount").description); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "missionid").description); Assert.IsNotNull(cottleVars.FirstOrDefault(k => k.key == "abandoned").description); var vaVars = vars.AsVoiceAttackVariables("EDDI", entry.Key); Assert.AreEqual(4, vaVars.Count); Assert.AreEqual(typeof(string), vaVars.FirstOrDefault(k => k.key == "EDDI commodity ejected commodity").variableType); Assert.AreEqual(typeof(int), vaVars.FirstOrDefault(k => k.key == "EDDI commodity ejected amount").variableType); Assert.AreEqual(typeof(decimal), vaVars.FirstOrDefault(k => k.key == "EDDI commodity ejected missionid").variableType); Assert.AreEqual(typeof(bool), vaVars.FirstOrDefault(k => k.key == "EDDI commodity ejected abandoned").variableType); Assert.AreEqual("The name of the commodity ejected", vaVars.FirstOrDefault(k => k.key == "EDDI commodity ejected commodity").description); Assert.AreEqual("The amount of commodity ejected", vaVars.FirstOrDefault(k => k.key == "EDDI commodity ejected amount").description); Assert.AreEqual("ID of the mission-related commodity, if applicable", vaVars.FirstOrDefault(k => k.key == "EDDI commodity ejected missionid").description); Assert.AreEqual("True if the cargo has been abandoned", vaVars.FirstOrDefault(k => k.key == "EDDI commodity ejected abandoned").description); }
public void TestGenerateWikiEvents() { foreach (KeyValuePair <string, Type> entry in Events.TYPES.OrderBy(i => i.Key)) { List <string> output = new List <string> { Events.DESCRIPTIONS[entry.Key] + ".", "" }; var vars = new MetaVariables(entry.Value).Results; var CottleVars = vars.AsCottleVariables(); var VoiceAttackVars = vars.AsVoiceAttackVariables("EDDI", entry.Key); if (!vars.Any()) { output.Add("This event has no variables."); output.Add("To respond to this event in VoiceAttack, create a command entitled ((EDDI " + entry.Key.ToLowerInvariant() + "))."); output.Add(""); } if (vars.Any(v => v.keysPath.Any(k => k.Contains(@"<index")))) { output.Add("Where values are indexed (the compartments on a ship for example), the index will be represented by '*\\<index\\>*'."); if (VoiceAttackVars.Any(v => v.key.Contains(@"<index"))) { output.Add("For VoiceAttack, a variable with the root name of the indexed array shall identify the total number of entries in the array. For example, if compartments 1 and 2 are available then the value of the corresponding 'compartments' variable will be 2."); } output.Add(""); } if (CottleVars.Any()) { output.Add("When using this event in the [Speech responder](Speech-Responder) the information about this event is available under the `event` object. The available variables are as follows:"); output.Add(""); output.Add(""); foreach (var cottleVariable in CottleVars.OrderBy(i => i.key)) { var description = !string.IsNullOrEmpty(cottleVariable.description) ? $" - {cottleVariable.description}" : ""; output.Add($" - *{{event.{cottleVariable.key}}}* {description}"); output.Add(""); } } if (VoiceAttackVars.Any()) { output.Add(""); output.Add("To respond to this event in VoiceAttack, create a command entitled ((EDDI " + entry.Key.ToLowerInvariant() + ")). VoiceAttack variables will be generated to allow you to access the event information."); output.Add(""); output.Add("The following VoiceAttack variables are available for this event:"); output.Add(""); output.Add(""); void WriteVariableToOutput(VoiceAttackVariable variable) { var description = !string.IsNullOrEmpty(variable.description) ? $" - {variable.description}" : ""; if (variable.variableType == typeof(string)) { output.Add($" - *{{TXT:{variable.key}}}* {description}"); } else if (variable.variableType == typeof(int)) { output.Add($" - *{{INT:{variable.key}}}* {description}"); } else if (variable.variableType == typeof(bool)) { output.Add($" - *{{BOOL:{variable.key}}}* {description}"); } else if (variable.variableType == typeof(decimal)) { output.Add($" - *{{DEC:{variable.key}}}* {description}"); } else if (variable.variableType == typeof(DateTime)) { output.Add($" - *{{DATE:{variable.key}}}* {description}"); } output.Add(""); } foreach (var variable in VoiceAttackVars.OrderBy(i => i.key)) { WriteVariableToOutput(variable); } output.Add(""); output.Add("For more details on VoiceAttack integration, see https://github.com/EDCD/EDDI/wiki/VoiceAttack-Integration."); output.Add(""); } Directory.CreateDirectory(@"Wiki\events\"); File.WriteAllLines(@"Wiki\events\" + entry.Key.Replace(" ", "-") + "-event.md", output); } }