Beispiel #1
0
        private static ICodeBlock GetLoadGlobalContentCode()
        {
            ICodeBlock codeBlock = new CodeDocument();

            if (ProjectManager.GlueProjectSave.GlobalContentSettingsSave.LoadAsynchronously)
            {
                codeBlock
                .Struct("", "NamedDelegate")
                .Line("public string Name;")
                .Line("public System.Action LoadMethod;")
                .End()
                ._()
                .Line("static List<NamedDelegate> LoadMethodList = new List<NamedDelegate>();")
                ._();
            }

            string className = "GlobalContent";

            #region Instantiate the ClassProperties
            ClassProperties classProperties = new ClassProperties();
            classProperties.Members        = new List <FlatRedBall.Instructions.Reflection.TypedMemberBase>();
            classProperties.UntypedMembers = new Dictionary <string, string>();
            #endregion

            classProperties.NamespaceName = ProjectManager.ProjectNamespace;
            classProperties.ClassName     = className;
            classProperties.IsStatic      = true;
            classProperties.Partial       = true;

            classProperties.UsingStatements = new List <string>();



            #region Add using statements

            // todo: remove these, we don't need them anymore and they could cause ambiguity
            classProperties.UsingStatements.Add("System.Collections.Generic");
            classProperties.UsingStatements.Add("System.Threading");
            classProperties.UsingStatements.Add("FlatRedBall");
            classProperties.UsingStatements.Add("FlatRedBall.Math.Geometry");
            classProperties.UsingStatements.Add("FlatRedBall.ManagedSpriteGroups");
            classProperties.UsingStatements.Add("FlatRedBall.Graphics.Animation");
            classProperties.UsingStatements.Add("FlatRedBall.Graphics.Particle");
            classProperties.UsingStatements.Add("FlatRedBall.AI.Pathfinding");
            classProperties.UsingStatements.Add("FlatRedBall.Utilities");
            classProperties.UsingStatements.Add("BitmapFont = FlatRedBall.Graphics.BitmapFont");
            classProperties.UsingStatements.Add("FlatRedBall.Localization");



            bool shouldAddUsingForDataTypes = false;

            for (int i = 0; i < ProjectManager.GlueProjectSave.GlobalFiles.Count; i++)
            {
                if (FileManager.GetExtension(ProjectManager.GlueProjectSave.GlobalFiles[i].Name) == "csv")
                {
                    shouldAddUsingForDataTypes = true;
                    break;
                }
            }

            if (shouldAddUsingForDataTypes)
            {
                classProperties.UsingStatements.Add(ProjectManager.ProjectNamespace + ".DataTypes");
                classProperties.UsingStatements.Add("FlatRedBall.IO.Csv");
            }

            #endregion

            var contents = GetGlobalContentFilesMethods();

            codeBlock.InsertBlock(contents);

            classProperties.MethodContent = codeBlock;

            var toReturn = CodeWriter.CreateClass(classProperties);

            var block = new CodeBlockBaseNoIndent(null);
            block.Line("#if ANDROID || IOS || DESKTOP_GL");
            block.Line("// Android doesn't allow background loading. iOS doesn't allow background rendering (which is used by converting textures to use premult alpha)");
            block.Line("#define REQUIRES_PRIMARY_THREAD_LOADING");
            block.Line("#endif");


            toReturn.PreCodeLines.Add(block);

            return(toReturn);
        }