Esempio n. 1
0
        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);
        }
Esempio n. 2
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);
            }
        }