Beispiel #1
0
        private static void GenerateResizeBehaviorEnum(CodeBlockNamespace namespaceContents)
        {
            var enumBlock = namespaceContents.Enum("public", "ResizeBehavior");

            enumBlock.Line("StretchVisibleArea,");
            enumBlock.Line("IncreaseVisibleArea");
        }
Beispiel #2
0
        public static void GenerateWidthOrHeightEnum(CodeBlockNamespace namespaceContents)
        {
            var enumBlock = namespaceContents.Enum("public", "WidthOrHeight");

            enumBlock.Line("Width,");
            enumBlock.Line("Height");
        }
Beispiel #3
0
        private static string GetFileAliasLogicFileContents(bool isUsingContentPipeline)
        {
            var glueState = Container.Get <IGlueState>();

            var namespaceBlock = new CodeBlockNamespace(null, glueState.ProjectNamespace);

            var classBlock = namespaceBlock.Class("public", "FileAliasLogic");

            var codeBlock = classBlock.Function("public static void", "SetFileAliases", "");

            var files = ContentPipelineController.GetReferencedPngs();

            var contentFolder = glueState.ContentDirectory;

            if (isUsingContentPipeline)
            {
                foreach (var file in files)
                {
                    var    relativeFile  = "content/" + FileManager.MakeRelative(file, contentFolder).ToLowerInvariant();
                    string withExtension = relativeFile;
                    string noExtension   = FileManager.RemoveExtension(relativeFile);
                    var    line          =
                        $"FlatRedBall.Content.ContentManager.FileAliases.Add(FlatRedBall.IO.FileManager.Standardize(\"{withExtension}\"), " +
                        $"FlatRedBall.IO.FileManager.Standardize(\"{noExtension}\"));";
                    codeBlock.Line(line);
                }
            }

            var codeFileContents = namespaceBlock.ToString();

            return(codeFileContents);
        }
        internal void RegenCodeDialogTreeTags()
        {
            const string fieldType          = "public const string";
            var          nameSpaceBlock     = new CodeBlockNamespace(null, ProjectManager.ProjectBase.RootNamespace);
            var          classBlock         = nameSpaceBlock.Class("public partial", "DialogTree");
            var          internalClassBlock = classBlock.Class("public", "Tag");
            var          codeFileName       = $"{FileManager.GetDirectory(GlueState.Self.CurrentGlueProjectFileName)}DialogTree.Tags.Generated.cs";

            foreach (var tag in dialogTreeTags)
            {
                internalClassBlock.Line($"{fieldType} {tag} = \"{tag}\";");
            }

            TaskManager.Self.AddAsyncTask(
                () =>
            {
                bool wasSaved = SaveDiaogTreeCsFile(nameSpaceBlock.ToString(), codeFileName);

                bool wasAdded = ProjectManager.CodeProjectHelper.AddFileToCodeProjectIfNotAlreadyAdded(ProjectManager.ProjectBase, codeFileName);

                if (wasAdded)
                {
                    ProjectManager.SaveProjects();
                }
            },
                "Adding geneated file to the DialogTree file"
                );
        }
Beispiel #5
0
        public static string GetGame1GeneratedContents()
        {
            var namespaceBlock = new CodeBlockNamespace(null, GlueState.Self.ProjectNamespace);
            var classBlock     = namespaceBlock.Class("public partial", "Game1");

            GenerateClassScope(classBlock);

            GenerateGeneratedInitialize(classBlock);

            GenerateGeneratedUpdate(classBlock);

            GenerateGeneratedDraw(classBlock);

            return(namespaceBlock.ToString());
        }
        private static void GenerateCameraSetupData(CodeBlockNamespace namespaceContents)
        {
            var classBlock = namespaceContents.Class("public", "CameraSetupData");

            classBlock.AutoProperty("public float", "Scale");
            classBlock.AutoProperty("public bool", "Is2D");
            classBlock.AutoProperty("public int", "ResolutionWidth");
            classBlock.AutoProperty("public int", "ResolutionHeight");
            classBlock.AutoProperty("public decimal?", "AspectRatio");
            classBlock.AutoProperty("public bool", "AllowWidowResizing");
            classBlock.AutoProperty("public bool", "IsFullScreen");
            classBlock.AutoProperty("public ResizeBehavior", "ResizeBehavior");
            classBlock.AutoProperty("public WidthOrHeight", "DominantInternalCoordinates");



            // set up here
        }
        internal void RegenCodeDialogTreeFileName()
        {
            const string fieldType      = "public const string";
            var          nameSpaceBlock = new CodeBlockNamespace(null, ProjectManager.ProjectBase.RootNamespace);
            var          classBlock     = nameSpaceBlock.Class("public partial", "DialogTree");
            var          codeFileName   = $"{FileManager.GetDirectory(GlueState.Self.CurrentGlueProjectFileName)}DialogTree.Generated.cs";

            //AutoGen the deserialization function.
            //We do not need a try catch since we know the deserialization will work.
            var deserializeFunction = classBlock.Function("public static Rootobject", "DeserializeDialogTree", "string fileName");

            deserializeFunction.Line("var fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open);");
            deserializeFunction.Line("var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Rootobject));");
            deserializeFunction.Line("var toReturn = (Rootobject)serializer.ReadObject(fileStream);");
            deserializeFunction.Line("fileStream.Close();");
            deserializeFunction.Line("return toReturn;");

            var getFileFromNameFunction = classBlock.Function("public static Rootobject", "GetFileFromName", "string fileName");

            getFileFromNameFunction.Line("Rootobject toReturn = null;");
            var switchStatement = getFileFromNameFunction.Switch("fileName");

            var destroyFunction = classBlock.Function("public static void", "ClearTrees", string.Empty);

            foreach (var treeName in dialogTreeFileNames)
            {
                var fileName  = FileManager.RemovePath(treeName);
                var fieldName = FileManager.RemoveExtension(fileName);
                var localPath = FileManager.MakeRelative(treeName);

                classBlock.Line($"private static Rootobject m{fieldName};");
                var property = classBlock.Property("public static Rootobject", $"{fieldName}");
                var get      = property.Get();
                get.If($"m{fieldName} == null").Line($"m{fieldName} = DeserializeDialogTree(\"{localPath.ToLower()}\");");
                get.Line($"return m{fieldName};");

                destroyFunction.Line($"m{fieldName} = null;");

                //classBlock.Line($"{fieldType} {fieldName} = \"{localPath.ToLower()}\";");

                switchStatement.Line($"case \"{fieldName}\":");
                switchStatement.Line($"    toReturn = DialogTree.{fieldName};");
                switchStatement.Line($"    break;");
            }

            getFileFromNameFunction.Line("return toReturn;");

            TaskManager.Self.AddAsyncTask(
                () =>
            {
                bool wasSaved = SaveDiaogTreeCsFile(nameSpaceBlock.ToString(), codeFileName);

                bool wasAdded = ProjectManager.CodeProjectHelper.AddFileToCodeProjectIfNotAlreadyAdded(ProjectManager.ProjectBase, codeFileName);

                if (wasAdded)
                {
                    ProjectManager.SaveProjects();
                }
            },
                "Adding geneated file to the DialogTree file"
                );
        }