public static DeltinScript Generate(string fileName, Pathmap map, OutputLanguage language) { string baseEditorFile = Extras.CombinePathWithDotNotation(null, "!PathfindEditor.del"); return(new DeltinScript(new TranslateSettings(baseEditorFile) { AdditionalRules = (varCollection) => { // Set the initial nodes. Rule initialNodes = new Rule("Initial Nodes"); initialNodes.Actions = ArrayBuilder <Element> .Build( // File name HUD. Element.Hud(text: new V_CustomString(fileName), sortOrder: 1, textColor: Color.Orange, location: HudLocation.Right), // Set nodes, segments, and attributes. WorkshopArrayBuilder.SetVariable(null, map.NodesAsWorkshopData(), null, LoadNodes, false), WorkshopArrayBuilder.SetVariable(null, map.SegmentsAsWorkshopData(), null, LoadSegments, false), WorkshopArrayBuilder.SetVariable(null, map.AttributesAsWorkshopData(), null, LoadAttributes, false) ); return new Rule[] { initialNodes }; }, OptimizeOutput = false, OutputLanguage = language })); }
public void Export(List <ExtensionalGraph> extensionalGraphs, OutputLanguage output, bool writeToConsole, bool writeToFiles, bool useProjectFolder) { string fileExtension = GetExtension(output); for (int i = 0; i < extensionalGraphs.Count; i++) { ExtensionalGraph extensionalGraph = extensionalGraphs[i]; if (writeToFiles) { string path = useProjectFolder ? _helper.GetPathWith(_conf.OutputFolderName, extensionalGraph.FileName + fileExtension) : extensionalGraph.FileName + fileExtension; if (useProjectFolder) { _helper.EnsureOutputDirectoryCreated(_conf.OutputFolderName); } File.WriteAllText(path, extensionalGraph.GraphString); } if (writeToConsole) { if (i == 0) { Console.WriteLine("\nRESULTS:\n"); } Console.WriteLine($"Output graph {i}: \n"); Console.WriteLine(extensionalGraph.GraphString); } } }
public DeltinScript(TranslateSettings translateSettings) { FileGetter = translateSettings.FileGetter; Diagnostics = translateSettings.Diagnostics; Language = translateSettings.OutputLanguage; OptimizeOutput = translateSettings.OptimizeOutput; GlobalScope = Scope.GetGlobalScope(); RulesetScope = GlobalScope.Child(); RulesetScope.PrivateCatch = true; Types.GetDefaults(this); Importer = new Importer(this, FileGetter, translateSettings.Root.Uri); Importer.CollectScriptFiles(translateSettings.Root); Translate(); if (!Diagnostics.ContainsErrors()) { ToWorkshop(translateSettings.AdditionalRules); } foreach (IComponent component in Components) { if (component is IDisposable disposable) { disposable.Dispose(); } } }
internal ShaderLanguage(OutputLanguage language) { Language = language; _keywords = new Dictionary <Type, Translation>(); _modifiers = new List <Modifier>(); TranslatedTypes = new ConcurrentDictionary <string, ShaderType>(); }
public virtual string ToWorkshop(OutputLanguage language) { AddMissingParameters(); List <string> parameters = AdditionalParameters().ToList(); parameters.AddRange(ParameterValues.Select(p => p.ToWorkshop(language))); string result = Extras.Indent(Indent, true); // TODO: option for spaces or tab output. if (!ElementList.IsValue && Disabled) { result += LanguageInfo.Translate(language, "disabled") + " "; } result += LanguageInfo.Translate(language, Name); if (parameters.Count != 0) { result += "(" + string.Join(", ", parameters) + ")"; } else if (AlwaysShowParentheses) { result += "()"; } if (!ElementList.IsValue) { result += ";"; } return(result); }
public void ToWorkshop(StringBuilder stringBuilder, OutputLanguage language) { stringBuilder.AppendLine(I18n.I18n.Translate(language, "variables")); stringBuilder.AppendLine("{"); stringBuilder.AppendLine(Extras.Indent(1, false) + I18n.I18n.Translate(language, "global") + ":"); WriteCollection(stringBuilder, variableList(true)); stringBuilder.AppendLine(Extras.Indent(1, false) + I18n.I18n.Translate(language, "player") + ":"); WriteCollection(stringBuilder, variableList(false)); stringBuilder.AppendLine("}"); bool anyExtendedGlobal = extendedVariableList(true).Any(v => v != null); bool anyExtendedPlayer = extendedVariableList(false).Any(v => v != null); if (anyExtendedGlobal || anyExtendedPlayer) { stringBuilder.AppendLine(); stringBuilder.AppendLine($"// Extended collection variables:"); foreach (var ex in extendedVariableList(true)) { stringBuilder.AppendLine($"// global [{ex.Index}]: {ex.DebugName}"); } foreach (var ex in extendedVariableList(false)) { stringBuilder.AppendLine($"// player [{ex.Index}]: {ex.DebugName}"); } } }
private void CreateNewProject_OnClick(object sender, RoutedEventArgs e) { string selectedLanguage = "C#"; // Currently, only support C# OutputLanguage outputLanguage = _projectEditorViewModel.OutputLanguages.First(ol => ol.Name == selectedLanguage); _projectEditorViewModel.StartNewProject(outputLanguage); }
private string GetExtension(OutputLanguage language) { return(language switch { OutputLanguage.GML => _conf.GmlFileExtension, OutputLanguage.DOT => _conf.DotFileExtension, _ => "" });
public GenerateAttribute(OutputLanguage language = OutputLanguage.Inherit, string relativePath = null, Option skipNamespace = Option.Inherit, Option propertiesToFields = Option.Inherit, Option fieldsToProperties = Option.Inherit, Option formatNames = Option.Inherit) { this.Language = language; this.RelativePath = relativePath; this.SkipNamespace = skipNamespace; this.PropertiesToFields = propertiesToFields; this.FieldsToProperties = fieldsToProperties; this.FormatNames = formatNames; }
private string GetOutputLanguage(OutputLanguage language) { switch (language) { case OutputLanguage.EnglishUS: default: return("en-us"); } }
public static void I18nWarningMessage(StringBuilder builder, OutputLanguage outputLanguage) { if (outputLanguage == OutputLanguage.enUS) { return; } builder.AppendLine($"// Outputting to the language {outputLanguage.ToString()}."); builder.AppendLine($"// Not all languages are tested. If a value is not outputting correctly, you can change"); builder.AppendLine($"// the keyword info in the Languages/i18n-{outputLanguage.ToString()}.xml file."); builder.AppendLine(); }
public void Test_StartNewProject() { ProjectEditorViewModel vm = new ProjectEditorViewModel(); OutputLanguage outputLanguage = vm.OutputLanguages.First(ol => ol.Name == "C#"); vm.StartNewProject(outputLanguage); // Assertions vm.CurrentProject.ShouldNotBeNull(); vm.CurrentProject.Datatypes.Count.ShouldBe(17); }
public Task <Unit> Handle(DidChangeConfigurationParams configChangeParams, CancellationToken token) { var json = configChangeParams.Settings?.SelectToken("ostw") as JObject; if (json != null) { dynamic config = json; ReferencesCodeLens = config.codelens.references; ImplementsCodeLens = config.codelens.implements; ElementCountCodeLens = config.codelens.elementCount; OutputLanguage = GetOutputLanguage(config.outputLanguage); LanguageInfo.LoadLanguage(OutputLanguage); OptimizeOutput = config.optimizeOutput; } return(Unit.Task); OutputLanguage GetOutputLanguage(string languageString) { switch (languageString) { case "English": return(OutputLanguage.enUS); case "German": return(OutputLanguage.deDE); case "Spanish (Castilian)": return(OutputLanguage.esES); case "Spanish (Mexico)": return(OutputLanguage.esMX); case "French": return(OutputLanguage.frFR); case "Italian": return(OutputLanguage.itIT); case "Japanese": return(OutputLanguage.jaJP); case "Korean": return(OutputLanguage.koKR); case "Polish": return(OutputLanguage.plPL); case "Portuguese": return(OutputLanguage.ptBR); case "Russian": return(OutputLanguage.ruRU); case "Chinese (S)": return(OutputLanguage.zhCN); case "Chinese (T)": return(OutputLanguage.zhTW); default: return(OutputLanguage.enUS); } } }
public string ToWorkshop(OutputLanguage language, bool optimize) { Element a = Value1; Element b = Value2; if (optimize) { a = a.Optimize(); b = b.Optimize(); } return(a.ToWorkshop(language) + " " + CompareOperator.ToWorkshop(language) + " " + b.ToWorkshop(language)); }
static void Main(string[] args) { string[] samples = { "FunctionalityTestShader.cs", //"SampleShader.cs", //"SampleTextureShader.cs", //"MoltenSpriteShader.cs" }; Translator translator = new Translator(); TranslationResult output = null; OutputLanguage language = OutputLanguage.HLSL; // Load all of the sources into a dictionary, // so that all of them can be translated in a single converter.Convert() call. Dictionary <string, string> sources = new Dictionary <string, string>(); foreach (string fn in samples) { Console.WriteLine($"Reading {fn}"); FileInfo fInfo = new FileInfo(fn); string strInput = File.ReadAllText(fn); sources.Add(fn, strInput); } output = translator.Translate(sources, language); // Store the output to file so we can take a look at it ourselves. if (output != null) { string langExtension = $"{language.ToString().ToLower()}"; foreach (KeyValuePair <string, ShaderTranslationResult> kvp in output) { using (FileStream fs = new FileStream($"{kvp.Key}.{langExtension}", FileMode.Create, FileAccess.Write)) { using (StreamWriter writer = new StreamWriter(fs)) { writer.Write(kvp.Value.SourceCode); } } } } Console.ReadKey(); translator.Dispose(); }
public static void LoadLanguage(OutputLanguage language) { lock (LanguageLock) { if (CurrentLanguage != language && language != OutputLanguage.enUS) { string languageFile = Path.Combine(Program.ExeFolder, "Languages", "i18n-" + language.ToString() + ".xml"); XmlSerializer serializer = new XmlSerializer(typeof(I18nLanguage)); using (var fileStream = File.OpenRead(languageFile)) Language = (I18nLanguage)serializer.Deserialize(fileStream); } CurrentLanguage = language; } }
public static string Translate(OutputLanguage language, string methodName) { if (language == OutputLanguage.enUS) { return(methodName); } lock (LanguageLock) { if (CurrentLanguage != language) { throw new Exception($"The '{language.ToString()}' language is not loaded."); } return(Language.Methods.FirstOrDefault(m => m.EnglishName == methodName)?.Translation ?? throw new Exception($"Could not find '{methodName}' in the language file.")); } }
private void ParseArgs(string[] args) { //_fileNames = new List<string>() { "StarLabel.fgl" }; _saveOutput = true; foreach (string s in args) { if (s == "throw") { _shouldThrowExceptions = true; } else if (s == "parseTree") { _printParseTree = true; } else if (s == "code") { _printCode = true; } else if (s == "output") { _printOutput = true; } else if (s == "noWrite") { _saveOutput = false; } else if (s == "project") { _projectFolder = true; } else if (s == "help") { PrintHelp(); } else if (s == "dot") { _output = OutputLanguage.DOT; } else { _fileNames.Add(s); } } }
public virtual string ToWorkshop(OutputLanguage language, ToWorkshopContext context) { // Get the parameters AddMissingParameters(); List <string> parameters = AdditionalParameters().ToList(); parameters.AddRange(ParameterValues.Select(p => p.ToWorkshop(language, ToWorkshopContext.NestedValue))); string result = Extras.Indent(Indent, true); // TODO: option for spaces or tab output. // Add a comment and newline if (Comment != null) { result += $"\"{Comment}\"\n" + Extras.Indent(Indent, true); } // Add the disabled tag if the element is disabled. if (!ElementList.IsValue && Disabled) { result += LanguageInfo.Translate(language, "disabled") + " "; } // Add the name of the element. result += LanguageInfo.Translate(language, Name); // Add the parameters. if (parameters.Count != 0) { result += "(" + string.Join(", ", parameters) + ")"; } else if (AlwaysShowParentheses) { result += "()"; } // Add the ; if the element is an action. if (!ElementList.IsValue) { result += ";"; } return(result); }
public static DeltinScript Generate(PathMap map, OutputLanguage language) { string baseEditorFile = Extras.CombinePathWithDotNotation(null, "!PathfindEditor.del"); return(new DeltinScript(new TranslateSettings(baseEditorFile) { AdditionalRules = (varCollection) => { // Set the initial nodes. Rule initialNodes = new Rule("Initial Nodes"); initialNodes.Actions = ArrayBuilder <Element> .Build( WorkshopArrayBuilder.SetVariable(null, map.NodesAsWorkshopData(), null, LoadNodes, false), WorkshopArrayBuilder.SetVariable(null, map.SegmentsAsWorkshopData(), null, LoadSegments, false) ); return new Rule[] { initialNodes }; }, OptimizeOutput = false, OutputLanguage = language })); }
/// <summary> /// Generates the prod code. /// </summary> /// <param name="template">The template to use in generating.</param> /// <param name="language">The language to generate.</param> /// <returns>The generated code</returns> public string GenerateProd(ProdTextTemplate template, OutputLanguage language) { string codeOut = string.Empty; switch (language) { case OutputLanguage.CSharp: codeOut = csGenerateProd(template); break; case OutputLanguage.VB: break; case OutputLanguage.CPlusPlus: break; default: break; } return(codeOut); }
public DeltinScript(TranslateSettings translateSettings) { FileGetter = translateSettings.FileGetter; Diagnostics = translateSettings.Diagnostics; Language = translateSettings.OutputLanguage; OptimizeOutput = translateSettings.OptimizeOutput; Types = new ScriptTypes(this); Types.GetDefaults(); GlobalScope = new Scope("global scope"); RulesetScope = GlobalScope.Child(); RulesetScope.PrivateCatch = true; Types.AddTypesToScope(GlobalScope); Importer = new Importer(this, FileGetter, translateSettings.Root.Uri); Importer.CollectScriptFiles(this, translateSettings.Root); Translate(); if (!Diagnostics.ContainsErrors()) { try { ToWorkshop(translateSettings.AdditionalRules); } catch (Exception ex) { WorkshopCode = "An exception was thrown while translating to workshop.\r\n" + ex.ToString(); } } foreach (IComponent component in Components) { if (component is IDisposable disposable) { disposable.Dispose(); } } }
public string ToWorkshop(OutputLanguage language, ToWorkshopContext context) { string numTranslate(string name) { return(LanguageInfo.Translate(language, name) + WorkshopName.Substring(name.Length)); } if (@Enum.Type == typeof(PlayerSelector) && WorkshopName.StartsWith("Slot")) { return(numTranslate("Slot")); } if (@Enum.Type == typeof(Button) && WorkshopName.StartsWith("Ability")) { return(numTranslate("Ability")); } if ((@Enum.Type == typeof(Team) || @Enum.Type == typeof(Color)) && WorkshopName.StartsWith("Team")) { return(numTranslate("Team")); } return(LanguageInfo.Translate(language, WorkshopName).RemoveStructuralChars()); }
public string ToWorkshop(OutputLanguage language) { string numTranslate(string name) { return(I18n.I18n.Translate(language, name) + WorkshopName.Substring(name.Length)); } if (@Enum.Type == typeof(PlayerSelector) && WorkshopName.StartsWith("Slot")) { return(numTranslate("Slot")); } if (@Enum.Type == typeof(Button) && WorkshopName.StartsWith("Ability")) { return(numTranslate("Ability")); } if ((@Enum.Type == typeof(Team) || @Enum.Type == typeof(Color)) && WorkshopName.StartsWith("Team")) { return(numTranslate("Team")); } return(I18n.I18n.Translate(language, WorkshopName)); }
public DeltinScript(TranslateSettings translateSettings) { FileGetter = translateSettings.FileGetter; Diagnostics = translateSettings.Diagnostics; Language = translateSettings.OutputLanguage; OptimizeOutput = translateSettings.OptimizeOutput; types.AddRange(CodeType.DefaultTypes); Importer = new Importer(translateSettings.Root.Uri); CollectScriptFiles(translateSettings.Root); GlobalScope = Scope.GetGlobalScope(); RulesetScope = GlobalScope.Child(); RulesetScope.PrivateCatch = true; Translate(); if (!Diagnostics.ContainsErrors()) { ToWorkshop(translateSettings.AdditionalRules); } }
public virtual string ToWorkshop(OutputLanguage language) { List <IWorkshopTree> elementParameters = new List <IWorkshopTree>(); for (int i = 0; i < ParameterData.Length; i++) { IWorkshopTree parameter = ParameterValues?.ElementAtOrDefault(i); // If the parameter is null, get the default variable. if (parameter == null) { parameter = ParameterData[i].GetDefault(); } elementParameters.Add(parameter); } List <string> parameters = AdditionalParameters().ToList(); parameters.AddRange(elementParameters.Select(p => p.ToWorkshop(language))); string result = ""; if (!ElementList.IsValue && Disabled) { result += I18n.I18n.Translate(language, "disabled") + " "; } result += I18n.I18n.Translate(language, Name); if (parameters.Count != 0) { result += "(" + string.Join(", ", parameters) + ")"; } if (!ElementList.IsValue) { result += ";"; } return(result); }
/// <summary> /// Converts the provided C# source code to the specified shader language. /// </summary> /// <param name="cSharpSources">A dictionary containing source code by file or friendly name. The name is used to identify the source code in message logs.</param> /// <param name="outputLanguage">The language that the input source code should be translated to.</param> /// <param name="flags">A set of flags to change the default behaviour of the converter.</param> /// <param name="preprocessorSymbols">A list of defined preprocessor symbols.</param> /// <returns></returns> public TranslationResult Translate(Dictionary <string, string> cSharpSources, OutputLanguage outputLanguage, TranslationFlags flags = TranslationFlags.None, List <string> preprocessorSymbols = null) { if (_disposed) { throw new ObjectDisposedException("Translator instance has been disposed."); } TranslationArgs tArgs = new TranslationArgs() { CSharpSources = new Dictionary <string, string>(cSharpSources), Flags = flags, Language = outputLanguage, PreprocessorSymbols = preprocessorSymbols ?? new List <string>(), }; TranslationContext context = _runner.Run(tArgs); TranslationResult result = BuildResult(context, flags); context.Recycle(); return(result); }
/// <summary> /// Converts the provided C# source code to the specified shader language. /// </summary> /// <param name="fileOrFriendlyName">The filename or friendly name to assign to identify the source code in message logs.</param> /// <param name="cSharpSource">The C# source code to be converted.</param> /// <param name="outputLanguage">The output shader language.</param> /// <param name="flags">A set of flags to change the default behaviour of the converter.</param> /// <param name="preprocessorSymbols">A list of defined preprocessor symbols.</param> /// <returns></returns> public TranslationResult Translate(string fileOrFriendlyName, string cSharpSource, OutputLanguage outputLanguage, TranslationFlags flags = TranslationFlags.None, List <string> preprocessorSymbols = null) { return(Translate(new Dictionary <string, string>() { [fileOrFriendlyName] = cSharpSource, }, outputLanguage, flags)); }
public string ToWorkshop(OutputLanguage outputLanguage, ToWorkshopContext context) => throw new NotImplementedException();
public WorkshopBuilder(OutputLanguage outputLanguage, StringBuilder builder) { OutputLanguage = outputLanguage; _builder = builder; }