public static string GetSecondGenericType(NamedObjectSave collisionRelationship, out bool isList)
        {
            var secondName = collisionRelationship.Properties.GetValue <string>(nameof(CollisionRelationshipViewModel.SecondCollisionName));

            var container = collisionRelationship.GetContainer();

            string secondType = null;

            isList = false;

            if (container != null)
            {
                var secondObject = container.GetNamedObject(secondName);

                isList = secondObject?.IsList == true;

                if (secondObject != null)
                {
                    if (secondObject.IsList)
                    {
                        secondType = secondObject.SourceClassGenericType?.Replace("\\", ".");
                    }
                    else
                    {
                        secondType = NamedObjectSaveCodeGenerator.GetQualifiedTypeName(secondObject);
                    }
                }
            }

            return(secondType);
        }
Beispiel #2
0
        private static ICodeBlock SetInterpolateBetweenValuesForStates(IElement element, string enumType, List <StateSave> states, ICodeBlock curBlock, Dictionary <InstructionSave, InterpolationCharacteristic> mInterpolationCharacteristics, string firstOrSecondValue)
        {
            foreach (StateSave state in states)
            {
                curBlock = curBlock.Case(enumType + "." + state.Name);

                foreach (InstructionSave instructionSave in state.InstructionSaves)
                {
                    var customVariable = element.GetCustomVariable(instructionSave.Member);

                    NamedObjectSave sourceNamedObjectSave = null;
                    if (customVariable != null)
                    {
                        sourceNamedObjectSave = element.GetNamedObjectRecursively(customVariable.SourceObject);
                    }

                    if (sourceNamedObjectSave != null)
                    {
                        NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(curBlock, sourceNamedObjectSave);
                    }

                    if (GetValue(mInterpolationCharacteristics, instructionSave.Member) != InterpolationCharacteristic.CantInterpolate)
                    {
                        if (instructionSave.Value == null)
                        {
                            curBlock.Line("set" + instructionSave.Member + " = false;");
                        }
                        else
                        {
                            string valueToWrite = GetRightSideAssignmentValueAsString(element, instructionSave);

                            curBlock.Line(instructionSave.Member + firstOrSecondValue + " = " + valueToWrite + ";");
                        }
                    }
                    else // This value can't be interpolated, but if the user has set a value of 0 or 1, then it should be set
                    {
                        ICodeBlock ifBlock;
                        //  value will come from the first state unless the interpolationValue is 1.
                        // This makes the code behave the same as InterpolateTo which uses instructions.
                        if (firstOrSecondValue == FirstValue)
                        {
                            ifBlock = curBlock.If("interpolationValue < 1");
                        }
                        else
                        {
                            ifBlock = curBlock.If("interpolationValue >= 1");
                        }
                        string valueToWrite = GetRightSideAssignmentValueAsString(element, instructionSave);
                        ifBlock.Line("this." + instructionSave.Member + " = " + valueToWrite + ";");
                    }
                    if (sourceNamedObjectSave != null)
                    {
                        NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(curBlock, sourceNamedObjectSave);
                    }
                }
                curBlock = curBlock.End();
            }
            return(curBlock);
        }
Beispiel #3
0
        private static ICodeBlock AssignValuesUsingStartingValues(IElement element, ICodeBlock curBlock, Dictionary <InstructionSave, InterpolationCharacteristic> mInterpolationCharacteristics)
        {
            foreach (KeyValuePair <InstructionSave, InterpolationCharacteristic> kvp in mInterpolationCharacteristics)
            {
                if (kvp.Value != InterpolationCharacteristic.CantInterpolate)
                {
                    curBlock = curBlock.If("set" + kvp.Key.Member);

                    CustomVariable variable = element.GetCustomVariable(kvp.Key.Member);
                    var            nos      = element.GetNamedObjectRecursively(variable.SourceObject);

                    if (nos != null)
                    {
                        NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(curBlock, nos);
                    }

                    string relativeValue = InstructionManager.GetRelativeForAbsolute(kvp.Key.Member);

                    string variableToAssign = kvp.Key.Member;


                    string leftSideOfEqualsWithRelative = GetLeftSideOfEquals(element, variable, kvp.Key, true);

                    if (!string.IsNullOrEmpty(leftSideOfEqualsWithRelative) && leftSideOfEqualsWithRelative != kvp.Key.Member)
                    {
                        string beforeDotParent = variable.SourceObject;

                        if (string.IsNullOrEmpty(variable.SourceObject))
                        {
                            beforeDotParent = "this";
                        }

                        curBlock = curBlock.If(beforeDotParent + ".Parent != null");



                        AddAssignmentForInterpolationForVariable(curBlock, variable, variableToAssign, leftSideOfEqualsWithRelative);
                        curBlock = curBlock.End().Else();
                    }

                    AddAssignmentForInterpolationForVariable(curBlock, variable, variableToAssign, variableToAssign);

                    if (!string.IsNullOrEmpty(relativeValue))
                    {
                        curBlock = curBlock.End(); // end the else
                    }

                    curBlock = curBlock.End();
                    if (nos != null)
                    {
                        NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(curBlock, nos);
                    }
                }
            }
            return(curBlock);
        }
        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);
        }
Beispiel #5
0
        public static void WriteSetStateOnNamedObject(NamedObjectSave namedObject, ICodeBlock codeBlock)
        {
            if (!string.IsNullOrEmpty(namedObject.CurrentState))
            {
                IElement referencedElement = namedObject.GetReferencedElement();
                if (referencedElement != null && referencedElement.GetUncategorizedStatesRecursively().Count != 0)
                {
                    string qualifiedName = NamedObjectSaveCodeGenerator.GetQualifiedTypeName(namedObject);

                    string lineToAdd = namedObject.FieldName + ".CurrentState = " + qualifiedName + ".VariableState." + namedObject.CurrentState + ";";
                    codeBlock.Line(lineToAdd);
                }
            }
        }
Beispiel #6
0
        private static ICodeBlock GenerateInterpolateForIndividualState(IElement element, ICodeBlock codeBlock, ICodeBlock otherBlock, StateSave stateSave, string enumType)
        {
            codeBlock  = codeBlock.Case(enumType + "." + stateSave.Name);
            otherBlock = otherBlock.Case(enumType + "." + stateSave.Name);

            foreach (InstructionSave instruction in stateSave.InstructionSaves)
            {
                CustomVariable customVariable = null;
                customVariable = element.GetCustomVariable(instruction.Member);

                string valueAsString = CodeParser.ParseObjectValue(instruction.Value);

                if (customVariable != null && !string.IsNullOrEmpty(valueAsString))
                {
                    NamedObjectSave sourceNamedObjectSave = element.GetNamedObjectRecursively(customVariable.SourceObject);

                    if (sourceNamedObjectSave == null || sourceNamedObjectSave.IsDisabled == false)
                    {
                        if (sourceNamedObjectSave != null)
                        {
                            NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, sourceNamedObjectSave);
                            NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(otherBlock, sourceNamedObjectSave);
                        }
                        string timeCastString = "";

                        if (instruction.Value is float)
                        {
                            timeCastString = "(float)";
                        }

                        if (string.IsNullOrEmpty(customVariable.SourceObject))
                        {
                            GenerateInterpolateForIndividualStateNoSource(ref codeBlock, element, ref otherBlock, instruction, customVariable, valueAsString, timeCastString);
                        }
                        else
                        {
                            GenerateInterpolateForIndividualStateWithSource(ref codeBlock, element, ref otherBlock, customVariable, valueAsString, sourceNamedObjectSave, timeCastString);
                        }
                        if (sourceNamedObjectSave != null)
                        {
                            NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, sourceNamedObjectSave);
                            NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(otherBlock, sourceNamedObjectSave);
                        }
                    }
                }
            }

            return(codeBlock);
        }
        public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
        {
            //////////////////////////EARLY OUT//////////////////////////////////////
            if (element is ScreenSave)
            {
                return(codeBlock);
            }
            ///////////////////////END EARLY OUT/////////////////////////////////////

            codeBlock = codeBlock.Function("public void", "MoveToLayer", "Layer layerToMoveTo");

            foreach (NamedObjectSave nos in element.NamedObjects)
            {
                if (!nos.IsDisabled)
                {
                    if (nos.GetAssetTypeInfo() != null && !string.IsNullOrEmpty(nos.GetAssetTypeInfo().RemoveFromLayerMethod))
                    {
                        NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
                        bool shouldSkip = GetShouldSkip(nos);

                        if (!shouldSkip)
                        {
                            codeBlock.If("LayerProvidedByContainer != null")
                            .Line(nos.GetAssetTypeInfo().RemoveFromLayerMethod.Replace("this", nos.InstanceName).Replace("mLayer", "LayerProvidedByContainer") + ";")
                            .End();

                            codeBlock.Line(nos.GetAssetTypeInfo().LayeredAddToManagersMethod[0].Replace("this", nos.InstanceName).Replace("mLayer", "layerToMoveTo") + ";");
                        }
                        NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);
                    }
                    else if (nos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(nos.SourceClassType))
                    {
                        NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
                        codeBlock.Line(nos.InstanceName + ".MoveToLayer(layerToMoveTo);");
                        NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);
                    }
                }
            }

            codeBlock.Line("LayerProvidedByContainer = layerToMoveTo;");

            codeBlock = codeBlock.End();

            return(codeBlock);
        }
Beispiel #8
0
        public override ICodeBlock GenerateActivity(ICodeBlock codeBlock, IElement element)
        {
            if (element is EntitySave)
            {
                EntitySave entitySave = (EntitySave)element;
                if (entitySave.IsScrollableEntityList && !string.IsNullOrEmpty(entitySave.ItemType))
                {
                    codeBlock.Line("ScrollableListActivity();");

                    mListNamedObjectSave.SourceType             = SourceType.FlatRedBallType;
                    mListNamedObjectSave.SourceClassType        = "PositionedObjectList<>";
                    mListNamedObjectSave.SourceClassGenericType = entitySave.ItemType;

                    mListNamedObjectSave.InstanceName = "mScrollableItems";

                    NamedObjectSaveCodeGenerator.GetActivityForNamedObject(mListNamedObjectSave, codeBlock);
                }
            }

            return(codeBlock);
        }
Beispiel #9
0
        public override ICodeBlock GenerateAddToManagers(ICodeBlock codeBlock, IElement element)
        {
            if (ShouldGenerate)
            {
                bool wasAnythingMovedToALayer = false;
                // todo:  Need to register the layer here
                foreach (var item in element.AllNamedObjects.Where(item =>
                                                                   GumPluginCodeGenerator.IsGue(item) &&
                                                                   !string.IsNullOrEmpty(item.LayerOn) &&
                                                                   NamedObjectSaveCodeGenerator.GetFieldCodeGenerationType(item) == CodeGenerationType.Full))
                {
                    string frbLayerName = item.LayerOn;
                    string gumLayerName = $"{item.LayerOn}Gum";

                    if (item.LayerOn == AvailableLayersTypeConverter.UnderEverythingLayerName)
                    {
                        frbLayerName = AvailableLayersTypeConverter.UnderEverythingLayerCode;
                        gumLayerName = UnderEverythingLayerGumName;
                    }

                    if (item.LayerOn == AvailableLayersTypeConverter.TopLayerName)
                    {
                        frbLayerName = AvailableLayersTypeConverter.TopLayerName;
                        gumLayerName = TopLayerGumName;
                    }

                    codeBlock.Line($"{item.FieldName}.MoveToFrbLayer({frbLayerName}, {gumLayerName});");
                    wasAnythingMovedToALayer = true;
                }

                if (wasAnythingMovedToALayer && element is FlatRedBall.Glue.SaveClasses.ScreenSave)
                {
                    codeBlock.Line("FlatRedBall.Gui.GuiManager.SortZAndLayerBased();");
                }
            }
            return(base.GenerateAddToManagers(codeBlock, element));
        }
Beispiel #10
0
        private static void GenerateInitializeForEvent(ICodeBlock codeBlock, IElement element, EventResponseSave ers)
        {
            bool wasEventAdded = false;

            //We always want this to happen, even if it's
            // emtpy
            //if (!string.IsNullOrEmpty(ers.Contents))
            //{
            NamedObjectSave sourceNos = null;
            bool            shouldCloseIfStatementForNos = false;

            if (!string.IsNullOrEmpty(ers.SourceVariable))
            {
                // This is tied to a variable, so the name comes from the variable event rather than the
                // event name itself
                string eventName = ers.BeforeOrAfter.ToString() + ers.SourceVariable + "Set";
                codeBlock.Line("this." + eventName + " += On" + ers.EventName + ";");
                wasEventAdded = true;
            }

            else if (string.IsNullOrEmpty(ers.SourceObject) || ers.SourceObject == "<NONE>")
            {
                string    leftSide  = null;
                EventSave eventSave = ers.GetEventSave();
                if (eventSave == null || string.IsNullOrEmpty(eventSave.ExternalEvent))
                {
                    leftSide = "this." + ers.EventName;
                }
                else
                {
                    leftSide = eventSave.ExternalEvent;
                }



                codeBlock.Line(leftSide + " += On" + ers.EventName + ";");
                wasEventAdded = true;
            }
            else if (!string.IsNullOrEmpty(ers.SourceObjectEvent))
            {
                // Only append this if the source NOS is fully-defined.  If not, we don't want to generate compile errors.
                sourceNos = element.GetNamedObject(ers.SourceObject);

                if (sourceNos != null && sourceNos.IsFullyDefined)
                {
                    NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, sourceNos);

                    string leftSide = null;

                    leftSide = ers.SourceObject + "." + ers.SourceObjectEvent;

                    codeBlock.Line(leftSide + " += On" + ers.EventName + ";");
                    wasEventAdded = true;
                    shouldCloseIfStatementForNos = true;
                }
            }

            if (!string.IsNullOrEmpty(ers.SourceObject) && !string.IsNullOrEmpty(ers.SourceObjectEvent) && wasEventAdded)
            {
                codeBlock.Line(ers.SourceObject + "." + ers.SourceObjectEvent + " += On" + ers.EventName + "Tunnel;");
                if (shouldCloseIfStatementForNos)
                {
                    NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, sourceNos);
                }
            }
        }
 IEnumerable <NamedObjectSave> GetObjectsForGumLayers(IElement element)
 {
     return(element.AllNamedObjects.Where(item => item.IsLayer &&
                                          NamedObjectSaveCodeGenerator.GetFieldCodeGenerationType(item) == CodeGenerationType.Full));
 }
        public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
        {
            //////////////////////////EARLY OUT//////////////////////////////////////
            if (element is ScreenSave)
            {
                return(codeBlock);
            }
            ///////////////////////END EARLY OUT/////////////////////////////////////

            bool isInDerived = element.InheritsFromElement();

            if (isInDerived)
            {
                codeBlock = codeBlock.Function("public override void", "MoveToLayer", "FlatRedBall.Graphics.Layer layerToMoveTo");
                codeBlock.Line("var layerToRemoveFrom = LayerProvidedByContainer; // assign before calling base so removal is not impacted by base call");
                codeBlock.Line("base.MoveToLayer(layerToMoveTo);");
            }
            else
            {
                codeBlock = codeBlock.Function("public virtual void", "MoveToLayer", "FlatRedBall.Graphics.Layer layerToMoveTo");
                codeBlock.Line("var layerToRemoveFrom = LayerProvidedByContainer;");
            }


            if (element.InheritsFromFrbType())
            {
                AssetTypeInfo ati = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(element.BaseElement, element);

                if (ati != null)
                {
                    if (ati.RemoveFromLayerMethod != null)
                    {
                        codeBlock.If("layerToRemoveFrom != null")
                        .Line(ati.RemoveFromLayerMethod.Replace("mLayer", "layerToRemoveFrom") + ";")
                        .End();
                    }

                    if (ati.LayeredAddToManagersMethod.Count != 0)
                    {
                        codeBlock.Line(ati.LayeredAddToManagersMethod[0].Replace("mLayer", "layerToMoveTo") + ";");
                    }
                }
            }


            foreach (NamedObjectSave nos in element.NamedObjects)
            {
                if (!nos.IsDisabled && !nos.IsContainer && !nos.DefinedByBase)
                {
                    bool shouldCheckForNull = nos.Instantiate == false;



                    if (nos.GetAssetTypeInfo() != null && !string.IsNullOrEmpty(nos.GetAssetTypeInfo().RemoveFromLayerMethod))
                    {
                        NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
                        bool shouldSkip = GetShouldSkip(nos);

                        if (!shouldSkip)
                        {
                            if (shouldCheckForNull)
                            {
                                codeBlock = codeBlock.If(nos.InstanceName + " != null");
                            }
                            codeBlock.If("layerToRemoveFrom != null")
                            .Line(nos.GetAssetTypeInfo().RemoveFromLayerMethod.Replace("this", nos.InstanceName).Replace("mLayer", "layerToRemoveFrom") + ";")
                            .End();

                            codeBlock.Line(nos.GetAssetTypeInfo().LayeredAddToManagersMethod[0].Replace("this", nos.InstanceName).Replace("mLayer", "layerToMoveTo") + ";");

                            if (shouldCheckForNull)
                            {
                                codeBlock = codeBlock.End();
                            }
                        }
                        NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);
                    }
                    else if (nos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(nos.SourceClassType))
                    {
                        if (shouldCheckForNull)
                        {
                            codeBlock = codeBlock.If(nos.InstanceName + " != null");
                        }
                        NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
                        codeBlock.Line(nos.InstanceName + ".MoveToLayer(layerToMoveTo);");
                        NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);


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

            if (isInDerived == false)
            {
                // Doesn't hurt if derived assigns this but...I guess we can keep it clean and only do it in one place
                codeBlock.Line("LayerProvidedByContainer = layerToMoveTo;");
            }

            codeBlock = codeBlock.End();

            return(codeBlock);
        }
        // We need to make this be part of the function so that we can have everything be async
        //static List<string> mUsingStrings = new List<string>();
        internal static void GenerateUsingStatements(ICodeBlock codeBlock, IElement SaveObject)
        {
            List <string> usingStrings = new List <string>();

            if (SaveObject is EntitySave)
            {
                EntitySave asEntitySave = (EntitySave)SaveObject;

                // I don't think we need this anymore
                //mUsingStrings.Add("Matrix = Microsoft.Xna.Framework.Matrix");


                // Since Entities inherit are IDestroyable
                usingStrings.Add("FlatRedBall.Graphics");
                // And since we want a Visible property, we'll have extension methods for Lists of this
                usingStrings.Add("FlatRedBall.Math");

                if (asEntitySave.ImplementsIClickable || asEntitySave.ImplementsIWindow)
                {
                    usingStrings.Add("FlatRedBall.Gui");
                }
            }

            // We are phasing this out:
            //mUsingStrings.Add("FlatRedBall.Broadcasting");


            usingStrings.Add("FlatRedBall");

            usingStrings.Add("System");
            usingStrings.Add("System.Collections.Generic");
            usingStrings.Add("System.Text");

            bool shouldAddUsingForDataTypes = false;

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

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

            NamedObjectSaveCodeGenerator.AddUsingsForNamedObjects(usingStrings, SaveObject);

            if (ObjectFinder.Self.GlueProject.UsesTranslation)
            {
                usingStrings.Add("FlatRedBall.Localization");
            }

            // Plugins don't generate using statements.
            // This is intentional so we don't get naming conflicts

            // Remove duplicates
            StringFunctions.RemoveDuplicates(usingStrings);

            foreach (string s in usingStrings.Distinct())
            {
                codeBlock.Line("using " + s + ";");
            }
        }
Beispiel #14
0
        private static ICodeBlock GenerateVariableAssignmentForState(IElement element, ICodeBlock codeBlock, StateSave stateSave, string enumType, bool isElse)
        {
            string variableNameModifier = enumType;

            if (enumType == "VariableState")
            {
                variableNameModifier = "";
            }

            ICodeBlock curBlock;

            if (isElse)
            {
                curBlock = codeBlock.ElseIf($"Current{variableNameModifier}State == {enumType}.{stateSave.Name}");
            }
            else
            {
                curBlock = codeBlock.If($"Current{variableNameModifier}State == {enumType}.{stateSave.Name}");
            }
            bool doesStateAssignAbsoluteValues = GetDoesStateAssignAbsoluteValues(stateSave, element);

            foreach (InstructionSave instruction in stateSave.InstructionSaves)
            {
                if (instruction.Value != null)
                {
                    // Get the valueAsString, which is the right-side of the equals sign
                    string rightSideOfEquals = GetRightSideAssignmentValueAsString(element, instruction);

                    if (!string.IsNullOrEmpty(rightSideOfEquals))
                    {
                        CustomVariable  customVariable = element.GetCustomVariableRecursively(instruction.Member);
                        NamedObjectSave referencedNos  = element.GetNamedObjectRecursively(customVariable.SourceObject);

                        if (referencedNos != null)
                        {
                            NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(curBlock, referencedNos);
                        }

                        string leftSideOfEquals             = GetLeftSideOfEquals(element, customVariable, instruction, false);
                        string leftSideOfEqualsWithRelative = GetLeftSideOfEquals(element, customVariable, instruction, true);



                        if (leftSideOfEquals != leftSideOfEqualsWithRelative)
                        {
                            string objectWithParent = null;

                            if (string.IsNullOrEmpty(customVariable.SourceObject))
                            {
                                objectWithParent = "this";
                            }
                            else
                            {
                                objectWithParent = customVariable.SourceObject;
                            }

                            curBlock
                            .If(objectWithParent + ".Parent == null")
                            .Line(leftSideOfEquals + " = " + rightSideOfEquals + ";")
                            .End()

                            .Else()
                            .Line(leftSideOfEqualsWithRelative + " = " + rightSideOfEquals + ";");
                        }
                        else
                        {
                            curBlock.Line(leftSideOfEquals + " = " + rightSideOfEquals + ";");
                        }

                        if (referencedNos != null)
                        {
                            NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(curBlock, referencedNos);
                        }
                    }
                }
            }

            return(codeBlock);
        }
        // We need to make this be part of the function so that we can have everything be async
        //static List<string> mUsingStrings = new List<string>();
        internal static void GenerateUsingStatements(ICodeBlock codeBlock, IElement SaveObject)
        {
            List <string> usingStrings = new List <string>();

            if (SaveObject is EntitySave)
            {
                EntitySave asEntitySave = (EntitySave)SaveObject;

                bool hasScreensInProject = ProjectManager.GlueProjectSave.Screens.Count != 0;
                if (hasScreensInProject)
                {
                    usingStrings.Add(ProjectManager.ProjectNamespace + ".Screens");
                }

                // I don't think we need this anymore
                //mUsingStrings.Add("Matrix = Microsoft.Xna.Framework.Matrix");


                // Since Entities inherit are IDestroyable
                usingStrings.Add("FlatRedBall.Graphics");
                // And since we want a Visible property, we'll have extension methods for Lists of this
                usingStrings.Add("FlatRedBall.Math");


                if (asEntitySave.CreatedByOtherEntities)
                {
                    usingStrings.Add(ProjectManager.ProjectNamespace + ".Performance");
                }

                if (asEntitySave.ImplementsIClickable || asEntitySave.ImplementsIWindow)
                {
                    usingStrings.Add("FlatRedBall.Gui");
                }
            }

            // We are phasing this out:
            //mUsingStrings.Add("FlatRedBall.Broadcasting");



            #region Add the using PROJECT.Factories if necessary
            if (ProjectManager.GlueProjectSave.Entities.Count != 0)
            {
                // add their usings
                for (int i = 0; i < ProjectManager.GlueProjectSave.Entities.Count; i++)
                {
                    EntitySave entitySave = ProjectManager.GlueProjectSave.Entities[i];

                    string entityNamespace = FileManager.MakeRelative(FileManager.GetDirectory(entitySave.Name)).Replace('/', '.');
                    entityNamespace = ProjectManager.ProjectNamespace + "." + entityNamespace.Substring(0, entityNamespace.Length - 1);

                    if (!usingStrings.Contains(entityNamespace))
                    {
                        usingStrings.Add(entityNamespace);
                    }
                }



                for (int i = 0; i < ProjectManager.GlueProjectSave.Entities.Count; i++)
                {
                    if (ProjectManager.GlueProjectSave.Entities[i].CreatedByOtherEntities)
                    {
                        usingStrings.Add(ProjectManager.ProjectNamespace + ".Factories");
                        break;
                    }
                }
            }

            #endregion

            usingStrings.Add("FlatRedBall");
            usingStrings.Add("FlatRedBall.Screens");

            usingStrings.Add("System");
            usingStrings.Add("System.Collections.Generic");
            usingStrings.Add("System.Text");

            bool shouldAddUsingForDataTypes = false;

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

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

            NamedObjectSaveCodeGenerator.AddUsingsForNamedObjects(usingStrings, SaveObject);

            if (ObjectFinder.Self.GlueProject.UsesTranslation)
            {
                usingStrings.Add("FlatRedBall.Localization");
            }

            // Plugins don't generate using statements.
            // This is intentional so we don't get naming conflicts

            // Remove duplicates
            StringFunctions.RemoveDuplicates(usingStrings);

            foreach (string s in usingStrings.Distinct())
            {
                codeBlock.Line("using " + s + ";");
            }
        }