Example #1
0
        public override ICodeBlock GenerateFields(ICodeBlock codeBlock, SaveClasses.IElement element)
        {
            var currentBlock = codeBlock;

            if (element.HasStates)
            {
                List <StateSave> statesForThisCategory = GetSharedVariableStates(element);

                const string enumName = "VariableState";

                currentBlock = CreateClassForStateCategory(currentBlock, statesForThisCategory, enumName, element);
                GenerateCurrentStateProperty(element, codeBlock, "VariableState", statesForThisCategory);

                //Build State Categories
                var stateCategories = GetAllStateCategoryNames(element, false);

                foreach (var stateCategory in stateCategories)
                {
                    var states = GetAllStatesForCategory(element, stateCategory);

                    CreateClassForStateCategory(currentBlock, states, stateCategory, element);
                    GenerateCurrentStateProperty(element, codeBlock, stateCategory, states);
                }
            }

            return(codeBlock);
        }
Example #2
0
        public static List <StateSave> GetSharedVariableStates(SaveClasses.IElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element argument cannot be null");
            }

            var statesForThisCategory = new List <StateSave>();

            var currentElement = element;

            //Get states for parent entities
            if (!string.IsNullOrEmpty(currentElement.BaseElement))
            {
                IElement baseElement = ObjectFinder.Self.GetIElement(currentElement.BaseElement);
                if (baseElement != null)
                {
                    statesForThisCategory.AddRange(GetSharedVariableStates(baseElement));
                }
            }


            for (int i = 0; i < element.States.Count; i++)
            {
                statesForThisCategory.Add(element.States[i]);
            }

            statesForThisCategory.AddRange(element.StateCategoryList.Where(category => category.SharesVariablesWithOtherCategories).SelectMany(category => category.States));
            return(statesForThisCategory);
        }
Example #3
0
        public override ICodeBlock GenerateFields(ICodeBlock codeBlock, SaveClasses.IElement element)
        {
            codeBlock.Line("#if DEBUG");
            codeBlock.Line("static bool HasBeenLoadedWithGlobalContentManager = false;");
            codeBlock.Line("#endif");

            return(codeBlock);
        }
Example #4
0
        public override ICodeBlock GenerateLoadStaticContent(ICodeBlock codeBlock, SaveClasses.IElement element)
        {
            #region For debugging record if we're using a global content manager

            codeBlock.Line("#if DEBUG");

            codeBlock.If("contentManagerName == FlatRedBall.FlatRedBallServices.GlobalContentManager")
            .Line("HasBeenLoadedWithGlobalContentManager = true;");

            codeBlock.ElseIf("HasBeenLoadedWithGlobalContentManager")
            .Line("throw new System.Exception(\"This type has been loaded with a Global content manager, then loaded with a non-global.  This can lead to a lot of bugs\");");

            codeBlock.Line("#endif");

            #endregion

            return(codeBlock);
        }
        public override ICodeBlock GenerateFields(ICodeBlock codeBlock, SaveClasses.IElement element)
        {
            EntitySave asEntitySave = element as EntitySave;

            if (asEntitySave != null && asEntitySave.ImplementsICollidable)
            {
                codeBlock.Line("private FlatRedBall.Math.Geometry.ShapeCollection mGeneratedCollision;");
                var propBlock = codeBlock.Property("public FlatRedBall.Math.Geometry.ShapeCollection", "Collision");

                propBlock.Get().Line("return mGeneratedCollision;");

                return(codeBlock);
            }
            else
            {
                return(base.GenerateFields(codeBlock, element));
            }
        }
Example #6
0
        public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, SaveClasses.IElement element)
        {
            if (element.HasStates)
            {
                List <StateSave> sharedVariableStates = GetSharedVariableStates(element);

                if (sharedVariableStates.Count != 0)
                {
                    #region Create the static state that should be set prior to loading

                    string propertyPrefix = "public static ";

                    if (!string.IsNullOrEmpty(element.BaseElement))
                    {
                        IElement baseElement = ObjectFinder.Self.GetIElement(element.BaseElement);
                        if (baseElement != null && baseElement.DefinesCategoryEnumRecursive("VariableState"))
                        {
                            propertyPrefix += "new ";
                        }
                    }

                    codeBlock
                    .Line("static VariableState mLoadingState = null;")
                    .Property(propertyPrefix + "VariableState", "LoadingState")
                    .Get()
                    .Line("return mLoadingState;")
                    .End()
                    .Set()
                    .Line("mLoadingState = value;")
                    .End()
                    .End();

                    #endregion
                }



                GenerateInterpolationAdditionalMethods(codeBlock, element, sharedVariableStates);

                GeneratePreloadStateContent(codeBlock, element, sharedVariableStates);
            }

            return(codeBlock);
        }
        public override CodeBuilder.ICodeBlock GenerateAdditionalMethods(CodeBuilder.ICodeBlock codeBlock, SaveClasses.IElement element)
        {
            if (element is EntitySave)
            {
                bool hasBase = element.InheritsFromElement();
                if (hasBase == false)
                {
                    codeBlock.Line("protected bool mIsPaused;");

                    var function = codeBlock.Function("public override void", "Pause", "FlatRedBall.Instructions.InstructionList instructions");

                    function.Line("base.Pause(instructions);");
                    function.Line("mIsPaused = true;");

                    foreach (var nos in element.AllNamedObjects)
                    {
                        GeneratePauseForNos(nos, function);
                    }
                }
                codeBlock = GenerateSetToIgnorePausing(codeBlock, element, hasBase);
            }

            return(codeBlock);
        }
 public override CodeBuilder.ICodeBlock GenerateInitialize(CodeBuilder.ICodeBlock codeBlock, SaveClasses.IElement element)
 {
     if (IsLoadingScreen(element))
     {
         codeBlock.Line("mSavedTargetElapedTime = FlatRedBallServices.Game.TargetElapsedTime.TotalSeconds;");
         codeBlock.Line("FlatRedBall.FlatRedBallServices.Game.TargetElapsedTime = TimeSpan.FromSeconds(.1);");
     }
     return(codeBlock);
 }
Example #9
0
 public override ICodeBlock GenerateActivity(ICodeBlock codeBlock, SaveClasses.IElement element)
 {
     //throw new NotImplementedException();
     return(codeBlock);
 }
Example #10
0
 public override ICodeBlock GenerateInitialize(ICodeBlock codeBlock, SaveClasses.IElement element)
 {
     return(codeBlock);
 }
        public override CodeBuilder.ICodeBlock GenerateFields(CodeBuilder.ICodeBlock codeBlock, SaveClasses.IElement element)
        {
            if (element is EntitySave)
            {
                EntitySave asEntity = element as EntitySave;

                if (asEntity.CreatedByOtherEntities && asEntity.GetAllBaseEntities().Count(item => item.CreatedByOtherEntities) == 0)
                {
                    codeBlock.AutoProperty("public int", "Index");
                    codeBlock.AutoProperty("public bool", "Used");
                }
            }

            return(codeBlock);
        }
Example #12
0
 public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, SaveClasses.IElement element)
 {
     return(codeBlock);
 }
Example #13
0
 public override ICodeBlock GenerateActivity(ICodeBlock codeBlock, SaveClasses.IElement element)
 {
     return(codeBlock);
 }
Example #14
0
 public override ICodeBlock GenerateAddToManagers(ICodeBlock codeBlock, SaveClasses.IElement element)
 {
     return(codeBlock);
 }
        private static CodeBuilder.ICodeBlock GenerateSetToIgnorePausing(CodeBuilder.ICodeBlock codeBlock, SaveClasses.IElement element, bool hasBase)
        {
            string virtualOrOverride = "virtual";

            if (hasBase)
            {
                virtualOrOverride = "override";
            }

            codeBlock = codeBlock.Function("public " + virtualOrOverride + " void", "SetToIgnorePausing", "");

            if (hasBase)
            {
                codeBlock.Line("base.SetToIgnorePausing();");
            }
            else
            {
                codeBlock.Line("FlatRedBall.Instructions.InstructionManager.IgnorePausingFor(this);");
            }

            foreach (NamedObjectSave nos in element.AllNamedObjects)
            {
                if (nos.IsFullyDefined && !nos.IsDisabled && !nos.IsContainer)
                {
                    NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);

                    bool shouldWrapInNullCheck = nos.SetByDerived || nos.SetByContainer || nos.Instantiate == false;

                    if (shouldWrapInNullCheck)
                    {
                        codeBlock = codeBlock.If(nos.InstanceName + " != null");
                    }



                    if (nos.GetAssetTypeInfo() != null && nos.GetAssetTypeInfo().CanIgnorePausing)
                    {
                        codeBlock.Line("FlatRedBall.Instructions.InstructionManager.IgnorePausingFor(" + nos.InstanceName + ");");
                    }
                    else if (nos.SourceType == SourceType.Entity)
                    {
                        codeBlock.Line(nos.InstanceName + ".SetToIgnorePausing();");
                    }

                    if (shouldWrapInNullCheck)
                    {
                        codeBlock = codeBlock.End();
                    }

                    NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);
                }
            }

            codeBlock = codeBlock.End();
            return(codeBlock);
        }
Example #16
0
        private static void GenerateInterpolationAdditionalMethods(ICodeBlock codeBlock, SaveClasses.IElement element, List <StateSave> sharedVariableStates)
        {
            StateCodeGenerator.GenerateInterpolateToStateMethod(element, codeBlock, "VariableState", sharedVariableStates);
            StateCodeGenerator.GenerateInterpolateBetweenMethod(element, codeBlock, "VariableState", sharedVariableStates);

            foreach (StateSaveCategory category in element.StateCategoryList.Where((category) => category.SharesVariablesWithOtherCategories == false))
            {
                StateCodeGenerator.GenerateInterpolateToStateMethod(element, codeBlock, category.Name, category.States);
                StateCodeGenerator.GenerateInterpolateBetweenMethod(element, codeBlock, category.Name, category.States);
            }
        }
Example #17
0
 public override CodeGeneration.CodeBuilder.ICodeBlock GenerateActivity(CodeGeneration.CodeBuilder.ICodeBlock codeBlock, SaveClasses.IElement element)
 {
     // We used to call TimedEmit here
     // but we only want to call it if the
     // NOS is non-null. That means we are going
     // to call the TimedEmit generating code from
     // within the NamedObjectSaveCodeGenerator's GenerateActivity
     return(codeBlock);
 }