Example #1
0
        private void AddReferencedFilesToElement(GumElement from, GlueElement to, Dictionary <string, CopiedFileReference> copiedFiles)
        {
            string gumDirectory     = FileManager.GetDirectory(mGumProjectSave.FullFileName);
            string contentDirectory = GetContentFolder();

            foreach (GumStateSave stateSave in from.States)
            {
                foreach (VariableSave variable in stateSave.Variables.Where(item => item.IsFile && item.Value != null && item.SetsValue))
                {
                    string sourceFile = (string)variable.Value;

                    string absoluteFile = FileManager.RemoveDotDotSlash(gumDirectory + sourceFile).ToLower();

                    if (copiedFiles.ContainsKey(absoluteFile))
                    {
                        string destination = copiedFiles[absoluteFile].Destination;
                        string rfsName     = FileManager.MakeRelative(destination, contentDirectory);
                        if (!to.ReferencedFiles.Any(item => item.Name == rfsName))
                        {
                            // create a RFS here
                            ReferencedFileSave rfs = new ReferencedFileSave();
                            rfs.Name        = rfsName;
                            rfs.RuntimeType = "Microsoft.Xna.Framework.Graphics.Texture2D";
                            to.ReferencedFiles.Add(rfs);
                        }
                    }
                }
            }
        }
Example #2
0
        private string GetFileContentsFor(GlueElement glueElement)
        {
            var glueProject     = GluePluginState.Self.GlueProject;
            var projectFileName = GluePluginState.Self.GlueProjectFilePath;

            string screensOrEntities = glueElement is ScreenSave ? "Screens" : "Entities";

            // Assume it's the same as the project name. Glue
            // uses the namespace in the .csproj which is more
            // accurate, but we don't (currently) have the csproj
            // loaded.
            // Does not support subfolders (yet)
            string entityNamespace = $"{GluePluginState.Self.ProjectRootNamespace}.{screensOrEntities}";

            string className = new FilePath(glueElement.Name).CaseSensitiveNoPathNoExtension;

            string fileContents = null;

            if (glueElement is FlatRedBall.Glue.SaveClasses.ScreenSave)
            {
                fileContents = string.Format(screenFileContentsToFormat, entityNamespace, className);
            }
            else
            {
                fileContents = string.Format(entityFileContentsToFormat, entityNamespace, className);
            }

            return(fileContents);
        }
Example #3
0
        private void AddInstances(GlueElement glueElement, ElementSave gumElement)
        {
            foreach (var namedObject in glueElement.NamedObjects)
            {
                var instance = ToInstanceSave(namedObject);

                List <VariableSave>     variableList     = null;
                List <VariableListSave> variableListList = null;
                GetVariableSaves(namedObject, null, glueElement, out variableList, out variableListList);
                gumElement.DefaultState.Variables.AddRange(variableList);
                gumElement.DefaultState.VariableLists.AddRange(variableListList);

                gumElement.Instances.Add(instance);

                // Do we want to "trust" the .glux?
                // ShapeCollection instances can now
                // contain shapes, so this if-check is
                // wrong. I could add an explicit check
                // for list or ShapeCollection, but maybe
                // I'll just comment out the if-check for now.
                //if (namedObject.IsList)
                {
                    foreach (var containedObject in namedObject.ContainedObjects)
                    {
                        var containedInstance = ToInstanceSave(containedObject);
                        gumElement.Instances.Add(containedInstance);
                        List <VariableSave>     containedVariableList;
                        List <VariableListSave> containedVariableListList;
                        GetVariableSaves(containedObject, namedObject, glueElement, out containedVariableList, out containedVariableListList);
                        gumElement.DefaultState.Variables.AddRange(containedVariableList);
                    }
                }
            }
        }
Example #4
0
 static void OnElementRemoved(FlatRedBall.Glue.SaveClasses.IElement obj)
 {
     if (obj != null)
     {
         PluginManager.BeforeElementRemoved();
         GlueViewState.Self.CurrentElement = null;
     }
 }
Example #5
0
 private void ApplyVariableGroups(VariableGroupDictionary variableGroups, GlueElement glueElement,
                                  List <VariableSave> gumVariables)
 {
     if (variableGroups.HasCategory(GlueToGumTextureCoordinateConversionLogic.TextureCoordinatesCategory))
     {
         GlueToGumTextureCoordinateConversionLogic.Self.ApplyTextureCoordinatesVariables(variableGroups, gumVariables, glueElement);
     }
 }
        /// <summary>
        /// Gets associated EventSave that comes from BuiltInEvents.csv.  This may be null
        /// if the EventResponseSave is an event responding to a changed variable.
        /// </summary>
        public static EventSave GetEventSave(this EventResponseSave instance)
        {
            EventSave toReturn = null;

            string key = "";

            if (!string.IsNullOrEmpty(instance.SourceObject) && !string.IsNullOrEmpty(instance.SourceObjectEvent))
            {
                key = instance.SourceObjectEvent;

                IElement container = ObjectFinder.Self.GetElementContaining(instance);

                if (container != null)
                {
                    NamedObjectSave nos = container.GetNamedObjectRecursively(instance.SourceObject);
#if GLUE
                    string type;
                    string args;

                    FlatRedBall.Glue.Plugins.PluginManager.GetEventSignatureArgs(nos, instance, out type, out args);
                    if (type != null)
                    {
                        toReturn              = new EventSave();
                        toReturn.Arguments    = args;
                        toReturn.DelegateType = type;
                    }
#endif
                    if (toReturn == null && nos != null && nos.SourceType == SourceType.Entity)
                    {
                        // This may be a tunnel into a tunneled event
                        FlatRedBall.Glue.SaveClasses.IElement element = ObjectFinder.Self.GetIElement(nos.SourceClassType);

                        if (element != null)
                        {
                            foreach (EventResponseSave ers in element.Events)
                            {
                                if (ers.EventName == instance.SourceObjectEvent)
                                {
                                    toReturn = ers.GetEventSave();
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                key = instance.EventName;
            }

            if (toReturn == null && EventManager.AllEvents.ContainsKey(key))
            {
                toReturn = EventManager.AllEvents[key];
            }

            return(toReturn);
        }
Example #7
0
 public override ICodeBlock GenerateAddToManagers(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
 {
     //foreach (var namedObject in element.AllNamedObjects.Where(item => IsGue(item)))
     //{
     //    //FlatRedBall.Gui.GuiManager.AddWindow(mNarrowButtonIWindow);
     //    codeBlock.Line("FlatRedBall.Gui.GuiManager.AddWindow(" + GetWrapperNameFor(namedObject) + ");");
     //}
     return(base.GenerateAddToManagers(codeBlock, element));
 }
Example #8
0
 static void OnElementRemoved(FlatRedBall.Glue.SaveClasses.IElement obj)
 {
     if (obj != null)
     {
         glueViewSettings.SetElementCameraSave(obj, SpriteManager.Camera);
         glueViewSettings.Save(SettingsSaveFileName);
         GlueViewState.Self.CurrentElement = null;
     }
 }
Example #9
0
        public override ICodeBlock GenerateFields(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
        {
            //foreach (var namedObject in element.AllNamedObjects.Where(item => IsGue(item) &&
            //    NamedObjectSaveCodeGenerator.GetFieldCodeGenerationType(item) == CodeGenerationType.Full))
            //{
            //    codeBlock.Line("FlatRedBall.Gum.GueIWindowWrapper " + GetWrapperNameFor(namedObject) + ";");
            //}

            return(codeBlock);
        }
 public override ICodeBlock GenerateActivity(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
 {
     if (element.SupportsAdvancedInterpolation())
     {
         foreach (var enumName in element.GetStateEnumNames())
         {
             codeBlock.Line(TweenerNameFor(enumName) + ".Update(FlatRedBall.TimeManager.SecondDifference);");
         }
     }
     return(codeBlock);
 }
 public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
 {
     if (element.SupportsAdvancedInterpolation())
     {
         foreach (var enumName in element.GetStateEnumNames())
         {
             codeBlock = GenerateInterpolateToStateAdvanced(codeBlock, enumName);
         }
     }
     return(codeBlock);
 }
        public override ICodeBlock GenerateFields(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
        {
            if (element.SupportsAdvancedInterpolation())
            {
                foreach (var enumName in element.GetStateEnumNames())
                {
                    codeBlock.Line("FlatRedBall.Glue.StateInterpolation.Tweener " + TweenerNameFor(enumName) + ";");
                    codeBlock.Line(enumName + " mFrom" + enumName + "Tween;");
                    codeBlock.Line(enumName + " mTo" + enumName + "Tween;");
                }
            }

            return(codeBlock);
        }
Example #13
0
        static void BeforeElementLoaded(FlatRedBall.Glue.SaveClasses.IElement obj)
        {
            // I think we need to set this *before* plugins react to it, no?
            GlueViewState.Self.CurrentElement = obj;


            // We used to set this *after* the Camera settings
            // but I think we want to do it before so that camera
            // settings can be saved.
            PluginManager.ReactToElementLoad();

            // This used to set the camera explicitly here, but we have a camera controller that does that for
            // us now, so we can get rid of it here:
        }
Example #14
0
        public override ICodeBlock GenerateInitialize(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
        {
            //foreach(var namedObject in element.AllNamedObjects.Where(item=> IsGue(item) &&
            //    NamedObjectSaveCodeGenerator.GetInitializeCodeGenerationType(item, element) == CodeGenerationType.Full))
            //{
            //    string name = GetWrapperNameFor(namedObject);
            //    codeBlock.Line( name + " = new FlatRedBall.Gum.GueIWindowWrapper();");
            //    //mNarrowButtonIWindow.GraphicalUiElement = NarrowButton;
            //    codeBlock.Line(name + ".GraphicalUiElement = " + namedObject.InstanceName + ";");

            //}


            return(codeBlock);
        }
Example #15
0
        private void AddStates(GlueElement glueElement, GumElement gumElement)
        {
            foreach (var glueState in glueElement.States)
            {
                var gumState = ToGumState(glueState, glueElement);

                gumElement.States.Add(gumState);
            }

            foreach (var glueStateCategory in glueElement.StateCategoryList)
            {
                var gumStateCategory = ToGumStateCategory(glueStateCategory, glueElement);

                gumElement.Categories.Add(gumStateCategory);
            }
        }
        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);
        }
Example #17
0
        public FilePath GetCustomCodeFileLocationFor(GlueElement glueElement, bool absolute = true)
        {
            var projectFileName = GluePluginState.Self.GlueProjectFilePath;

            string screensOrEntities = glueElement is ScreenSave ? "Screens" : "Entities";
            string className         = className = new FilePath(glueElement.Name).CaseSensitiveNoPathNoExtension;

            string customCodeLocation = null;

            customCodeLocation = $"{screensOrEntities}\\{className}.cs";

            if (absolute)
            {
                customCodeLocation = $"{projectFileName.GetDirectoryContainingThis()}{customCodeLocation}";
            }

            return(customCodeLocation);
        }
Example #18
0
        public void TrySaveCustomCodeFileFor(GlueElement glueElement)
        {
            var glueProject = GluePluginState.Self.GlueProject;

            ///////////////////////Early Out///////////////////////
            if (glueProject == null || GluePluginState.Self.InitializationState != InitializationState.Initialized)
            {
                return;
            }
            ////////////////////End Early Out/////////////////////

            var location = GetCustomCodeFileLocationFor(glueElement);

            // if it already exists, don't overwrite it:
            if (location.Exists() == false)
            {
                var fileContents = GetFileContentsFor(glueElement);

                System.IO.File.WriteAllText(location.StandardizedCaseSensitive, fileContents);
            }

            // todo - do we have to add the file to the .csproj or will
            // Glue handle that for us?
        }
        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);
        }
Example #20
0
 public override ICodeBlock GenerateDestroy(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
 {
     return(base.GenerateDestroy(codeBlock, element));
 }
Example #21
0
 public override void GenerateRemoveFromManagers(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
 {
     base.GenerateRemoveFromManagers(codeBlock, element);
 }
Example #22
0
        private void AddGumVariables(InstructionSave glueVariable, NamedObjectSave namedObject,
                                     GlueElement glueElement,
                                     List <VariableSave> gumVariables,
                                     List <VariableListSave> gumVariableLists,
                                     VariableGroupDictionary variableGroups, bool isInState = false)
        {
            string glueVariableName = glueVariable.Member;

            if (isInState)
            {
                // It's a state variable so it references a different variable that we have to find:
                var variableOnElement = glueElement.GetCustomVariable(glueVariable.Member);

                if (variableOnElement != null)
                {
                    glueVariableName = variableOnElement.SourceObjectProperty;
                }


                if (!string.IsNullOrEmpty(variableOnElement.SourceObject))
                {
                    namedObject = glueElement.AllNamedObjects
                                  .FirstOrDefault(item => item.InstanceName == variableOnElement.SourceObject);
                }
            }

            // Let's be explicit instead of expecting the names to match up:
            switch (glueVariableName)
            {
            case "Height":
            {
                var variableSave = new VariableSave();
                variableSave.Name  = $"{namedObject.InstanceName}.Height";
                variableSave.Type  = "float";
                variableSave.Value = (float)glueVariable.Value;
                gumVariables.Add(variableSave);
            }
            break;

            case "Points":
            {
                var variableListSave = new VariableListSave <Vector2>();
                variableListSave.Name = $"{namedObject.InstanceName}.Points";

                var pointsPositiveYUp = glueVariable.Value as List <Vector2>;



                if (pointsPositiveYUp != null)
                {
                    foreach (var frbPoint in pointsPositiveYUp)
                    {
                        var newPoint = frbPoint;
                        newPoint.Y *= -1;

                        variableListSave.ValueAsIList.Add(newPoint);
                    }
                }
                gumVariableLists.Add(variableListSave);
            }
            break;

            case "Radius":
            {
                if (namedObject.SourceType == SourceType.FlatRedBallType && namedObject.SourceClassType == "Circle")
                {
                    var variableSave = new VariableSave();
                    variableSave.Name  = $"{namedObject.InstanceName}.Width";
                    variableSave.Type  = "float";
                    variableSave.Value = (float)glueVariable.Value * 2.0f;
                    variableSave.IsHiddenInPropertyGrid = true;
                    gumVariables.Add(variableSave);

                    variableSave       = new VariableSave();
                    variableSave.Name  = $"{namedObject.InstanceName}.Height";
                    variableSave.Type  = "float";
                    variableSave.Value = (float)glueVariable.Value * 2.0f;
                    variableSave.IsHiddenInPropertyGrid = true;
                    gumVariables.Add(variableSave);


                    variableSave       = new VariableSave();
                    variableSave.Name  = $"{namedObject.InstanceName}.Radius";
                    variableSave.Type  = "float";
                    variableSave.Value = (float)glueVariable.Value;
                    gumVariables.Add(variableSave);
                }
            }
            break;

            case "RotationZ":
            {
                var variableSave = new VariableSave();
                variableSave.Name = $"{namedObject.InstanceName}.Rotation";
                variableSave.Type = "float";
                var valueRadians = (float)glueVariable.Value;
                var degrees      = 360 * (valueRadians / (2 * Math.PI));
                variableSave.Value = (float)degrees;
                gumVariables.Add(variableSave);
            }

            break;

            case "RightTexturePixel":
            case "LeftTexturePixel":
            case "BottomTexturePixel":
            case "TopTexturePixel":
                variableGroups.AddVariable(glueVariable, namedObject,
                                           glueVariableName, GlueToGumTextureCoordinateConversionLogic.TextureCoordinatesCategory);
                break;

            case "Texture":
            {
                var variableSave = new VariableSave();
                variableSave.Name = $"{namedObject.InstanceName}.SourceFile";
                variableSave.Type = "string";

                //var referencedFileName = (string)glueVariable.Value;
                //var nos = glueElement.GetReferencedFileSave(referencedFileName);

                //if(nos == null)
                //{
                //    // todo - need to look in global content;
                //}

                // assume the content location is in a monogame DGL location, and the
                // file is a PNG. Eventually we can make this more intelligent
                var fileName = $"../Content/{glueElement.Name}/{(string)glueVariable.Value}.png";

                variableSave.Value  = fileName;
                variableSave.IsFile = true;
                gumVariables.Add(variableSave);

                variableGroups.AddVariable(glueVariable, namedObject, glueVariableName,
                                           GlueToGumTextureCoordinateConversionLogic.TextureCoordinatesCategory);
            }
            break;

            case "TextureScale":
            {
                var variableSave = new VariableSave();

                variableSave       = new VariableSave();
                variableSave.Name  = $"{namedObject.InstanceName}.Width";
                variableSave.Type  = "float";
                variableSave.Value = (float)glueVariable.Value * 100;
                gumVariables.Add(variableSave);


                variableSave       = new VariableSave();
                variableSave.Name  = $"{namedObject.InstanceName}.Height";
                variableSave.Type  = "float";
                variableSave.Value = (float)glueVariable.Value * 100;
                gumVariables.Add(variableSave);

                // todo width units?
            }
            break;

            case "X":
            {
                VariableSave variableSave = null;
                variableSave       = new VariableSave();
                variableSave.Type  = "float";
                variableSave.Name  = $"{namedObject.InstanceName}.X";
                variableSave.Value = (float)glueVariable.Value;
                gumVariables.Add(variableSave);
            }
            break;

            case "Width":
            {
                var variableSave = new VariableSave();
                variableSave.Name  = $"{namedObject.InstanceName}.Width";
                variableSave.Type  = "float";
                variableSave.Value = (float)glueVariable.Value;
                gumVariables.Add(variableSave);
            }
            break;

            case "Y":
            {
                var variableSave = new VariableSave();
                variableSave.Name  = $"{namedObject.InstanceName}.Y";
                variableSave.Type  = "float";
                variableSave.Value = (float)glueVariable.Value;
                gumVariables.Add(variableSave);
            }
            break;

            default:
                int m = 3;
                break;
            }
        }
Example #23
0
        private void GetVariableSaves(NamedObjectSave namedObject, NamedObjectSave parentNamedObject, GlueElement glueElement,
                                      out List <VariableSave> gumVariables, out List <VariableListSave> gumVariableLists)
        {
            VariableGroupDictionary variableGroups = new VariableGroupDictionary();

            gumVariables     = new List <VariableSave>();
            gumVariableLists = new List <VariableListSave>();
            foreach (var glueVariable in namedObject.InstructionSaves)
            {
                AddGumVariables(glueVariable, namedObject, glueElement, gumVariables, gumVariableLists, variableGroups);
            }

            ApplyVariableGroups(variableGroups, glueElement, gumVariables);

            if (namedObject.SourceType == SourceType.FlatRedBallType &&
                namedObject.SourceClassType == "PositionedObjectList<T>" &&
                namedObject.SourceClassGenericType != null)
            {
                AddVariablesForPositionedObjectList(namedObject, gumVariables);
            }

            if (namedObject.SourceType == SourceType.FlatRedBallType &&
                namedObject.SourceClassType == "ShapeCollection")
            {
                AddVariablesForShapeCollection(namedObject, gumVariables);
            }

            if (parentNamedObject != null)
            {
                var parentVariable = new VariableSave();
                parentVariable.Value     = parentNamedObject.InstanceName;
                parentVariable.SetsValue = true;
                parentVariable.Type      = "string";
                parentVariable.Name      = $"{namedObject.InstanceName}.Parent";
                gumVariables.Add(parentVariable);
            }


            // everything should set value
            foreach (var gumVariable in gumVariables)
            {
                gumVariable.SetsValue = true;
            }
        }
        private void AddReferencedFilesToElement(GumElement from, GlueElement to, Dictionary<string, CopiedFileReference> copiedFiles)
        {
            string gumDirectory = FileManager.GetDirectory(mGumProjectSave.FullFileName);
            string contentDirectory = GetContentFolder();
            foreach (GumStateSave stateSave in from.States)
            {

                foreach (VariableSave variable in stateSave.Variables.Where(item=>item.IsFile && item.Value != null && item.SetsValue))
                {
                    string sourceFile = (string)variable.Value;

                    string absoluteFile = FileManager.RemoveDotDotSlash(gumDirectory + sourceFile).ToLower();

                    if (copiedFiles.ContainsKey(absoluteFile))
                    {
                        string destination = copiedFiles[absoluteFile].Destination;
                        string rfsName = FileManager.MakeRelative(destination, contentDirectory);
                        if (!to.ReferencedFiles.Any(item => item.Name == rfsName))
                        {
                            // create a RFS here
                            ReferencedFileSave rfs = new ReferencedFileSave();
                            rfs.Name = rfsName;
                            rfs.RuntimeType = "Microsoft.Xna.Framework.Graphics.Texture2D";
                            to.ReferencedFiles.Add(rfs);
                        }
                    }
                }
            }

        }
Example #25
0
        private GumStateCategory ToGumStateCategory(GlueStateCategory glueStateCategory, GlueElement glueElement)
        {
            var gumStateCategory = new GumStateCategory();

            gumStateCategory.Name = glueStateCategory.Name;

            foreach (var glueState in glueStateCategory.States)
            {
                var gumState = ToGumState(glueState, glueElement);
                gumStateCategory.States.Add(gumState);
            }

            return(gumStateCategory);
        }
Example #26
0
        private GumState ToGumState(FlatRedBall.Glue.SaveClasses.StateSave glueState, GlueElement glueElement)
        {
            var gumState = new GumState();

            gumState.Name = glueState.Name;

            VariableGroupDictionary variableGroups = new VariableGroupDictionary();

            foreach (var glueVariable in glueState.InstructionSaves)
            {
                AddGumVariables(glueVariable, null, glueElement, gumState.Variables, gumState.VariableLists, variableGroups, isInState: true);
            }

            ApplyVariableGroups(variableGroups, glueElement, gumState.Variables);


            // everything should set value
            foreach (var gumVariable in gumState.Variables)
            {
                gumVariable.SetsValue = true;
            }


            return(gumState);
        }