internal override void PerformLocalIdAllocation(VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { this.LocalScopeId = varIds.GetVarId(this.FirstToken); if (this.LocalScopeId == -1) { string name = this.FirstToken.Value; if (SystemLibraryManager.IsValidLibrary(name)) { throw new ParserException(this.FirstToken, "'" + name + "' is referenced but not imported in this file."); } throw new ParserException(this.FirstToken, "'" + name + "' is used but is never assigned to."); } } }
public override Dictionary <string, FileOutput> Package( BuildContext buildContext, string projectId, Dictionary <string, Executable[]> finalCode, ICollection <StructDefinition> structDefinitions, string fileCopySourceRoot, ResourceDatabase resourceDatabase, SystemLibraryManager libraryManager) { Dictionary <string, FileOutput> output = new Dictionary <string, FileOutput>(); FileOutput byteCodeFile = this.GenerateByteCodeFile(resourceDatabase.ByteCodeRawData); output["bytecode.php"] = byteCodeFile; Dictionary <string, string> replacements = new Dictionary <string, string>(); List <string> codePhp = new List <string>(); codePhp.Add("<?php\n\n"); foreach (string component in finalCode.Keys) { this.Translator.Translate(codePhp, finalCode[component]); codePhp.Add(this.Translator.NL); } codePhp.Add("\n\n?>"); output["crayon.php"] = new FileOutput() { Type = FileOutputType.Text, TextContent = string.Join("", codePhp), }; output["cryutil.php"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements(Util.ReadResourceFileInternally("server-php/cryutil.php"), replacements), }; output["index.php"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements(Util.ReadResourceFileInternally("server-php/index.php"), replacements), }; return(output); }
public override Dictionary <string, FileOutput> Package( BuildContext buildContext, string projectId, Dictionary <string, ParseTree.Executable[]> finalCode, ICollection <ParseTree.StructDefinition> structDefinitions, string fileCopySourceRoot, ResourceDatabase resourceDatabase, SystemLibraryManager libraryManager) { Dictionary <string, FileOutput> output = new Dictionary <string, FileOutput>(); string package = "com." + projectId.ToLowerInvariant() + ".app"; string pathToJavaCode = "app/src/main/java/" + package.Replace('.', '/'); Dictionary <string, string> replacements = new Dictionary <string, string>() { { "PROJECT_TITLE", projectId }, { "PROJECT_ID", projectId }, { "PACKAGE", package }, { "CURRENT_YEAR", DateTime.Now.Year.ToString() }, { "COPYRIGHT", "©" }, }; foreach (string simpleCopyText in new string[] { // Boilerplate Android project stuff "build.gradle|AndroidProject/Boilerplate/BuildGradle.txt", "gradle.properties|AndroidProject/Boilerplate/GradleProperties.txt", "gradlew|AndroidProject/Boilerplate/Gradlew.txt", "gradlew.bat|AndroidProject/Boilerplate/GradlewBat.txt", projectId + ".iml|AndroidProject/Boilerplate/ProjectIml.txt", "android.iml|AndroidProject/Boilerplate/AndroidIml.txt", "settings.gradle|AndroidProject/Boilerplate/SettingsGradle.txt", "gradle/wrapper/gradle-wrapper.jar|AndroidProject/Boilerplate/GradleWrapperJar", "gradle/wrapper/gradle-wrapper.properties|AndroidProject/Boilerplate/GradleWrapperProperties.txt", "app/app.iml|AndroidProject/Boilerplate/AppIml.txt", "app/build.gradle|AndroidProject/Boilerplate/AppBuildGradle.txt", "app/src/main/res/layout/activity_game.xml|AndroidProject/Boilerplate/ResLayoutActivityGameXml.txt", "app/src/main/res/values/attrs.xml|AndroidProject/Boilerplate/ResValuesAttrsXml.txt", "app/src/main/res/values/colors.xml|AndroidProject/Boilerplate/ResValuesColorsXml.txt", "app/src/main/res/values/strings.xml|AndroidProject/Boilerplate/ResValuesStringsXml.txt", "app/src/main/res/values/styles.xml|AndroidProject/Boilerplate/ResValuesStylesXml.txt", "app/src/main/res/values-v11/styles.xml|AndroidProject/Boilerplate/ResValuesV11StylesXml.txt", "app/src/main/res/drawable-hdpi/ic_launcher.png|AndroidProject/Boilerplate/ResDrawableHdpiIcLauncher.png", "app/src/main/res/drawable-mdpi/ic_launcher.png|AndroidProject/Boilerplate/ResDrawableMdpiIcLauncher.png", "app/src/main/res/drawable-xhdpi/ic_launcher.png|AndroidProject/Boilerplate/ResDrawableXhdpiIcLauncher.png", "app/src/main/res/drawable-xxhdpi/ic_launcher.png|AndroidProject/Boilerplate/ResDrawableXxhdpiIcLauncher.png", pathToJavaCode + "/util/SystemUiHider.java|AndroidProject/Boilerplate/JavaUtilSystemUiHider.txt", pathToJavaCode + "/util/SystemUiHiderBase.java|AndroidProject/Boilerplate/JavaUtilSystemUiHiderBase.txt", pathToJavaCode + "/util/SystemUiHiderHoneycomb.java|AndroidProject/Boilerplate/JavaUtilSystemUiHiderHoneycomb.txt", "app/src/main/AndroidManifest.xml|AndroidProject/Boilerplate/AndroidManifestXml.txt", "app/src/main/ic_launcher-web.png|AndroidProject/Boilerplate/IcLauncherWeb.png", ".idea/copyright/profiles_settings.xml|AndroidProject/Boilerplate/Idea/CopyrightProfilesSettingsXml.txt", ".idea/libraries/support_v4_18_0_0.xml|AndroidProject/Boilerplate/Idea/LibrariesSupportXml.txt", ".idea/scopes/scope_settings.xml|AndroidProject/Boilerplate/Idea/ScopeSettingsXml.txt", ".idea/.name|AndroidProject/Boilerplate/Idea/DotName.txt", ".idea/compiler.xml|AndroidProject/Boilerplate/Idea/CompilerXml.txt", ".idea/encodings.xml|AndroidProject/Boilerplate/Idea/EncodingsXml.txt", ".idea/gradle.xml|AndroidProject/Boilerplate/Idea/GradleXml.txt", ".idea/misc.xml|AndroidProject/Boilerplate/Idea/MiscXml.txt", ".idea/modules.xml|AndroidProject/Boilerplate/Idea/ModulesXml.txt", ".idea/vcs.xml|AndroidProject/Boilerplate/Idea/VcsXml.txt", ".idea/workspace.xml|AndroidProject/Boilerplate/Idea/WorkspaceXml.txt", // Crayon Android stuff pathToJavaCode + "/AndroidTranslationHelper.java|AndroidProject/AndroidTranslationHelper.txt", pathToJavaCode + "/GlUtil.java|AndroidProject/GlUtil.txt", pathToJavaCode + "/GameActivity.java|AndroidProject/GameActivity.txt", pathToJavaCode + "/OpenGlRenderer.java|AndroidProject/OpenGlRenderer.txt", pathToJavaCode + "/CrayonGlRenderer.java|AndroidProject/CrayonGlRenderer.txt", pathToJavaCode + "/CrayonGlSurfaceView.java|AndroidProject/CrayonGlSurfaceView.txt", // Generic Crayon Java stuff pathToJavaCode + "/TranslationHelper.java|Project/TranslationHelper.txt", pathToJavaCode + "/Image.java|Project/Image.txt", }) { string[] parts = simpleCopyText.Split('|'); string target = parts[0]; string source = parts[1]; bool isBinary = !source.EndsWith(".txt"); if (isBinary) { output[target] = new FileOutput() { Type = FileOutputType.Binary, BinaryContent = Util.ReadResourceBytesInternally("java-common/" + source) }; } else { string text = Util.ReadResourceFileInternally("java-common/" + source); output[target] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements(text, replacements) }; } } foreach (string basicFile in new string[] { "TranslationHelper", "Image", }) { output[pathToJavaCode + "/" + basicFile + ".java"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements( Util.ReadResourceFileInternally("java-common/" + basicFile + ".txt"), replacements) }; } string[] items = finalCode.Keys.OrderBy <string, string>(s => s.ToLowerInvariant()).ToArray(); List <string> crayonWrapper = new List <string>(); crayonWrapper.Add(string.Join("\n", "package %%%PACKAGE%%%;", "", "import java.util.ArrayList;", "import java.util.HashMap;", "import java.util.Stack;", "", "final class CrayonWrapper {", " private CrayonWrapper() {}", "")); this.Translator.CurrentIndention++; foreach (string finalCodeKey in items) { this.Translator.Translate(crayonWrapper, finalCode[finalCodeKey]); } this.Translator.CurrentIndention--; crayonWrapper.Add(string.Join("\n", "}", "")); output[pathToJavaCode + "/CrayonWrapper.java"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements(string.Join("", crayonWrapper), replacements) }; string nl = this.Translator.NL; foreach (StructDefinition structDefinition in structDefinitions) { string structName = structDefinition.Name.Value; string filename = structName + ".java"; List <string> codeContents = new List <string>(); codeContents.Add("class " + structName + " {" + nl); codeContents.Add(" public " + structName + "("); List <string> types = new List <string>(); for (int i = 0; i < structDefinition.FieldsByIndex.Length; ++i) { string type; Annotation typeAnnotation = structDefinition.Types[i]; if (typeAnnotation == null) { throw new Exception("Are there any of these left?"); } else { type = this.GetTypeStringFromAnnotation(typeAnnotation.FirstToken, typeAnnotation.GetSingleArgAsString(null), false, false); } types.Add(type); if (i > 0) { codeContents.Add(", "); } codeContents.Add(type); codeContents.Add(" v_" + structDefinition.FieldsByIndex[i]); } codeContents.Add(") {" + nl); for (int i = 0; i < structDefinition.FieldsByIndex.Length; ++i) { codeContents.Add(" this." + structDefinition.FieldsByIndex[i] + " = v_" + structDefinition.FieldsByIndex[i] + ";" + nl); } codeContents.Add(" }" + nl + nl); for (int i = 0; i < structDefinition.FieldsByIndex.Length; ++i) { codeContents.Add(" public "); codeContents.Add(types[i]); codeContents.Add(" " + structDefinition.FieldsByIndex[i] + ";" + nl); } codeContents.Add("}" + nl); string fileContents = string.Join("", codeContents); string header = "package " + package + ";" + nl + nl; bool useList = fileContents.Contains("ArrayList<"); bool useHashMap = fileContents.Contains("HashMap<"); bool useStack = fileContents.Contains("Stack<"); if (useList || useHashMap || useStack) { if (useList) { header += "import java.util.ArrayList;" + nl; } if (useHashMap) { header += "import java.util.HashMap;" + nl; } if (useStack) { header += "import java.util.Stack;" + nl; } header += nl; } fileContents = header + fileContents; output[pathToJavaCode + "/" + filename] = new FileOutput() { Type = FileOutputType.Text, TextContent = fileContents }; output["app/src/main/res/bytecode/ByteCode.txt"] = resourceDatabase.ByteCodeFile; } /* * foreach (string file in filesToCopyOver) * { * SystemBitmap bmpHack = null; * if (file.ToLowerInvariant().EndsWith(".png")) * { * bmpHack = new SystemBitmap(FileUtil.JoinPath(inputFolder, file)); * } * * if (bmpHack != null) * { * output["app/src/main/res/images/" + file] = new FileOutput() * { * Type = FileOutputType.Image, * Bitmap = bmpHack * }; * } * else * { * output["app/src/main/res/images/" + file] = new FileOutput() * { * Type = FileOutputType.Copy, * RelativeInputPath = file * }; * } * } * ///*/ output["app/src/main/res/raw/bytes.txt"] = resourceDatabase.ByteCodeFile; return(output); }
public override Dictionary <string, FileOutput> Package( BuildContext buildContext, string projectId, Dictionary <string, ParseTree.Executable[]> finalCode, ICollection <ParseTree.StructDefinition> structDefinitions, string fileCopySourceRoot, ResourceDatabase resourceDatabase, SystemLibraryManager libraryManager) { string jsFilePrefix = ""; if (buildContext.JsFilePrefix != null) { jsFilePrefix = buildContext.JsFilePrefix; if (!jsFilePrefix.StartsWith("/")) { jsFilePrefix = "/" + jsFilePrefix; } if (!jsFilePrefix.EndsWith("/")) { jsFilePrefix += "/"; } } Dictionary <string, FileOutput> output = new Dictionary <string, FileOutput>(); bool hasIcon = buildContext.IconFilePath != null; Dictionary <string, string> replacements = new Dictionary <string, string>() { { "PROJECT_ID", projectId }, { "DEFAULT_TITLE", buildContext.DefaultTitle ?? "Untitled" }, { "FAVICON", hasIcon ? "<link rel=\"shortcut icon\" href=\"" + jsFilePrefix + "favicon.ico\">" : "" }, }; if (hasIcon) { output["favicon.ico"] = new FileOutput() { Type = FileOutputType.Binary, BinaryContent = Util.GetIconFileBytesFromImageFile(buildContext.IconFilePath), }; } output["bytecode.js"] = new FileOutput() { Type = FileOutputType.Text, TextContent = "C$bytecode = " + Util.ConvertStringValueToCode(resourceDatabase.ByteCodeFile.TextContent, true) + ";\n" + "C$resourceManifest = " + Util.ConvertStringValueToCode(resourceDatabase.ResourceManifestFile.TextContent, true) + ";", }; List <string> codeJs = new List <string>(); foreach (string jsFile in new string[] { "common.js", }) { codeJs.Add(Util.ReadResourceFileInternally("javascript-common/" + jsFile)); codeJs.Add(this.Translator.NL); } foreach (string jsFile in new string[] { "game.js", "input.js", "imageresources.js", "drawing.js", "sound.js", "gamepad.js", }) { codeJs.Add(Util.ReadResourceFileInternally("game-javascript/" + jsFile)); codeJs.Add(this.Translator.NL); } foreach (string component in finalCode.Keys) { this.Translator.Translate(codeJs, finalCode[component]); codeJs.Add(this.Translator.NL); } string codeJsText = Constants.DoReplacements(string.Join("", codeJs), replacements); output["code.js"] = new FileOutput() { Type = FileOutputType.Text, TextContent = codeJsText }; output["libraries.js"] = new FileOutput() { Type = FileOutputType.Text, TextContent = libraryManager.EmbeddedContent, }; Dictionary <string, string> textResources = new Dictionary <string, string>(); foreach (FileOutput textFile in resourceDatabase.TextResources) { textResources["text/" + textFile.CanonicalFileName] = textFile.TextContent; } foreach (string filename in resourceDatabase.ImageSheetFiles.Keys) { FileOutput imageSheetFile = resourceDatabase.ImageSheetFiles[filename]; output["resources/images/" + filename] = imageSheetFile; } if (resourceDatabase.ImageSheetManifestFile != null) { textResources["imageresmanifest.txt"] = resourceDatabase.ImageSheetManifestFile.TextContent; } foreach (FileOutput audioFile in resourceDatabase.AudioResources) { output["resources/audio/" + audioFile.CanonicalFileName] = audioFile; } output["resources.js"] = new FileOutput() { TextContent = BuildTextResourcesCodeFile(textResources, jsFilePrefix), Type = FileOutputType.Text, }; output["index.html"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements(this.GenerateHtmlFile(), replacements), }; return(output); }
public override Dictionary <string, FileOutput> Package( BuildContext buildContext, string projectId, Dictionary <string, ParseTree.Executable[]> finalCode, ICollection <ParseTree.StructDefinition> structDefinitions, string fileCopySourceRoot, ResourceDatabase resourceDatabase, SystemLibraryManager libraryManager) { Dictionary <string, string> replacements = new Dictionary <string, string>() { { "PROJECT_GUID", GetGuid(buildContext.GuidSeed, "@@project").ToUpper() }, { "ASSEMBLY_GUID", GetGuid(buildContext.GuidSeed, "@@assembly").ToLower() }, { "PROJECT_TITLE", projectId }, { "PROJECT_ID", projectId }, { "CURRENT_YEAR", DateTime.Now.Year.ToString() }, { "COPYRIGHT", "©" }, }; Dictionary <string, FileOutput> output = new Dictionary <string, FileOutput>(); string crayonHeader = string.Join(this.Translator.NL, new string[] { "using System;", "using System.Collections.Generic;", "using System.Linq;", "", "namespace " + projectId, "{", "" }); string crayonWrapperHeader = string.Join(this.Translator.NL, new string[] { crayonHeader + "\tinternal partial class CrayonWrapper", "\t{", "" }); string crayonFooter = "}" + this.Translator.NL; string crayonWrapperFooter = "\t}" + this.Translator.NL + crayonFooter; string nl = this.Translator.NL; foreach (StructDefinition structDefinition in structDefinitions) { string structName = structDefinition.Name.Value; List <string> codeContents = new List <string>(); codeContents.Add(crayonHeader); codeContents.Add("\tpublic class " + structName + nl); codeContents.Add("\t{" + nl); codeContents.Add("\t\tpublic " + structName + "("); List <string> types = new List <string>(); for (int i = 0; i < structDefinition.FieldsByIndex.Length; ++i) { string type; Annotation typeAnnotation = structDefinition.Types[i]; if (typeAnnotation == null) { type = "object"; } else { type = this.GetTypeStringFromAnnotation(typeAnnotation.FirstToken, typeAnnotation.GetSingleArgAsString(null)); } types.Add(type); if (i > 0) { codeContents.Add(", "); } codeContents.Add(type); codeContents.Add(" v_" + structDefinition.FieldsByIndex[i]); } codeContents.Add(")" + nl); codeContents.Add("\t\t{" + nl); for (int i = 0; i < structDefinition.FieldsByIndex.Length; ++i) { codeContents.Add("\t\t\tthis." + structDefinition.FieldsByIndex[i] + " = v_" + structDefinition.FieldsByIndex[i] + ";" + nl); } codeContents.Add("\t\t}" + nl + nl); for (int i = 0; i < structDefinition.FieldsByIndex.Length; ++i) { codeContents.Add("\t\tpublic "); codeContents.Add(types[i]); codeContents.Add(" " + structDefinition.FieldsByIndex[i] + ";" + nl); } codeContents.Add("\t}" + nl); codeContents.Add(crayonFooter); output[projectId + "/Crayon/" + structName + ".cs"] = new FileOutput() { Type = FileOutputType.Text, TextContent = string.Join("", codeContents) }; } foreach (string codefile in finalCode.Keys) { List <string> codeContents = new List <string>(); codeContents.Add(crayonWrapperHeader); this.Translator.CurrentIndention = 2; this.Translator.Translate(codeContents, finalCode[codefile]); codeContents.Add(crayonWrapperFooter); output[projectId + "/Crayon/" + codefile + ".cs"] = new FileOutput() { Type = FileOutputType.Text, TextContent = string.Join("", codeContents) }; } // Copy templated files over with proper replacements foreach (string templateFile in new string[] { "TranslationHelper", }) { output[projectId + "/Crayon/" + templateFile + ".cs"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements( Util.ReadResourceFileInternally("csharp-common/" + templateFile + ".txt"), replacements) }; } // Add files for specific C# platform this.PlatformSpecificFiles(projectId, output, replacements, resourceDatabase, buildContext.IconFilePath, buildContext); Dictionary <string, string> libraryResourceFiles = this.LibraryManager.CopiedFiles; foreach (string file in libraryResourceFiles.Keys) { string content = libraryResourceFiles[file]; output[file.Replace("%PROJECT_ID%", projectId)] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements(content, replacements) }; } return(output); }
public override Dictionary <string, FileOutput> Package( BuildContext buildContext, string projectId, Dictionary <string, ParseTree.Executable[]> finalCode, ICollection <ParseTree.StructDefinition> structDefinitions, string fileCopySourceRoot, ResourceDatabase resourceDatabase, SystemLibraryManager libraryManager) { Dictionary <string, FileOutput> output = new Dictionary <string, FileOutput>(); List <string> concatenatedCode = new List <string>(); Dictionary <string, string> replacements = new Dictionary <string, string>() { { "PROJECT_ID", projectId }, }; bool hasIcon = buildContext.IconFilePath != null; if (hasIcon) { output["resources/icon.png"] = new FileOutput() { Type = FileOutputType.Copy, AbsoluteInputPath = buildContext.IconFilePath, }; } foreach (string file in new string[] { "Imports.py", "Header.py", "Library.py", "ImageHelper.py", "GfxRenderer.py", "ResourceReader.py", "GamepadLibraryHelper.py", }) { string content; if (file == "Library.py") { content = libraryManager.EmbeddedContent; } else { content = this.GetPyGameCode(file, replacements); } concatenatedCode.Add(content); concatenatedCode.Add(this.Translator.NL); } this.Translator.TranslateGlobals(concatenatedCode, finalCode); concatenatedCode.Add(this.Translator.NL); this.Translator.TranslateSwitchLookups(concatenatedCode, finalCode); concatenatedCode.Add(this.Translator.NL); this.Translator.TranslateFunctions(concatenatedCode, finalCode); concatenatedCode.Add(this.Translator.NL); concatenatedCode.Add(this.GetPyGameCode("Footer.py", replacements)); concatenatedCode.Add(this.Translator.NL); output["run.py"] = new FileOutput() { Type = FileOutputType.Text, TextContent = string.Join("", concatenatedCode) }; output["resources/byte_code.txt"] = resourceDatabase.ByteCodeFile; if (resourceDatabase.ImageSheetManifestFile != null) { output["resources/image_sheet_manifest.txt"] = resourceDatabase.ImageSheetManifestFile; } output["resources/manifest.txt"] = resourceDatabase.ResourceManifestFile; foreach (FileOutput textFile in resourceDatabase.TextResources) { output["resources/text/" + textFile.CanonicalFileName] = textFile; } foreach (FileOutput audioFile in resourceDatabase.AudioResources) { output["resources/audio/" + audioFile.CanonicalFileName] = audioFile; } Dictionary <string, FileOutput> imageSheetTiles = resourceDatabase.ImageSheetFiles; if (imageSheetTiles != null) { foreach (string tileName in imageSheetTiles.Keys) { output["resources/images/" + tileName] = imageSheetTiles[tileName]; } } foreach (FileOutput image in resourceDatabase.ImageResources) { if (image.Type != FileOutputType.Ghost) { output["resources/images/" + image.CanonicalFileName] = image; } } return(output); }
public override Dictionary <string, FileOutput> Package( BuildContext buildContext, string projectId, Dictionary <string, ParseTree.Executable[]> finalCode, ICollection <ParseTree.StructDefinition> structDefinitions, string fileCopySourceRoot, ResourceDatabase resourceDatabase, SystemLibraryManager libraryManager) { Dictionary <string, FileOutput> output = new Dictionary <string, FileOutput>(); string package = projectId.ToLowerInvariant(); Dictionary <string, string> replacements = new Dictionary <string, string>() { { "PROJECT_TITLE", projectId }, { "PROJECT_ID", projectId }, { "PACKAGE", package }, { "CURRENT_YEAR", DateTime.Now.Year.ToString() }, { "COPYRIGHT", "©" }, }; bool hasIcon = buildContext.IconFilePath != null; if (hasIcon) { output["resources/icon.png"] = new FileOutput() { Type = FileOutputType.Copy, AbsoluteInputPath = buildContext.IconFilePath, }; } foreach (string awtFile in new string[] { "AwtTranslationHelper", }) { output["src/" + package + "/" + awtFile + ".java"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements( Util.ReadResourceFileInternally("game-java-awt/" + awtFile + ".txt"), replacements) }; } foreach (string basicFile in new string[] { "TranslationHelper", }) { output["src/" + package + "/" + basicFile + ".java"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements( Util.ReadResourceFileInternally("java-common/" + basicFile + ".txt"), replacements) }; } foreach (string basicFile in new string[] { "AwtTranslationHelper", "Start", "GameWindow", "Image", "RenderEngine", }) { output["src/" + package + "/" + basicFile + ".java"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements( Util.ReadResourceFileInternally("game-java-awt/" + basicFile + ".txt"), replacements) }; } string[] items = finalCode.Keys.OrderBy <string, string>(s => s.ToLowerInvariant()).ToArray(); List <string> crayonWrapper = new List <string>(); crayonWrapper.Add(string.Join("\n", "package %%%PACKAGE%%%;", "", "import java.util.ArrayList;", "import java.util.HashMap;", "import java.util.Stack;", "", "public final class CrayonWrapper {", " private CrayonWrapper() {}", "")); this.Translator.CurrentIndention++; foreach (string finalCodeKey in items) { this.Translator.Translate(crayonWrapper, finalCode[finalCodeKey]); } this.Translator.CurrentIndention--; crayonWrapper.Add(string.Join("\n", "}", "")); output["src/" + package + "/CrayonWrapper.java"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements(string.Join("", crayonWrapper), replacements) }; string nl = this.Translator.NL; foreach (StructDefinition structDefinition in structDefinitions) { string structName = structDefinition.Name.Value; string filename = structName + ".java"; List <string> codeContents = new List <string>(); codeContents.Add("public final class " + structName + " {" + nl); codeContents.Add(" public " + structName + "("); List <string> types = new List <string>(); for (int i = 0; i < structDefinition.FieldsByIndex.Length; ++i) { string type; Annotation typeAnnotation = structDefinition.Types[i]; if (typeAnnotation == null) { throw new Exception("Are there any of these left?"); } else { type = this.GetTypeStringFromAnnotation(typeAnnotation.FirstToken, typeAnnotation.GetSingleArgAsString(null), false, false); } types.Add(type); if (i > 0) { codeContents.Add(", "); } codeContents.Add(type); codeContents.Add(" v_" + structDefinition.FieldsByIndex[i]); } codeContents.Add(") {" + nl); for (int i = 0; i < structDefinition.FieldsByIndex.Length; ++i) { codeContents.Add(" this." + structDefinition.FieldsByIndex[i] + " = v_" + structDefinition.FieldsByIndex[i] + ";" + nl); } codeContents.Add(" }" + nl + nl); for (int i = 0; i < structDefinition.FieldsByIndex.Length; ++i) { codeContents.Add(" public "); codeContents.Add(types[i]); codeContents.Add(" " + structDefinition.FieldsByIndex[i] + ";" + nl); } codeContents.Add("}" + nl); string fileContents = string.Join("", codeContents); string header = "package " + package + ";" + nl + nl; bool useList = fileContents.Contains("ArrayList<"); bool useHashMap = fileContents.Contains("HashMap<"); bool useStack = fileContents.Contains("Stack<"); if (useList || useHashMap || useStack) { if (useList) { header += "import java.util.ArrayList;" + nl; } if (useHashMap) { header += "import java.util.HashMap;" + nl; } if (useStack) { header += "import java.util.Stack;" + nl; } header += nl; } fileContents = header + fileContents; output["src/" + package + "/" + filename] = new FileOutput() { Type = FileOutputType.Text, TextContent = fileContents }; } foreach (string tileFile in resourceDatabase.ImageSheetFiles.Keys) { output["resources/images/" + tileFile] = resourceDatabase.ImageSheetFiles[tileFile]; } foreach (FileOutput image in resourceDatabase.ImageResources) { if (image.Type != FileOutputType.Ghost) { output["resources/images/" + image.CanonicalFileName] = image; } } foreach (FileOutput textFile in resourceDatabase.TextResources) { output["resources/text/" + textFile.CanonicalFileName] = textFile; } Dictionary <string, string> libraryResourceFiles = this.LibraryManager.CopiedFiles; foreach (string file in libraryResourceFiles.Keys) { string content = libraryResourceFiles[file]; output[file.Replace("%PROJECT_ID%", projectId.ToLower())] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements(content, replacements) }; } output["resources/bytecode.txt"] = resourceDatabase.ByteCodeFile; output["resources/manifest.txt"] = resourceDatabase.ResourceManifestFile; if (resourceDatabase.ImageSheetManifestFile != null) { output["resources/imagesheetmanifest.txt"] = resourceDatabase.ImageSheetManifestFile; } output["build.xml"] = new FileOutput() { Type = FileOutputType.Text, TextContent = Constants.DoReplacements( Util.ReadResourceFileInternally("game-java-awt/BuildXml.txt"), replacements) }; return(output); }