Exemple #1
0
        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));
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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");
            }
        }
Exemple #4
0
        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);
        }
Exemple #6
0
        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));
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
            }
        }