Example #1
0
        private static string GetDisplaySetupNew(ICodeBlock fileCode)
        {
            var displaySettings = GlueState.Self.CurrentGlueProject.DisplaySettings;


            fileCode.Line("using Camera = FlatRedBall.Camera;");

            var namespaceContents = fileCode.Namespace(ProjectManager.ProjectNamespace);

            GenerateCameraSetupData(namespaceContents);

            GenerateResizeBehaviorEnum(namespaceContents);

            GenerateWidthOrHeightEnum(namespaceContents);

            var classContents = namespaceContents.Class("internal static", "CameraSetup");

            classContents.Line("static Microsoft.Xna.Framework.GraphicsDeviceManager graphicsDeviceManager;");

            GenerateStaticCameraSetupData(classContents);

            GenerateResetMethodNew(displaySettings.GenerateDisplayCode, classContents);

            GenerateSetupCameraMethodNew(displaySettings.GenerateDisplayCode, classContents);

            GenerateResetWindow(displaySettings.GenerateDisplayCode, classContents);

            GenerateHandleResize(classContents);

            GenerateSetAspectRatio(classContents);

            return(fileCode.ToString());
        }
Example #2
0
        private static bool GenerateClassFromMembers(ReferencedFileSave rfs, bool succeeded, string className, List <TypedMemberBase> members, Dictionary <string, string> untypedMembers)
        {
            ICodeBlock codeBlock = new CodeDocument();

            // If the CSV
            // is going to
            // be deserialized
            // to a dictionary,
            // then we should create
            // const members for all of
            // the keys in the dictionary
            // to make accessing the dictionary
            // type-safe.
            if (rfs != null)
            {
                succeeded = CreateConstsForCsvEntries(rfs, members, untypedMembers, codeBlock);
            }

            FilePath absoluteFileName = null;

            if (succeeded)
            {
                ICodeBlock codeContent = CodeWriter.CreateClass(ProjectManager.ProjectNamespace + ".DataTypes", className, true, members,
                                                                false, new List <string>(), untypedMembers, codeBlock);


                if (rfs != null)
                {
                    absoluteFileName = Plugins.ExportedImplementations.GlueState.Self.CurrentGlueProjectDirectory + GetFullDataFileNameFor(rfs);
                }
                else
                {
                    absoluteFileName = Plugins.ExportedImplementations.GlueState.Self.CurrentGlueProjectDirectory + "DataTypes/" + className + ".Generated.cs";
                }

                CodeWriter.SaveFileContents(codeContent.ToString(), absoluteFileName.FullPath, true);

                GlueCommands.Self.ProjectCommands.CreateAndAddCodeFile(absoluteFileName, save: false);
            }

            if (succeeded)
            {
                string message;
                if (rfs != null)
                {
                    message = "Generating class " + className + " from CSV " + rfs.Name + " to " + absoluteFileName;
                }
                else
                {
                    message = "Generating class " + className + " from Custom Class";
                }


                Plugins.PluginManager.ReceiveOutput(message);
            }
            return(succeeded);
        }
Example #3
0
        private static string GetDisplaySetupOld(ICodeBlock classContents)
        {
            string fileContents = Resources.Resource1.CameraSetupTemplate;

            fileContents = CodeWriter.ReplaceNamespace(fileContents, ProjectManager.ProjectNamespace);


            GenerateSetupCameraMethod(classContents);
            GenerateResetCameraMethod(classContents);

            StringFunctions.ReplaceLine(ref fileContents, "// Generated Code:", classContents.ToString());
            return(fileContents);
        }
Example #4
0
        public static void GenerateEventGeneratedFile(IElement element)
        {
            //string fileName = EventManager.GetEventFileNameForElement(element);
            //string fullCustomFileName = ProjectManager.ProjectBase.Directory + fileName;

            ////////////////// Early Out //////////////////////

            ///////////////// End Early Out////////////////////

            string projectDirectory = ProjectManager.ProjectBase.Directory;


            string fullGeneratedFileName = projectDirectory + EventManager.GetGeneratedEventFileNameForElement(element);

            ////////////////EARLY OUT///////////////
            if (element.Events.Count == 0)
            {
                // The file may exist.  If it does, we want to make sure it's empty:
                if (File.Exists(fullGeneratedFileName))
                {
                    FileWatchManager.IgnoreNextChangeOnFile(fullGeneratedFileName);
                    FileManager.SaveText("", fullGeneratedFileName);
                }


                return;
            }
            ///////////////END EARLY OUT///////////

            if (!File.Exists(fullGeneratedFileName))
            {
                CodeWriter.AddEventGeneratedCodeFileForElement(element);
            }
            else
            {
                // Make sure the file is part of the project
                GlueCommands.Self.ProjectCommands.UpdateFileMembershipInProject(ProjectManager.ProjectBase, fullGeneratedFileName, false, false);
            }

            ICodeBlock codeBlock = GenerateEventGeneratedCodeFile(element);

            // Let's try this a few times:
            int  numberOfFailures = 0;
            bool succeeded        = false;

            FileWatchManager.IgnoreNextChangeOnFile(fullGeneratedFileName);

            while (numberOfFailures < 3)
            {
                try
                {
                    FileManager.SaveText(codeBlock.ToString(), fullGeneratedFileName);
                    succeeded = true;
                    break;
                }
                catch
                {
                    numberOfFailures++;
                    System.Threading.Thread.Sleep(30);
                }
            }

            if (!succeeded)
            {
                GlueGui.ShowMessageBox("Could not save " + fullGeneratedFileName);
            }
        }
Example #5
0
        public override string GetCode()
        {
            string entityClassName = FileManager.RemovePath(FileManager.RemoveExtension(EntitySave.Name));

            string baseEntityName = null;

            if (!string.IsNullOrEmpty(EntitySave.BaseEntity))
            {
                EntitySave rootEntitySave = EntitySave.GetRootBaseEntitySave();

                // There could be an invalid inheritance chain.  We don't want Glue to bomb if so, so
                // we'll check for this.
                if (rootEntitySave != null && rootEntitySave != EntitySave)
                {
                    baseEntityName = rootEntitySave.Name;
                }
            }


            string factoryClassName = ClassName;

            ClassProperties classProperties = new ClassProperties();

            classProperties.NamespaceName = ProjectManager.ProjectNamespace + ".Factories";
            classProperties.ClassName     = factoryClassName + " : IEntityFactory";

            classProperties.Members = new List <FlatRedBall.Instructions.Reflection.TypedMemberBase>();

            classProperties.UntypedMembers = new Dictionary <string, string>();
            string positionedObjectListType = string.Format("FlatRedBall.Math.PositionedObjectList<{0}>", entityClassName);

            // Factories used to be always static but we're going to make them singletons instead
            //classProperties.IsStatic = true;

            classProperties.UsingStatements = new List <string>();
            classProperties.UsingStatements.Add(GlueCommands.Self.GenerateCodeCommands.GetNamespaceForElement(EntitySave));
            classProperties.UsingStatements.Add("System");

            if (!string.IsNullOrEmpty(baseEntityName))
            {
                EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(baseEntityName);
                classProperties.UsingStatements.Add(GlueCommands.Self.GenerateCodeCommands.GetNamespaceForElement(baseEntity));
            }


            classProperties.UsingStatements.Add("FlatRedBall.Math");
            classProperties.UsingStatements.Add("FlatRedBall.Graphics");
            classProperties.UsingStatements.Add(ProjectManager.ProjectNamespace + ".Performance");


            ICodeBlock codeContent = CodeWriter.CreateClass(classProperties);

            const int numberOfInstancesToPool = 20;

            var methodTag = codeContent.GetTag("Methods")[0];

            var methodBlock = GetAllFactoryMethods(factoryClassName, baseEntityName, numberOfInstancesToPool,
                                                   ShouldPoolObjects);

            methodTag.InsertBlock(methodBlock);

            var codeBlock = new CodeBlockBase(null);

            codeBlock.Line("static string mContentManagerName;");
            codeBlock.Line("static System.Collections.Generic.List<System.Collections.IList> ListsToAddTo = new System.Collections.Generic.List<System.Collections.IList>();");

            codeBlock.Line(string.Format("static PoolList<{0}> mPool = new PoolList<{0}>();", entityClassName));

            codeBlock.Line(string.Format("public static Action<{0}> EntitySpawned;", entityClassName));

            ImplementIEntityFactory(factoryClassName, codeBlock);

            #region Self and mSelf
            codeBlock.Line("static " + factoryClassName + " mSelf;");

            var selfProperty = codeBlock.Property("public static " + factoryClassName, "Self");
            var selfGet      = selfProperty.Get();
            selfGet.If("mSelf == null")
            .Line("mSelf = new " + entityClassName + "Factory" + "();");
            selfGet.Line("return mSelf;");
            #endregion

            ((codeContent.BodyCodeLines.Last() as CodeBlockBase).BodyCodeLines.Last() as CodeBlockBase).InsertBlock(codeBlock);
            return(codeContent.ToString());
        }