Example #1
0
        static void Main(string[] args)
        {
            Program.args = args;

            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
            if (!args.Contains("--langserver"))
            {
                Log.Write(LogLevel.Normal, "Overwatch Script To Workshop " + VERSION);
            }

            Log.LogLevel = LogLevel.Normal;
            if (args.Contains("-verbose"))
            {
                Log.LogLevel = LogLevel.Verbose;
            }
            if (args.Contains("-quiet"))
            {
                Log.LogLevel = LogLevel.Quiet;
            }

            if (args.Contains("--langserver"))
            {
                Log.LogLevel = LogLevel.Quiet;
                DeltintegerLanguageServer.Run();
            }
            else if (args.Contains("--generatealphabet"))
            {
                Console.Write("Output folder: ");
                string folder = Console.ReadLine();
                Deltin.Deltinteger.Models.Letter.Generate(folder);
            }
            else if (args.Contains("--editor"))
            {
                string pathfindEditorScript = Extras.CombinePathWithDotNotation(null, "!PathfindEditor.del");

                if (!File.Exists(pathfindEditorScript))
                {
                    Log.Write(LogLevel.Normal, "The PathfindEditor.del module is missing!");
                }
                else
                {
                    Script(pathfindEditorScript);
                }
            }
            else if (args.ElementAtOrDefault(0) == "--i18n")
            {
                I18n.GenerateI18n.Generate(args);
            }
            else if (args.ElementAtOrDefault(0) == "--i18nlink")
            {
                I18n.GenerateI18n.GenerateKeyLink();
            }
            else
            {
                string script = args.ElementAtOrDefault(0);

                if (script != null && File.Exists(script))
                {
                    #if DEBUG == false
                    try
                    {
                    #endif

                    string ext = Path.GetExtension(script).ToLower();
                    if (ext == ".csv")
                    {
                        PathMap map    = PathMap.ImportFromCSV(script);
                        string  result = map.ExportAsXML();
                        string  output = Path.ChangeExtension(script, "pathmap");
                        using (FileStream fs = File.Create(output))
                        {
                            Byte[] info = Encoding.Unicode.GetBytes(result);
                            fs.Write(info, 0, info.Length);
                        }
                        Log.Write(LogLevel.Normal, "Created pathmap file at '" + output + "'.");
                    }
                    else if (ext == ".pathmap")
                    {
                        Editor.FromPathmapFile(script);
                    }
                    else
                    {
                        Script(script);
                    }

                    #if DEBUG == false
                }
                catch (Exception ex)
                {
                    Log.Write(LogLevel.Normal, "Internal exception.");
                    Log.Write(LogLevel.Normal, ex.ToString());
                }
                    #endif
                }
                else
                {
                    Log.Write(LogLevel.Normal, $"Could not find the file '{script}'.");
                    Log.Write(LogLevel.Normal, $"Drag and drop a script over the executable to parse.");
                }
            }

            Finished();
        }
Example #2
0
        private LanguageServerOptions AddRequests(LanguageServerOptions options)
        {
            // Pathmap creation is seperated into 2 requests, 'pathmapFromClipboard' and 'pathmapApply'.
            // Pathmap generation request.
            options.OnRequest <object, string>("pathmapFromClipboard", _ => Task <string> .Run(() => {
                // Create the error handler for pathmap parser.
                ServerPathmapHandler error = new ServerPathmapHandler();

                // Get the pathmap. 'map' will be null if there is an error.
                try
                {
                    PathMap map = PathMap.ImportFromCSV(Clipboard.GetText(), error);

                    if (map == null)
                    {
                        return(error.Message);
                    }
                    else
                    {
                        lastMap = map;
                        return("success");
                    }
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }));

            // Pathmap save request.
            options.OnRequest <Newtonsoft.Json.Linq.JToken>("pathmapApply", uriToken => Task.Run(() => {
                // Save 'lastMap' to a file.
                string result = lastMap.ExportAsXML();
                string output = uriToken["path"].ToObject <string>().Trim('/');
                using (FileStream fs = File.Create(output))
                {
                    Byte[] info = Encoding.Unicode.GetBytes(result);
                    fs.Write(info, 0, info.Length);
                }
            }));

            // Pathmap editor request.
            options.OnRequest <PathmapDocument, bool>("pathmapEditor", (editFileToken) => Task <bool> .Run(() => {
                DeltinScript compile;
                if (editFileToken.Text == null)
                {
                    string editor = Extras.CombinePathWithDotNotation(null, "!PathfindEditor.del");
                    compile       = new DeltinScript(new TranslateSettings(editor)
                    {
                        OutputLanguage = ConfigurationHandler.OutputLanguage
                    });
                }
                else
                {
                    compile = Editor.Generate(PathMap.ImportFromXML(editFileToken.Text), ConfigurationHandler.OutputLanguage);
                }

                Clipboard.SetText(compile.WorkshopCode);

                return(true);
            }));

            return(options);
        }