Example #1
0
        private AssetTypeInfo CreateAtiForRawTmx()
        {
            AssetTypeInfo toReturn = CreateAtiForLayeredTilemapScnx();

            toReturn.VariableDefinitions.Add(new VariableDefinition
            {
                Name         = "X",
                Type         = "float",
                DefaultValue = "0",
                Category     = "Position"
            });

            toReturn.VariableDefinitions.Add(new VariableDefinition
            {
                Name         = "Y",
                Type         = "float",
                DefaultValue = "0",
                Category     = "Position"
            });

            toReturn.VariableDefinitions.Add(new VariableDefinition
            {
                Name         = "Z",
                Type         = "float",
                DefaultValue = "0",
                Category     = "Position"
            });

            toReturn.FriendlyName          = "LayeredTileMap (.tmx)";
            toReturn.QualifiedSaveTypeName = "";
            toReturn.Extension             = "tmx";
            toReturn.CustomLoadMethod      = "{THIS} = FlatRedBall.TileGraphics.LayeredTileMap.FromTiledMapSave(\"{FILE_NAME}\", {CONTENT_MANAGER_NAME});";

            return(toReturn);
        }
Example #2
0
        private AssetTypeInfo CreateAtiForLayeredTilemapScnx()
        {
            AssetTypeInfo toReturn = new AssetTypeInfo();

            toReturn.FriendlyName             = "LayeredTileMap (.scnx)";
            toReturn.QualifiedRuntimeTypeName = new PlatformSpecificType();
            toReturn.QualifiedRuntimeTypeName.QualifiedType = "FlatRedBall.TileGraphics.LayeredTileMap";
            toReturn.QualifiedSaveTypeName = "FlatRedBall.Content.SpriteEditorScene";
            toReturn.Extension             = "scnx";
            toReturn.AddToManagersMethod   = new List <string>();
            toReturn.AddToManagersMethod.Add("this.AddToManagers()");
            toReturn.LayeredAddToManagersMethod.Add("this.AddToManagers(mLayer)");
            toReturn.CustomLoadMethod = "{THIS} = FlatRedBall.TileGraphics.LayeredTileMap.FromScene(\"{FILE_NAME}\", {CONTENT_MANAGER_NAME});";
            toReturn.DestroyMethod    = "this.Destroy()";
            toReturn.ShouldBeDisposed = false;
            toReturn.ShouldAttach     = true;
            // I believe this means it will call Clone()
            toReturn.CanBeCloned = true;
            toReturn.MustBeAddedToContentPipeline = false;
            toReturn.HasCursorIsOn      = false;
            toReturn.HasVisibleProperty = false;
            toReturn.CanIgnorePausing   = false;
            toReturn.CanBeObject        = true;
            // We don't want this to show up as a file type - it's the same thing as a .scnx, and should only be used
            // from a TMX.
            toReturn.HideFromNewFileWindow = true;


            return(toReturn);
        }
Example #3
0
        private AssetTypeInfo CreateAtiForTileShapeCollection()
        {
            AssetTypeInfo toReturn = new AssetTypeInfo();

            toReturn.FriendlyName             = "TileShapeCollection";
            toReturn.QualifiedRuntimeTypeName = new PlatformSpecificType();
            toReturn.QualifiedRuntimeTypeName.QualifiedType = "FlatRedBall.TileCollisions.TileShapeCollection";
            toReturn.QualifiedSaveTypeName        = null;
            toReturn.Extension                    = null;
            toReturn.AddToManagersMethod          = new List <string>();
            toReturn.CustomLoadMethod             = null;
            toReturn.DestroyMethod                = "this.Visible = false";
            toReturn.ShouldBeDisposed             = false;
            toReturn.ShouldAttach                 = false;
            toReturn.MustBeAddedToContentPipeline = false;
            toReturn.CanBeCloned                  = false;
            toReturn.HasCursorIsOn                = false;
            toReturn.CanIgnorePausing             = false;
            toReturn.CanBeObject                  = true;
            toReturn.HasVisibleProperty           = true;
            toReturn.FindByNameSyntax             = $"Collisions.First(item => item.Name == \"OBJECTNAME\");";

            toReturn.GetObjectFromFileFunc = GetObjectFromFileFunc;
            toReturn.VariableDefinitions.Add(new VariableDefinition()
            {
                Name = "Visible", DefaultValue = "false", Type = "bool"
            });
            toReturn.ConstructorFunc = GenerateConstructionFunc;
            return(toReturn);
        }
        private void OptionsComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (mOptionsComboBox.SelectedItem != null && mOptionsComboBox.SelectedItem is AssetTypeInfo)
            {
                AssetTypeInfo ati = mOptionsComboBox.SelectedItem as AssetTypeInfo;

                string fileType = GetObjectTypeFromAti(ati);


                foreach (var option in mFileTypeOptions)
                {
                    if (option.ObjectType.Contains(fileType))
                    {
                        mDynamicUiHelper.Show(option.UiId);
                    }
                    else
                    {
                        mDynamicUiHelper.Hide(option.UiId);
                    }
                }
                if (mIsNameDefault)
                {
                    // We want to make sure we don't
                    // suggest a name that is already
                    // being used.
                    //textBox1.Text = fileType + "File";
                    textBox1.Text = StringFunctions.MakeStringUnique(fileType + "File", mNamesAlreadyUsed, 2);

                    while (ObjectFinder.Self.GetReferencedFileSaveFromFile(textBox1.Text + "." + ResultAssetTypeInfo.Extension) != null)
                    {
                        textBox1.Text = FlatRedBall.Utilities.StringFunctions.IncrementNumberAtEnd(textBox1.Text);
                    }
                }
            }
        }
Example #5
0
        private static string GetCreatedFileTarget(AssetTypeInfo assetTypeInfo, string directory, string name)
        {
            string createdFile = "";

            if (!directory.EndsWith("\\") && !directory.EndsWith("/"))
            {
                directory = directory + "/";
            }

            if (FileManager.IsRelative(directory))
            {
                createdFile = FileManager.RelativeDirectory + directory + name + "." + assetTypeInfo.Extension;

                if (ObjectFinder.Self.GlueProject != null)
                {
                    // I think we should always use the content directory whether we have a content project or not:
                    createdFile = ProjectManager.ContentDirectory + directory + name + "." + assetTypeInfo.Extension;
                }
            }
            else
            {
                createdFile = directory + name + "." + assetTypeInfo.Extension;
            }
            return(createdFile);
        }
Example #6
0
        private void AddRenderTargetAti()
        {
            AssetTypeInfo renderTargetAti = new AssetTypeInfo();

            // todo: need to make an explicit InstantiateOnAddToManagers bool for ATI, set to true for layers and this, instead of relying on "this = " in the AddToManagers call

            renderTargetAti.CanBeObject = true;
            renderTargetAti.QualifiedRuntimeTypeName = new PlatformSpecificType
            {
                QualifiedType = "Microsoft.Xna.Framework.Graphics.RenderTarget2D"
            };
            renderTargetAti.FriendlyName      = "RenderTarget";
            renderTargetAti.AddToManagersFunc = GetAddToManagersCodeForRenderTarget;
            renderTargetAti.ConstructorFunc   = GetConstructorFunc;

            renderTargetAti.VariableDefinitions.Add(new VariableDefinition
            {
                Name = "Width",
                Type = "int",
                UsesCustomCodeGeneration = true
            });


            renderTargetAti.VariableDefinitions.Add(new VariableDefinition
            {
                Name = "Height",
                Type = "int",
                UsesCustomCodeGeneration = true
            });

            // Seems like currently Glue doesn't differentiate between remove from managers and destroy...may need to investigate this if it becomes a problem.
            renderTargetAti.DestroyMethod = "this.Dispose()";

            AvailableAssetTypes.Self.AddAssetType(renderTargetAti);
        }
Example #7
0
 private void AddAssetTypeIfNotPresent(AssetTypeInfo ati)
 {
     if (AvailableAssetTypes.Self.AllAssetTypes.Any(item => item.FriendlyName == ati.FriendlyName) == false)
     {
         AvailableAssetTypes.Self.AddAssetType(ati);
     }
 }
Example #8
0
        private void CreateAndAddTpsAti()
        {
            AssetTypeInfo gumProjectAti = new AssetTypeInfo();

            gumProjectAti.FriendlyName = "TexturePacker Sprite Sheet (.tps)";

            //gumProjectAti.QualifiedSaveTypeName = "Gum.Data.ProjectSave";
            gumProjectAti.Extension = "tps";
            //gumProjectAti.CustomLoadMethod = "FlatRedBall.Gum.GumIdb.StaticInitialize(\"{FILE_NAME}\"); " +
            //    "FlatRedBall.Gum.GumIdb.RegisterTypes();  " +
            //    "FlatRedBall.Gui.GuiManager.BringsClickedWindowsToFront = false;";
            gumProjectAti.SupportsMakeOneWay           = false;
            gumProjectAti.ShouldAttach                 = false;
            gumProjectAti.MustBeAddedToContentPipeline = false;
            gumProjectAti.CanBeCloned        = false;
            gumProjectAti.HasCursorIsOn      = false;
            gumProjectAti.HasVisibleProperty = false;
            gumProjectAti.CanIgnorePausing   = false;

            // don't let users add this:
            gumProjectAti.HideFromNewFileWindow = true;

            gumProjectAti.CanBeObject = false;

            AddIfNotPresent(gumProjectAti);
        }
 private bool IsIInstructable(AssetTypeInfo assetTypeInfo)
 {
     return(assetTypeInfo?.RuntimeTypeName == "Sprite" ||
            assetTypeInfo?.RuntimeTypeName == "Text" ||
            assetTypeInfo?.RuntimeTypeName == "PositionedObject"
            );
 }
Example #10
0
        /// <summary>
        /// Returns whether the calling Entity inherits from another Entity that implements IVisible.
        /// Whether the calling Entity itself implements IVisible doesn't matter.
        /// </summary>
        /// <param name="instance">The calling Entity</param>
        /// <returns>Whether the implementation is found in a base Entity.</returns>
        public static bool GetInheritsFromIVisible(this EntitySave instance)
        {
            if (string.IsNullOrEmpty(instance.BaseEntity))
            {
                return(false);
            }
            else
            {
                if (instance.InheritsFromFrbType())
                {
                    AssetTypeInfo ati = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(instance.BaseEntity, instance);

                    if (ati != null)
                    {
                        return(ati.HasVisibleProperty);
                    }
                }
                else
                {
                    EntitySave entitySave = ObjectFinder.Self.GetEntitySave(instance.BaseEntity);

                    return(entitySave != null && (entitySave.ImplementsIVisible || entitySave.GetInheritsFromIVisible()));
                }
            }

            return(false);
        }
Example #11
0
        private static void SetAtiValue(AssetTypeInfo ati, string variableName, string value)
        {
            var orthogonal = ati.VariableDefinitions.FirstOrDefault(item => item.Name == variableName);

            if (orthogonal != null)
            {
                orthogonal.DefaultValue = value;
            }
        }
Example #12
0
        private void CreateNoCodeGenerationAtiFor(string extension)
        {
            AssetTypeInfo ati = new AssetTypeInfo();

            ati.Extension    = extension;
            ati.FriendlyName = extension + " (" + extension + ")";

            AvailableAssetTypes.Self.AddAssetType(ati);
        }
Example #13
0
        private void BtnAddNewFileClick(object sender, System.EventArgs e)
        {
            if (!ProjectTypeIsValid())
            {
                return;
            }

            var nfw = new CustomizableNewFileWindow();

            foreach (var ati in AvailableAssetTypes.Self.AllAssetTypes)
            {
                if (!string.IsNullOrEmpty(ati.Extension) && !string.IsNullOrEmpty(ati.QualifiedSaveTypeName))
                {
                    nfw.AddOption(ati);
                }

                // special case .txt
                if (ati.Extension == "txt")
                {
                    nfw.AddOption(ati);
                }
            }

            // Also add CSV files
            //nfw.AddOption(new AssetTypeInfo("csv", "", null, "Spreadsheet (.csv)", "", ""));
            nfw.AddOption(AvailableAssetTypes.Self.AllAssetTypes.First(item => item.FriendlyName == "Spreadsheet (.csv)"));

            var dialogResult = nfw.ShowDialog();

            if (dialogResult == true)
            {
                AssetTypeInfo resultAssetTypeInfo = nfw.ResultAssetTypeInfo;
                bool          make2D = nfw.GetOptionFor(resultAssetTypeInfo) == "2D";

                string name = nfw.ResultName;

                string createdFile = PluginManager.CreateNewFile(resultAssetTypeInfo, make2D, FileManager.GetDirectoryKeepRelative(Rfs.Name), name);

                //var createdFile = resultAssetTypeInfo.CreateNewFile(FileManager.GetDirectoryKeepRelative(Rfs.Name) + name, "", make2D);
                createdFile = ProjectManager.MakeRelativeContent(createdFile);

                var psf = new ProjectSpecificFile
                {
                    ProjectName = cboProjectType.Text,
                    FilePath    = createdFile
                };

                Value.Add(psf);
                Rfs.ProjectSpecificFiles = Value;
                GlueCommands.Self.ProjectCommands.UpdateFileMembershipInProject(Rfs);
                ProjectManager.SaveProjects();
                GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

                RefreshList();
            }
        }
Example #14
0
        public static AssetTypeInfo GetAssetTypeInfo(this NamedObjectSave instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
            if (string.IsNullOrEmpty(instance.ClassType))
            {
                return(null);
            }

            // If this NOS uses an EntireFile, then we should ask the file for its AssetTypeInfo,
            // as there may be multiple file types that produce the same class type.
            // For example
            AssetTypeInfo returnAti = null;

            if (instance.IsEntireFile)
            {
                var container = instance.GetContainer();

                var rfs = container?.GetReferencedFileSave(instance.SourceFile);

                if (rfs != null)
                {
                    var candidateAti = rfs.GetAssetTypeInfo();

                    // The user may use a file, but may change the runtime type through the
                    // SourceName property, so we need to make sure they match:
                    if (candidateAti != null && candidateAti.RuntimeTypeName == instance.ClassType)
                    {
                        returnAti = candidateAti;
                    }
                }
            }

            if (returnAti == null)
            {
                returnAti = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(instance.ClassType, instance, isObject: true);
            }

            if (instance.ClassType.StartsWith("PositionedObjectList<"))
            {
                return(null);
            }
            else
            {
                // Vic says: I don't think this should throw an exception anymore
                //if (returnAti == null)
                //{
                //    throw new InvalidOperationException("You probably need to add the class type " + this.ClassType +
                //        " to the ContentTypes.csv");
                //}

                return(returnAti);
            }
        }
Example #15
0
        public ReferencedFileSave ShowAddNewFileDialog()
        {
            ReferencedFileSave rfs = null;

            NewFileWindow nfw = CreateNewFileWindow();

            if (nfw.ShowDialog(MainGlueWindow.Self) == DialogResult.OK)
            {
                string        name = nfw.ResultName;
                AssetTypeInfo resultAssetTypeInfo = nfw.ResultAssetTypeInfo;
                string        errorMessage;
                string        directory = null;
                IElement      element   = EditorLogic.CurrentElement;

                if (EditorLogic.CurrentTreeNode.IsDirectoryNode())
                {
                    directory = EditorLogic.CurrentTreeNode.GetRelativePath().Replace("/", "\\");
                }

                var option = nfw.GetOptionFor(resultAssetTypeInfo);

                rfs = GlueProjectSaveExtensionMethods.AddReferencedFileSave(
                    element, directory, name, resultAssetTypeInfo,
                    option, out errorMessage);



                if (!string.IsNullOrEmpty(errorMessage))
                {
                    MessageBox.Show(errorMessage);
                }
                else if (rfs != null)
                {
                    var createdFile = ProjectManager.MakeAbsolute(rfs.GetRelativePath());

                    if (createdFile.EndsWith(".csv"))
                    {
                        string location = ProjectManager.MakeAbsolute(createdFile);

                        CsvCodeGenerator.GenerateAndSaveDataClass(rfs, AvailableDelimiters.Comma);
                    }


                    ElementViewWindow.UpdateChangedElements();

                    ElementViewWindow.SelectedNode = GlueState.Self.Find.ReferencedFileSaveTreeNode(rfs);

                    PluginManager.ReactToNewFile(rfs);

                    GluxCommands.Self.SaveGlux();
                }
            }

            return(rfs);
        }
Example #16
0
        private AssetTypeInfo CreateAtiForLayeredTilemapTilb()
        {
            AssetTypeInfo toReturn = CreateAtiForLayeredTilemapScnx();

            toReturn.FriendlyName          = "LayeredTileMap (.tilb)";
            toReturn.QualifiedSaveTypeName = "";
            toReturn.Extension             = "tilb";
            toReturn.CustomLoadMethod      = "{THIS} = FlatRedBall.TileGraphics.LayeredTileMap.FromReducedTileMapInfo(\"{FILE_NAME}\", {CONTENT_MANAGER_NAME});";

            return(toReturn);
        }
Example #17
0
        private AssetTypeInfo CreateArticyDraftXmlAti()
        {
            var toReturn = new AssetTypeInfo();

            toReturn.FriendlyName             = "Articy:Draft XML File";
            toReturn.QualifiedRuntimeTypeName = new PlatformSpecificType();
            toReturn.QualifiedRuntimeTypeName.QualifiedType = "ArticyDraft.GameDialogue";

            // todo  continue here maybe

            return(toReturn);
        }
        public void AddIfNotPresent(AssetTypeInfo ati)
        {
            var alreadyAdded = AvailableAssetTypes.Self.AllAssetTypes
                               .Any(item =>
                                    item.FriendlyName == ati.FriendlyName &&
                                    item.QualifiedRuntimeTypeName.QualifiedType == ati.QualifiedRuntimeTypeName.QualifiedType);

            if (alreadyAdded == false)
            {
                AvailableAssetTypes.Self.AddAssetType(ati);
            }
        }
        public List <string> GetInheritanceList(IElement element, EntitySave entitySave, out EntitySave rootEntitySave)
        {
            var inheritsFromEntity = !string.IsNullOrEmpty(element.BaseElement) &&
                                     element.BaseElement != "<NONE>" && !element.InheritsFromFrbType();

            rootEntitySave = null;

            if (inheritsFromEntity)
            {
                rootEntitySave     = entitySave.GetRootBaseEntitySave();
                inheritsFromEntity = inheritsFromEntity && entitySave.GetRootBaseEntitySave() != null;
            }



            List <string> inheritanceList = new List <string>();

            if (inheritsFromEntity)
            {
                inheritanceList.Add(
                    ProjectManager.ProjectNamespace + "." + entitySave.BaseEntity.Replace("\\", "."));
            }
            else if (entitySave.InheritsFromFrbType())
            {
                AssetTypeInfo ati = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(entitySave.BaseEntity);

                if (ati != null)
                {
                    inheritanceList.Add(ati.QualifiedRuntimeTypeName.QualifiedType);
                }
                else
                {
                    inheritanceList.Add(entitySave.BaseEntity);
                }
            }
            else
            {
                inheritanceList.Add("FlatRedBall.PositionedObject");
            }


            inheritanceList.Add("FlatRedBall.Graphics.IDestroyable");


            foreach (ElementComponentCodeGenerator eccg in CodeWriter.CodeGenerators)
            {
                eccg.AddInheritedTypesToList(inheritanceList, element);
            }

            StringFunctions.RemoveDuplicates(inheritanceList);

            return(inheritanceList);
        }
        bool IsRfsOfType(ReferencedFileSave rfs, Type type)
        {
            AssetTypeInfo ati = rfs.GetAssetTypeInfo();

            if (ati != null)
            {
                return(ati.QualifiedRuntimeTypeName.QualifiedType == type.FullName);
            }
            else
            {
                return(false);
            }
        }
        bool IsRfsOfUnqualifiedRuntimeType(ReferencedFileSave rfs, string unqualifiedRuntimeType)
        {
            AssetTypeInfo ati = rfs.GetAssetTypeInfo();

            if (ati != null)
            {
                return(ati.RuntimeTypeName == unqualifiedRuntimeType);
            }
            else
            {
                return(false);
            }
        }
        private AssetTypeInfo GetAtiFor(ElementSave element)
        {
            AssetTypeInfo newAti = FlatRedBall.IO.FileManager.CloneObject <AssetTypeInfo>(GraphicalUiElementAti);


            newAti.QualifiedRuntimeTypeName = new PlatformSpecificType()
            {
                QualifiedType = GueDerivingClassCodeGenerator.GetQualifiedRuntimeTypeFor(element)
            };

            if (element is ComponentSave)
            {
                newAti.Extension        = GumProjectSave.ComponentExtension;
                newAti.CustomLoadMethod = ComponentAti.CustomLoadMethod + " as " + GueDerivingClassCodeGenerator.GetQualifiedRuntimeTypeFor(element);
            }
            string unqualifiedName = element.Name + "Runtime";

            newAti.FriendlyName = unqualifiedName;

            newAti.FindByNameSyntax = "GetGraphicalUiElementByName(\"OBJECTNAME\") as " +
                                      newAti.QualifiedRuntimeTypeName.QualifiedType;

            if (newAti.ExtraVariablesPattern.EndsWith(";") == false)
            {
                newAti.ExtraVariablesPattern += ";";
            }

            newAti.ExtraVariablesPattern = "";

            // 9/24/2014
            // Jesse was getting
            // the plugin to crash
            // on this line of code
            // with a NullReferenceException.
            // I'm going to wrap this in if-s to be sure it's safe.
            if (element != null && element.DefaultState != null && element.DefaultState.Variables != null)
            {
                foreach (var variable in element.DefaultState.Variables.Where(item => !string.IsNullOrEmpty(item.ExposedAsName) || string.IsNullOrEmpty(item.SourceObject)))
                {
                    var variableDefinition = new VariableDefinition();
                    variableDefinition.Category     = variable.Category;
                    variableDefinition.DefaultValue = variable.Value?.ToString();
                    variableDefinition.Name         = variable.ExposedAsName ?? variable.Name;
                    variableDefinition.Type         = variable.Type;

                    newAti.VariableDefinitions.Add(variableDefinition);
                }
            }

            return(newAti);
        }
Example #23
0
        public static void UpdateShownVariables(DataUiGrid grid, NamedObjectSave instance, IElement container)
        {
            grid.Categories.Clear();

            List <MemberCategory> categories = new List <MemberCategory>();
            var defaultCategory = new MemberCategory("Variables");

            defaultCategory.FontSize = 14;
            categories.Add(defaultCategory);

            AssetTypeInfo ati = instance.GetAssetTypeInfo();

            // not sure if this is needed:
            if (instance.TypedMembers.Count == 0)
            {
                instance.UpdateCustomProperties();
            }

            CreateCategoriesAndVariables(instance, container, categories, ati);

            if (ati != null)
            {
                SortCategoriesAndMembers(ref categories, ati);
            }


            if (defaultCategory.Members.Count == 0)
            {
                categories.Remove(defaultCategory);
            }
            else if (categories.Count != 1)
            {
                defaultCategory.Name = "Other Variables";
            }

            if (categories.Count != 0)
            {
                // "Name" should be the very first property:
                var nameCategory = CreateNameInstanceMember(instance);
                categories.Insert(0, nameCategory);
            }

            SetAlternatingColors(grid, categories);

            foreach (var category in categories)
            {
                grid.Categories.Add(category);
            }

            grid.Refresh();
        }
        public List <AssetTypeInfo> GetAtisForDerivedGues()
        {
            List <AssetTypeInfo> assetTypeInfos = new List <AssetTypeInfo>();

            foreach (var element in AppState.Self.AllLoadedElements)
            {
                if (GueDerivingClassCodeGenerator.Self.ShouldGenerateRuntimeFor(element))
                {
                    AssetTypeInfo newAti = GetAtiFor(element);
                    assetTypeInfos.Add(newAti);
                }
            }

            return(assetTypeInfos);
        }
Example #25
0
        public static AssetTypeInfo GetAssetTypeInfoForProjectSpecificFile(this ReferencedFileSave instance, ProjectSpecificFile psf)
        {
            string        extension         = FileManager.GetExtension(psf.FilePath);
            AssetTypeInfo thisAssetTypeInfo = instance.GetAssetTypeInfo();

            foreach (AssetTypeInfo assetTypeInfo in AvailableAssetTypes.Self.AllAssetTypes)
            {
                if (assetTypeInfo.Extension == extension &&
                    assetTypeInfo.RuntimeTypeName == thisAssetTypeInfo.RuntimeTypeName)
                {
                    return(assetTypeInfo);
                }
            }
            return(null);
        }
Example #26
0
        private void CreateAndAddTexturePackerSpriteSheetAti()
        {
            TextureAtlasAti = new AssetTypeInfo();
            TextureAtlasAti.FriendlyName = "Texture Atlas";
            // We don't want this as part of the VS project, since it's not loaded at runtime.
            TextureAtlasAti.Extension = "atlas";

            TextureAtlasAti.QualifiedRuntimeTypeName.QualifiedType = "FlatRedBall.Graphics.Texture.Atlas";
            TextureAtlasAti.CustomLoadMethod =
                "{THIS} = FlatRedBall.Graphics.Texture.AtlasLoader.Load(\"{FILE_NAME}\", {CONTENT_MANAGER_NAME});";

            TextureAtlasAti.CustomBuildToolName = "*.tps->TexturePacker.exe-> *.atlas";

            AddIfNotPresent(TextureAtlasAti);

            AvailableAssetTypes.Self.AddAssetType(TextureAtlasAti);
        }
Example #27
0
        public string GetObjectTypeFromAti(AssetTypeInfo ati)
        {
            if (ati == null)
            {
                return(null);
            }
            else
            {
                string fileType = ati.FriendlyName;
                if (fileType.Contains("("))
                {
                    fileType = fileType.Substring(0, fileType.IndexOf('('));
                }

                fileType = fileType.Replace(" ", "");
                return(fileType);
            }
        }
Example #28
0
        private bool CreateNewFile(AssetTypeInfo assetTypeInfo, object extraData, string directory, string name, out string resultingName)
        {
            resultingName = null;
            if (assetTypeInfo != null)
            {
                string createdFile = GetCreatedFileTarget(assetTypeInfo, directory, name);


                SaveNewFileAtLocation(assetTypeInfo, createdFile);

                bool make2D = (bool)extraData;

                AssetTypeInfoExtensionMethodsGlue.CreateCompanionSettingsFile(createdFile, make2D);
                resultingName = createdFile;

                return(true);
            }
            return(false);
        }
Example #29
0
        /// <summary>
        /// Returns whether the calling Entity inherits from another class that implements ICollidable.
        /// Whether the calling Entity itself implements ICollidable doesn't matter.
        /// </summary>
        /// <param name="instance">The calling Entity</param>
        /// <returns>Whether the implementation is found in a base Entity.</returns>
        public static bool GetHasImplementsCollidableProperty(this EntitySave instance)
        {
            if (string.IsNullOrEmpty(instance.BaseEntity))
            {
                return(true);
            }
            else
            {
                if (instance.InheritsFromFrbType())
                {
                    AssetTypeInfo ati = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(instance.BaseEntity, instance);

                    if (ati != null)
                    {
                        return(!ati.ImplementsICollidable);
                    }
                }
                return(true);
            }
        }
        public AssetTypeInfo CreateAtiForTileShapeCollection()
        {
            AssetTypeInfo toReturn = new AssetTypeInfo();

            toReturn.FriendlyName             = "TileShapeCollection";
            toReturn.QualifiedRuntimeTypeName = new PlatformSpecificType();
            toReturn.QualifiedRuntimeTypeName.QualifiedType = "FlatRedBall.TileCollisions.TileShapeCollection";
            toReturn.QualifiedSaveTypeName        = null;
            toReturn.Extension                    = null;
            toReturn.AddToManagersMethod          = new List <string>();
            toReturn.CustomLoadMethod             = null;
            toReturn.DestroyMethod                = "this.Visible = false";
            toReturn.ShouldBeDisposed             = false;
            toReturn.ShouldAttach                 = false;
            toReturn.MustBeAddedToContentPipeline = false;
            toReturn.CanBeCloned                  = false;
            toReturn.HasCursorIsOn                = false;
            toReturn.CanIgnorePausing             = false;
            toReturn.CanBeObject                  = true;
            toReturn.HasVisibleProperty           = true;

            return(toReturn);
        }
Example #31
0
        public bool CreateNewFile(AssetTypeInfo assetTypeInfo, object extraData, string directory, string name, out string resultingName)
        {
            resultingName = null;
            if (assetTypeInfo != null)
            {
                string createdFile = GetCreatedFileTarget(assetTypeInfo, directory, name);


                SaveNewFileAtLocation(assetTypeInfo, createdFile);

                bool make2D = (bool)extraData;

                AssetTypeInfoExtensionMethodsGlue.CreateCompanionSettingsFile(createdFile, make2D);
                resultingName = createdFile;

                return true;
            }
            return false;

        }
Example #32
0
        public string GetObjectTypeFromAti(AssetTypeInfo ati)
        {
            if (ati == null)
            {
                return null;
            }
            else
            {
                string fileType = ati.FriendlyName;
                if (fileType.Contains("("))
                {
                    fileType = fileType.Substring(0, fileType.IndexOf('('));
                }

                fileType = fileType.Replace(" ", "");
                return fileType;
            }
        }
        private static void InstantiateObjectInSwitchStatement(NamedObjectSave namedObject, ICodeBlock codeBlock,
            List<string[]> referencedFilesAlreadyUsingFullFile, AssetTypeInfo ati, string objectName, ReferencedFileSave rfs,
            List<StateSave> stateSaves, IElement saveObject, string defaultContainer, string overridingName)
        {
            var switchBlock = codeBlock.Switch("LoadingState");

            for (int i = 0; i < stateSaves.Count; i++)
            {
                StateSave stateSave = stateSaves[i];

                string name = "";

                // I don't think we're going to use these anymore
                //NamedObjectPropertyOverride objectOverride = stateSave.GetNamedObjectOverride(objectName);
                //name = FileManager.RemovePath(FileManager.RemoveExtension(objectOverride.SourceFile));

                InstantiateObjectUsingFile(namedObject, switchBlock.Case("VariableState." + stateSave.Name), referencedFilesAlreadyUsingFullFile, ati, objectName, rfs,
                    saveObject,
                    name, overridingName);
            }

            InstantiateObjectUsingFile(namedObject, switchBlock.Case("VariableState.Uninitialized:"), referencedFilesAlreadyUsingFullFile, ati, objectName, rfs,
                saveObject, defaultContainer, overridingName);
        }
        public static void GetLoadCallForAtiFile(ReferencedFileSave rfs, AssetTypeInfo ati, string variableName, string contentManagerString, string fileNameToLoad, ICodeBlock codeBlock)
        {
            string formattableLine = null;

            if (!string.IsNullOrEmpty(ati.CustomLoadMethod))
            {
                formattableLine = ati.CustomLoadMethod;
                // Replace the expressive variable names with ints:
                formattableLine = formattableLine.Replace("{THIS}", "{0}");
                formattableLine = formattableLine.Replace("{TYPE}", "{1}");
                formattableLine = formattableLine.Replace("{FILE_NAME}", "{2}");
                formattableLine = formattableLine.Replace("{CONTENT_MANAGER_NAME}", "{3}");

                // If the user didn't end the line with a semicolon, let's do it ourselves
                if (!formattableLine.EndsWith(";"))
                {
                    formattableLine = formattableLine + ";";
                }
            }
            else
            {

                formattableLine = "{0} = FlatRedBall.FlatRedBallServices.Load<{1}>(@\"{2}\", {3});";
            }

            bool shouldAddExtensionOnNonXnaPlatforms = 
                FileManager.GetExtension(fileNameToLoad) != FileManager.GetExtension(rfs.Name) && FileManager.GetExtension(rfs.Name) == "png";

            if(shouldAddExtensionOnNonXnaPlatforms)
            {
                codeBlock.Line("#if IOS || ANDROID || WINDOWS_8");

                string withExtension = fileNameToLoad + ".png";
                codeBlock.Line(
                    string.Format(formattableLine,
                                variableName, ati.QualifiedRuntimeTypeName.QualifiedType, withExtension, contentManagerString));
                codeBlock.Line("#else");

            }

            codeBlock.Line(
                string.Format(formattableLine,
                            variableName, ati.QualifiedRuntimeTypeName.QualifiedType, fileNameToLoad, contentManagerString));

            if (shouldAddExtensionOnNonXnaPlatforms)
            {
                codeBlock.Line("#endif");
            }

        }
        private static void SortMembers(List<MemberCategory> categories, AssetTypeInfo ati)
        {
            foreach(var category in categories)
            {
                string categoryName = category.Name;

                var variableDefinitions = ati.VariableDefinitions
                    .Where(item => item.Category == categoryName)
                    .Select(item=>item.Name)
                    .ToList();

                var sorted = category.Members
                    .OrderBy(item =>
                    {
                        var castedItem = item as DataGridItem;
                        var index = variableDefinitions.IndexOf(castedItem.UnmodifiedVariableName);

                        if(index == -1)
                        {
                            return int.MaxValue;
                        }
                        else
                        {
                            return index;
                        }
                    })
                    .ToList();

                category.Members.Clear();

                foreach(var item in sorted)
                {
                    category.Members.Add(item);
                }
            }
        }
Example #36
0
        private static string GetCreatedFileTarget(AssetTypeInfo assetTypeInfo, string directory, string name)
        {
            string createdFile = "";

            if (!directory.EndsWith("\\") && !directory.EndsWith("/"))
            {
                directory = directory + "/";
            }

            if (FileManager.IsRelative(directory))
            {
                createdFile = FileManager.RelativeDirectory + directory + name + "." + assetTypeInfo.Extension;

                if (ObjectFinder.Self.GlueProject != null)
                {
                    // I think we should always use the content directory whether we have a content project or not:
                    createdFile = ProjectManager.ContentDirectory + directory + name + "." + assetTypeInfo.Extension;
                }

            }
            else
            {
                createdFile = directory + name + "." + assetTypeInfo.Extension;
            }
            return createdFile;
        }
        private static List<MemberCategory> SortCategories(List<MemberCategory> categories, AssetTypeInfo ati)
        {
            var orderedCategoryNames = ati.VariableDefinitions.Select(item => item.Category).Distinct().ToList();

            categories = categories.OrderBy(item =>
            {
                int index = orderedCategoryNames.IndexOf(item.Name);

                if (index == -1)
                {
                    return int.MaxValue;
                }
                else
                {
                    return index;
                }
            }).ToList();
            return categories;
        }
        private static void GenerateInitializationForAssetTypeInfoRfs(ReferencedFileSave referencedFile, ICodeBlock codeBlock, bool loadsUsingGlobalContentManager, string variableName, string fileName, AssetTypeInfo ati, ProjectBase project)
        {
            string typeName = ati.RuntimeTypeName;
            var vsProject = project as VisualStudioProject;
            var isContentPipeline = (vsProject == null || vsProject.AllowContentCompile) &&
                                    (ati.MustBeAddedToContentPipeline || referencedFile.UseContentPipeline);

            if (isContentPipeline)
            {
                fileName = FileManager.RemoveExtension(fileName);
            }

            bool isSharedStatic = referencedFile.IsSharedStatic;


            string referencedFileName = referencedFile.Name;
            bool containedByGlobalContentFiles = GlobalContentFilesDictionary.ContainsKey(referencedFileName);

            var referencedFileContainerType = referencedFile.GetContainerType();

            if (isSharedStatic &&
                containedByGlobalContentFiles && 
                loadsUsingGlobalContentManager &&
                referencedFileContainerType != ContainerType.None)
            {
                string globalRfsVariable = GlobalContentFilesDictionary[referencedFile.Name].GetInstanceName();

                codeBlock.Line(string.Format("{0} = GlobalContent.{1};",
                                                variableName, globalRfsVariable));
            }
            else
            {
                ContentLoadWriter.GetLoadCallsForRfs(
                    referencedFile, fileName, ati, variableName, codeBlock, loadsUsingGlobalContentManager && referencedFile.IsSharedStatic, isContentPipeline);
            }
        }
        private static string WriteMethodForClone(NamedObjectSave namedObject, ICodeBlock codeBlock,
            List<string[]> referencedFilesAlreadyUsingFullFile, AssetTypeInfo nosAti, string objectName,
            ReferencedFileSave rfs, IElement container, string containerName, string overridingName)
        {
            int lastParen = namedObject.SourceName.LastIndexOf(" (");
            string nameOfSourceInContainer = namedObject.SourceName.Substring(0, lastParen);
            // This could have a quote in the name.  If so we want to escape it since this will be put in code:
            nameOfSourceInContainer = nameOfSourceInContainer.Replace("\"", "\\\"");

            string cloneString = ".Clone()";

            string namedObjectToPullFrom = null;
            foreach (string[] stringPair in referencedFilesAlreadyUsingFullFile)
            {
                if (rfs != null && stringPair[0] == rfs.Name && !namedObject.SourceName.StartsWith("Entire File ("))
                {
                    namedObjectToPullFrom = stringPair[1];
                    break;
                }
            }

            // September 30, 2012
            // Now all files - whether
            // they are part of an Entity
            // or part of a Screen, are static.
            // This means that the rfs.IsSharedStatic
            // check will usually fail.  However, Screens
            // will still add to managers even for static
            // object, so we want to make sure that we don't
            // clone an object already added to managers, so we
            // need the last check to see if the container is a ScreenSave.
            if (nosAti == null || !nosAti.CanBeCloned || namedObjectToPullFrom != null || (rfs != null && rfs.IsSharedStatic == false) || container is ScreenSave)
            {
                cloneString = "";
            }

            if (nosAti != null && !string.IsNullOrEmpty(nosAti.CustomCloneMethod))
            {
                cloneString = nosAti.CustomCloneMethod;

            }
            AssetTypeInfo rfsAti = null;
            if (rfs != null)
            {
                rfsAti = rfs.GetAssetTypeInfo();
            }

            bool usesFullConversion = false;

            if (rfsAti != null && rfsAti.Conversion.Count != 0)
            {
                var foundConversion = rfsAti.Conversion.FirstOrDefault(item => item.ToType == namedObject.InstanceType);

                if (foundConversion != null)
                {
                    cloneString = foundConversion.ConversionPattern.Replace("{NEW}", objectName);
                    cloneString = cloneString.Replace("{THIS}", rfs.GetInstanceName());
                    usesFullConversion = true;
                }
            }

            if (namedObjectToPullFrom != null)
            {
                containerName = namedObjectToPullFrom;
            }
            if (!string.IsNullOrEmpty(overridingName))
            {
                containerName = overridingName;
            }

            string listMemberName = ContentParser.GetMemberNameForList(FileManager.GetExtension(namedObject.SourceFile), namedObject.InstanceType);

            if (!string.IsNullOrEmpty(listMemberName))
            {
                listMemberName += ".";
            }

            if (nameOfSourceInContainer == "Entire File" && string.IsNullOrEmpty(listMemberName))
            {
                if (usesFullConversion)
                {
                    codeBlock.Line(cloneString + ";");
                }
                else if (cloneString.Contains("{THIS}"))
                {
                    string entireString = cloneString.Replace("{THIS}", objectName);
                    entireString = entireString.Replace("{SOURCE_FILE}", containerName);

                    codeBlock.Line(entireString);
                }
                else
                {
                    codeBlock.Line(string.Format("{0} = {1}{2};",
                                                 objectName,
                                                 containerName,
                                                 cloneString));
                }
            }
            else
            {
                string findByNameLine = "";
                if (nosAti != null)
                {
                    findByNameLine = nosAti.FindByNameSyntax;

                    if (string.IsNullOrEmpty(findByNameLine))
                    {
                        string message = "The object " + namedObject.ToString() + " is part of a file.  To be properly generated " +
                            "the AssetTypeInfo (or CSV value) for " + nosAti.ToString() + " must contain a FindByNameSyntax property";

                        throw new Exception(message);
                    }
                }



                findByNameLine = findByNameLine.Replace("OBJECTNAME", nameOfSourceInContainer);

                string possibleDot = ".";

                if (findByNameLine.StartsWith("["))
                {
                    possibleDot = "";
                }

                //if (namedObject.AddToManagers)
                {
                    // Not sure why we don't clone on a non add to manager.  This post right here suggests we should
                    // and I tend to believe Scott so...I'm following his advice:
                    // http://www.flatredball.com/frb/forum/viewtopic.php?f=26&t=4741
                    codeBlock.Line(string.Format("{0} = {1}{2}{3}{4}{5};",
                                                 objectName,
                                                 containerName,
                                                 possibleDot,
                                                 listMemberName,
                                                 findByNameLine,
                                                 cloneString));
                }
                //else
                //{

                //    stringBuilder.AppendLine(
                //        string.Format("\t\t\t{0} = {1}{2}{3}{4};",
                //            objectName,
                //            containerName,
                //            possibleDot,
                //            listMemberName,
                //            findByNameLine));
                //}
            }
            return containerName;
        }
Example #40
0
        public ReferencedFileSave CreateReferencedFileSaveForExistingFile(IElement containerForFile, string directoryInsideContainer, string absoluteFileName,
            PromptHandleEnum unknownTypeHandle, AssetTypeInfo ati, out string creationReport, out string errorMessage)
        {
            creationReport = "";
            errorMessage = null;

            ReferencedFileSave referencedFileSaveToReturn = null;

            string whyItIsntValid;
            // Let's see if there is already an Entity with the same name
            string fileWithoutPath = FileManager.RemovePath(FileManager.RemoveExtension(absoluteFileName));

            bool isValid = 
                NameVerifier.IsReferencedFileNameValid(fileWithoutPath, ati, referencedFileSaveToReturn, containerForFile, out whyItIsntValid);

            if (!isValid)
            {
                errorMessage = "Invalid file name:\n" + fileWithoutPath + "\n" + whyItIsntValid;
            }
            else
            {
                    Zipper.UnzipAndModifyFileIfZip(ref absoluteFileName);
                    string extension = FileManager.GetExtension(absoluteFileName);
                    
                    bool isValidExtensionOrIsConfirmedByUser;
                    bool isUnknownType;
                    CheckAndWarnAboutUnknownFileTypes(unknownTypeHandle, extension, out isValidExtensionOrIsConfirmedByUser, out isUnknownType);

                    if (isValidExtensionOrIsConfirmedByUser)
                    {

                        string directoryThatFileShouldBeRelativeTo = GetFullPathContentDirectory(containerForFile, directoryInsideContainer);

                        string projectDirectory = projectDirectory = FileManager.GetDirectory(ProjectManager.ContentProject.FullFileName);

                        string fileToAdd = GetNameOfFileRelativeToProject(absoluteFileName, directoryThatFileShouldBeRelativeTo, projectDirectory);

                        BuildToolAssociation bta = null;

                        if (ati != null && !string.IsNullOrEmpty(ati.CustomBuildToolName))
                        {
                            bta =
                                BuildToolAssociationManager.Self.GetBuilderToolAssociationByName(ati.CustomBuildToolName);
                        }

                        if (containerForFile != null)
                        {
                            referencedFileSaveToReturn = containerForFile.AddReferencedFile(fileToAdd, ati, bta);
                        }
                        else
                        {
                            bool useFullPathAsName = false;
                            // todo - support built files here
                            referencedFileSaveToReturn = AddReferencedFileToGlobalContent(fileToAdd, useFullPathAsName);
                        }



                        // This will be null if there was an error above in creating this file
                        if (referencedFileSaveToReturn != null)
                        {
                            if (containerForFile != null)
                                containerForFile.HasChanged = true;

                            if (fileToAdd.EndsWith(".csv"))
                            {
                                string fileToAddAbsolute = ProjectManager.MakeAbsolute(fileToAdd);
                                CsvCodeGenerator.GenerateAndSaveDataClass(referencedFileSaveToReturn, referencedFileSaveToReturn.CsvDelimiter);
                            }
                            if (isUnknownType)
                            {
                                referencedFileSaveToReturn.LoadedAtRuntime = false;
                            }

                            ProjectManager.UpdateFileMembershipInProject(referencedFileSaveToReturn);

                            PluginManager.ReactToNewFile(referencedFileSaveToReturn);
                            GluxCommands.Self.SaveGlux();
                            ProjectManager.SaveProjects();
                            UnreferencedFilesManager.Self.RefreshUnreferencedFiles(false);

                            string error;
                            referencedFileSaveToReturn.RefreshSourceFileCache(false, out error);

                            if (!string.IsNullOrEmpty(error))
                            {
                                ErrorReporter.ReportError(referencedFileSaveToReturn.Name, error, false);
                            }
                        }
                    }
            }

            return referencedFileSaveToReturn;
        }
        private static void InstantiateObjectUsingFile(NamedObjectSave namedObject, ICodeBlock codeBlock,
            List<string[]> referencedFilesAlreadyUsingFullFile, AssetTypeInfo nosAti, string objectName,
            ReferencedFileSave rfs, IElement container, string containerName, string overridingName)
        {
            #region If the user hasn't picked an object inside the file, it's either a SpriteRig or we should return ""

            if (string.IsNullOrEmpty(namedObject.SourceName) || namedObject.SourceName == "<NONE>")
            {
                if (FileManager.GetExtension(namedObject.SourceFile) == "srgx")
                {
                    codeBlock.Line(objectName + " = " + containerName + ";");
                }
            }

            #endregion

            #region else, the user has picked a file

            else
            {
                containerName = WriteMethodForClone(namedObject, codeBlock, referencedFilesAlreadyUsingFullFile, nosAti, objectName, rfs, container, containerName, overridingName);

            }

            #endregion
        }
        private static void CreateCategoriesAndVariables(NamedObjectSave instance, IElement container, List<MemberCategory> categories, AssetTypeInfo ati)
        {
            for (int i = 0; i < instance.TypedMembers.Count; i++)
            {

                TypedMemberBase typedMember = instance.TypedMembers[i];
                InstanceMember instanceMember = CreateInstanceMember(instance, container, typedMember, ati);

                var categoryToAddTo = GetOrCreateCategoryToAddTo(categories, ati, typedMember);

                if (instanceMember != null)
                {
                    categoryToAddTo.Members.Add(instanceMember);
                }
            }

            bool shouldAddSourceNameVariable = instance.SourceType == SourceType.File &&
                !string.IsNullOrEmpty(instance.SourceFile);

            if(shouldAddSourceNameVariable)
            {
                AddSourceNameVariable(instance, categories);

            }
        }
        private static string DecideOnLineToAdd(NamedObjectSave namedObject, AssetTypeInfo ati, bool layered)
        {
            int index = 0;
            
            if (ati.AddToManagersMethod.Count > 1 && namedObject.SourceType == SourceType.FlatRedBallType &&
                    (namedObject.SourceClassType == "Sprite" || namedObject.SourceClassType == "SpriteFrame") &&
                    namedObject.IsZBuffered)
            {
                index = 1;
            }

            if (layered)
            {
                return ati.LayeredAddToManagersMethod[index];
            }
            else
            {
                return ati.AddToManagersMethod[index];
            }
        }
        private static ICodeBlock ApplyResetVariables(NamedObjectSave namedObject, ICodeBlock codeBlock, AssetTypeInfo ati)
        {
            // Also reset variables before attachment.
            // May 15, 2011:  This should happen before
            // setting the custom variables.
            // May 16, 2011:  CustomVariables which are 
            // exposed variables are now set before AddToManagers
            // is even called.  Therefore, doing this before doesn't matter
            // anymore.  Moved back down to its old position.
            for (int i = 0; i < namedObject.VariablesToReset.Count; i++)
            {
                string variableToReset = namedObject.VariablesToReset[i];


                string relativeVersion = InstructionManager.GetRelativeForAbsolute(namedObject.VariablesToReset[i]);


                if ((namedObject.SourceType == SourceType.Entity || ati.ShouldAttach) && !string.IsNullOrEmpty(relativeVersion))
                {
                    codeBlock = codeBlock.If(namedObject.InstanceName + ".Parent == null");

                }

                codeBlock.Line(namedObject.InstanceName + "." + namedObject.VariablesToReset[i] + " = " +
                    namedObject.InstanceName + namedObject.VariablesToReset[i].Replace(".", "") + "Reset" + ";");

                if ((namedObject.SourceType == SourceType.Entity || ati.ShouldAttach) && !string.IsNullOrEmpty(relativeVersion))
                {
                    codeBlock = codeBlock.End().Else();

                    codeBlock.Line(namedObject.InstanceName + "." + relativeVersion + " = " +
                        namedObject.InstanceName + namedObject.VariablesToReset[i].Replace(".", "") + "Reset" + ";");
                    codeBlock = codeBlock.End();
                }
            }
            return codeBlock;
        }
Example #45
0
        private void SaveNewFileAtLocation(AssetTypeInfo assetTypeInfo, string createdFile)
        {
            string availableFile;

            if (assetTypeInfo.Extension == "csv")
            {
                string contents =

"\"Name (string, required)\",Health (float)" + Environment.NewLine + "Monster,100";

                FileManager.SaveText(contents, createdFile);
            }
            else if (assetTypeInfo.Extension == "txt")
            {
                const string contents = "Glue is such a great tool!";

                FileManager.SaveText(contents, createdFile);
            }
            // If the save type isn't null, then it's a type that is understood by the Glue, so we can
            // instantiate and save off the instance
            // Why don't we try a template first?
            else if (TryGetTemplateFileForAti(assetTypeInfo, out availableFile))
            {
                CreateNewFileFromAvailableFileTemplate(createdFile, availableFile);
            }
            else if (assetTypeInfo.SaveType != null)
            {
                object saveInstance = Activator.CreateInstance(assetTypeInfo.SaveType);
                FileManager.XmlSerialize(assetTypeInfo.SaveType, saveInstance, createdFile);
            }
            // Unknown type, so save an empty file.
            else
            {
                FileManager.SaveText(null, createdFile);
            }
        }
Example #46
0
        public static bool IsReferencedFileNameValid(string name, AssetTypeInfo ati, ReferencedFileSave rfs, IElement container, out string whyItIsntValid)
        {
            whyItIsntValid = "";

            CheckForCommonImproperNames(name, ref whyItIsntValid);

            // CheckForExistingEntity checks if the name is already used, but we can be more specific if it's part of this entity
            if(container != null)
            {
                string unqualifiedContainerName = FileManager.RemovePath(container.Name);

                if(unqualifiedContainerName.ToLowerInvariant() == FileManager.RemovePath(FileManager.RemoveExtension(name)))
                {
                    string containerType = "Entity";

                    if(container is ScreenSave)
                    {
                        containerType = "Screen";
                    }
                    else if(container is EntitySave)
                    {
                        containerType = "Entity";
                    }
                    else
                    {
                        containerType = "Container";
                    }

                    whyItIsntValid = "The " + containerType + " that you are adding the file to has the same name as the file.  This is not allowed in Glue.  Please rename the file";
                }
            }

            if (string.IsNullOrEmpty(whyItIsntValid))
            {
                CheckForExistingEntity(name, ref whyItIsntValid);
            }

            if (string.IsNullOrEmpty(whyItIsntValid))
            {
                CheckForRfsWithMatchingFileName(container, name, rfs, ref whyItIsntValid);
            }

            if (string.IsNullOrEmpty(whyItIsntValid))
            {
                if (ati != null && ati.Extension == "csv")
                {
                    // Let's see if there is already a spreadsheet by this name and if so, let's warn the user
                    // But we only want a spreadsheet that isn't using a created class:
                    var existing = ObjectFinder.Self.GetAllReferencedFiles().Where(item =>
                        // Is the item a CSV...
                        item.IsCsvOrTreatedAsCsv &&
                            // And is the item different than the rfs we're checking
                        item != rfs &&
                            // And do the names match?
                        FileManager.RemovePath(FileManager.RemoveExtension(item.Name)) == name &&
                            // And does it not use a custom class?
                        ObjectFinder.Self.GlueProject.CustomClasses.Any(customClass => customClass.CsvFilesUsingThis.Contains(item.Name)) == false)
                        .ToList();



                    if (existing.Count != 0)
                    {
                        whyItIsntValid = "There is already a CSV file using the name " + name + ":  " + existing[0].ToString();
                    }
                }
            }

            bool returnValue = string.IsNullOrEmpty(whyItIsntValid);
            return returnValue;
        }
Example #47
0
        private bool TryGetTemplateFileForAti(AssetTypeInfo assetTypeInfo, out string availableFile)
        {
            availableFile = GetNewFileTemplateForExtension(GetAvailableFilesForNewFile(), assetTypeInfo.Extension);

            return availableFile != null;
        }
        public static ReferencedFileSave AddReferencedFileSave(IElement element, string directoryPath, string fileName, 
            AssetTypeInfo resultAssetTypeInfo, string option, out string errorMessage)
        {
            char invalidCharacter;
            ReferencedFileSave rfs = null;
            errorMessage = null;

            #region Get directory

            string directoryRelativeToContent = "";

            if (!String.IsNullOrEmpty(directoryPath))
            {
                //string directory = directoryTreeNode.GetRelativePath().Replace("/", "\\");

                directoryRelativeToContent = directoryPath;
            }
            else if (element != null)
            {
                //string directory = elementToAddTo.GetRelativePath().Replace("/", "\\");

                directoryRelativeToContent = element.Name.Replace(@"/", @"\") + "\\";
            }
            else
            {
                directoryRelativeToContent = "GlobalContent/";
            }


            #endregion

            bool userCancelled = false;


            #region If there is some reason why the file name won't, then work show a message box

            string whyIsntValid;

            if (!NameVerifier.IsReferencedFileNameValid(fileName, resultAssetTypeInfo, rfs, element, out whyIsntValid))
            {
                errorMessage = "Invalid file name:\n" + fileName + "\n" + whyIsntValid;
            }
            else if (resultAssetTypeInfo == null)
            {
                errorMessage = "You must select a valid type for your new file.";
            }
            else if (ObjectFinder.Self.GetReferencedFileSaveFromFile(directoryRelativeToContent + fileName + "." + resultAssetTypeInfo.Extension) != null)
            {
                errorMessage = "There is already a file named\n\n" + directoryRelativeToContent + fileName + "." + resultAssetTypeInfo.Extension;
            }
            // TODO:  This currently checks for an exact match, but we should prevent different files (like a .emix and .scnx) from having the same name
            else if (EditorLogic.CurrentElement != null &&
                EditorLogic.CurrentElement.GetReferencedFileSaveRecursively(directoryRelativeToContent + fileName + "." + resultAssetTypeInfo.Extension) != null)
            {
                errorMessage = "There is already a file named " + fileName;
            }
            // need to check global content for duplicates.  This is not implemented yet.
            #endregion

            #region Else, create the file

            else
            {
                string createdFile = PluginManager.CreateNewFile(resultAssetTypeInfo, option == "2D",
                    directoryRelativeToContent, fileName);

                // let's just re-route this 
                // to the code that adds existing
                // files now that we have a file and
                // that's exactly what we're doing.
                rfs = RightClickHelper.AddSingleFile(createdFile, ref userCancelled, option);

                if (rfs == null && !userCancelled)
                {
                    throw new NullReferenceException("The RFS shouldn't be null");
                }

            }

            #endregion




            return rfs;
        }
Example #49
0
        private void CreateNoCodeGenerationAtiFor(string extension)
        {
            AssetTypeInfo ati = new AssetTypeInfo();
            ati.Extension = extension;
            ati.FriendlyName = extension + " (" + extension + ")";

            AvailableAssetTypes.Self.AddAssetType(ati);
        }
        /// <summary>
        /// Determines if a variable should be ignored by the variable plugin.
        /// </summary>
        /// <param name="typedMember">The typed member - represents the variable which may be ignored.</param>
        /// <param name="instance">The NamedObjectSave owning the variable.</param>
        /// <param name="ati">The Asset Typ Info for the NamedObjectSave.</param>
        /// <returns>Whether to skip the variable.</returns>
        private static bool GetIfShouldBeSkipped(TypedMemberBase typedMember, NamedObjectSave instance, AssetTypeInfo ati)
        {
            var name = typedMember.MemberName;

            if (ati != null)
            {

                if (ati.IsPositionedObject)
                {
                    if (name.EndsWith("Velocity") || name.EndsWith("Acceleration") || name.StartsWith("Relative") ||
                        name == "ParentBone" || name == "KeepTrackOfReal" || name == "Drag"

                        )
                    {
                        return true;
                    }

                }

                if (ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Math.Geometry.AxisAlignedRectangle")
                {
                    return name == "ScaleX" || name == "ScaleY" || name == "Top" || name == "Bottom" ||
                        name == "Left" || name == "Right";
                }

                if (ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Graphics.Text")
                {
                    return
                        name == "AlphaRate" || name == "RedRate" || name == "GreenRate" || name == "BlueRate" ||
                        name == "ScaleVelocity" || name == "SpacingVelocity" ||
                        name == "ScaleXVelocity" || name == "ScaleYVelocity" ||
                        // These used to be the standard way to size text, but now we just
                        // use "TextureScale"
                        name == "Scale" || name == "Spacing" || name == "NewLineDistance"
                        
                        ;
                }

                if (ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Camera")
                {
                    return
                        name == "AspectRatio" || name == "DestinationRectangle" || name == "CameraModelCullMode";

                }
             
                if (ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Math.Geometry.Polygon")
                {
                    return
                        name == "RotationX" || name == "RotationY" || name == "Points";
                }

                
                if (ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Graphics.Layer")
                {
                    return 
                        name == "LayerCameraSettings";
                }

                if (ati.QualifiedRuntimeTypeName.QualifiedType == "FlatRedBall.Sprite")
                {
                    return
                        name == "AlphaRate" || name == "RedRate" || name == "GreenRate" || name == "BlueRate" ||
                        name == "RelativeTop" || name == "RelativeBottom" || 
                        name == "RelativeLeft" || name == "RelativeRight" ||
                        name == "TimeCreated" || name == "TimeIntoAnimation" ||
                        name == "ScaleX" || name == "ScaleY" || 
                        name == "CurrentChainIndex" ||
                        name == "Top" || name == "Bottom" || name == "Left" || name == "Right" ||
                        name == "PixelSize" ||
                        name == "LeftTextureCoordinate" || name == "RightTextureCoordinate" ||
                        name == "BottomTextureCoordinate" || name == "TopTextureCoordinate" ||
                        name == "ScaleXVelocity" || name == "ScaleYVelocity" ||
                        name == "TextureFilter"
                        ;

                }
            }
            return false;
        }
        private static void WriteLoadedOnlyWhenReferencedPropertyBody(ReferencedFileSave referencedFile, string containerName, IElement element, 
            string contentManagerName, AssetTypeInfo ati, string variableName, string lastContentManagerVariableName, ICodeBlock getBlock)
        {
            string referencedFileName = GetFileToLoadForRfs(referencedFile, ati);


            string mThenVariableName = "m" + variableName;

            ICodeBlock ifBlock = null;
            if (element == null)
            {
                ifBlock = getBlock.If(mThenVariableName + " == null");
            }
            else
            {
                string contentManagerToCompareAgainst;

                if (element is ScreenSave)
                {
                    contentManagerToCompareAgainst = "\"" + FileManager.RemovePath(element.Name) + "\"";
                }
                else
                {
                    contentManagerToCompareAgainst = "ContentManagerName";
                }

                string conditionContents =
                    mThenVariableName + " == null || " + lastContentManagerVariableName + " != " + contentManagerToCompareAgainst;

                bool isDisposable = referencedFile.RuntimeType == "Texture2D" ||
                    referencedFile.RuntimeType == "Microsoft.Xna.Framework.Graphics.Texture2D";
                if (isDisposable)
                {
                    conditionContents += " || " + mThenVariableName + ".IsDisposed";
                }

                ifBlock = getBlock.If(conditionContents);
                ifBlock.Line(lastContentManagerVariableName + " = " + contentManagerToCompareAgainst + ";");
            }

            if (containerName != ContentLoadWriter.GlobalContentContainerName)
            {
                GenerateExceptionForPostInitializeLoads(getBlock);
            }

            PerformancePluginCodeGenerator.CodeBlock = ifBlock;
            PerformancePluginCodeGenerator.SaveObject = element;
            PerformancePluginCodeGenerator.GenerateStart(" Get " + variableName);
            if (ati != null && !referencedFile.IsCsvOrTreatedAsCsv)
            {
                GetLoadCallForAtiFile(referencedFile,
                    ati, mThenVariableName, contentManagerName,
                    ProjectBase.AccessContentDirectory + referencedFileName, ifBlock);
            }
            else if (referencedFile.IsCsvOrTreatedAsCsv)
            {
                GenerateCsvDeserializationCode(referencedFile, ifBlock, mThenVariableName,
                                                referencedFileName, LoadType.CompleteLoad);
            }


            if (element != null && element is EntitySave)
            {
                AppendAddUnloadMethod(ifBlock, containerName);
            }
            PerformancePluginCodeGenerator.GenerateEnd();

            getBlock.Line("return " + mThenVariableName + ";");
        }
        private static string GetFileToLoadForRfs(ReferencedFileSave referencedFile, AssetTypeInfo ati)
        {
            string referencedFileName = referencedFile.Name;

            if ((ati != null && ati.MustBeAddedToContentPipeline) || referencedFile.UseContentPipeline)
            {
                referencedFileName = FileManager.RemoveExtension(referencedFileName);
            }

            if (ProjectManager.ContentProject != null)
            {
                referencedFileName = ProjectManager.ContentProject.ContainedFilePrefix + referencedFileName;
            }

            referencedFileName = referencedFileName.ToLower();
            return referencedFileName;
        }
        private static void AppendPropertyForReferencedFileSave(ICodeBlock codeBlock, ReferencedFileSave referencedFile, string containerName, IElement element, string contentManagerName, AssetTypeInfo ati, string variableName, string typeName)
        {

            codeBlock.Line(StringHelper.Modifiers(Static: referencedFile.IsSharedStatic, Type: typeName, Name: "m" + variableName) + ";");

            // No need to use
            // ManualResetEvents
            // if the ReferencedFileSave
            // is LoadedOnlyWhenReferenced.

            bool shouldBlockThreads = containerName ==
                ContentLoadWriter.GlobalContentContainerName && !referencedFile.LoadedOnlyWhenReferenced;

            if (shouldBlockThreads)
            {
                codeBlock.Line("#if !REQUIRES_PRIMARY_THREAD_LOADING");

                codeBlock.Line("//Blocks the thread on request of " + variableName + " until it has been loaded");
                codeBlock.Line("static ManualResetEvent m" + variableName + "Mre = new ManualResetEvent(false);");

                codeBlock.Line("// Used to lock getter and setter so that " + variableName + " can be set on any thread even if its load is in progrss");
                codeBlock.Line("static object m" + variableName + "_Lock = new object();");
                codeBlock.Line("#endif");

            }

            string lastContentManagerVariableName = "mLastContentManagerFor" + variableName;
            if (referencedFile.LoadedAtRuntime && element != null)
            {
                codeBlock.Line("static string " + lastContentManagerVariableName + ";");
            }

            // Silverlight and Windows Phone only allow reflection on public methods
            // Since it's common practice to use reflection to reference LoadedOnlyWhenReferenced
            // properties, we need to make them public.
            var propBlock = codeBlock.Property(variableName, Public: true, Static: referencedFile.IsSharedStatic, Type: typeName);

            var getBlock = propBlock.Get();

            if (referencedFile.LoadedOnlyWhenReferenced)
            {
                WriteLoadedOnlyWhenReferencedPropertyBody(referencedFile, containerName, element, contentManagerName, ati, variableName, lastContentManagerVariableName, getBlock);
            }
            else if (containerName == ContentLoadWriter.GlobalContentContainerName)
            {
                #region Write the getter


                getBlock.Line("#if !REQUIRES_PRIMARY_THREAD_LOADING");

                if (shouldBlockThreads)
                {
                    getBlock = getBlock.Lock("m" + variableName + "_Lock");
                }

                //Perform a WaitOne on the event with a timeout value of zero.
                // It will return true if the event is not set, or false if the timeout occurs. 
                // In other words, false -> event is set, true -> event is not set.
                getBlock.Line("bool isBlocking = !m" + variableName + "Mre.WaitOne(0);");

                {
                    var ifBlock = getBlock.If("isBlocking");

                    // This is our way of telling the GlobalContentManager to hurry up - we're waiting
                    // on some content!
                    ifBlock.Line("RequestContentLoad(\"" + referencedFile.Name + "\");");

                    #region If RecordLockRecord - write the code for recording the load order so that it can be optimized

                    if (ProjectManager.GlueProjectSave.GlobalContentSettingsSave.RecordLockContention)
                    {
                        ifBlock.Line("LockRecord.Add(\"\\n" + variableName + "\");");
                    }

                    #endregion
                }

                getBlock.Line("m" + variableName + "Mre.WaitOne();");
                getBlock.Line("return m" + variableName + ";");
                if (shouldBlockThreads)
                {
                    getBlock = getBlock.End();
                }
                getBlock.Line("#else");
                WriteLoadedOnlyWhenReferencedPropertyBody(referencedFile, containerName, element, contentManagerName, ati, variableName, lastContentManagerVariableName, getBlock);


                getBlock.Line("#endif");

                #endregion

                #region Write the setter



                var setBlock = propBlock.Set();

                setBlock.Line("#if !REQUIRES_PRIMARY_THREAD_LOADING");

                if (shouldBlockThreads)
                {
                    setBlock = setBlock.Lock("m" + variableName + "_Lock");
                }

                WriteAssignmentAndMreSet(variableName, setBlock);
                if (shouldBlockThreads)
                {
                    setBlock = setBlock.End();
                }
                setBlock.Line("#else");
                setBlock.Line("m" + variableName + " = value;");


                setBlock.Line("#endif");
                #endregion

            }
            else
            {
                string fieldName = "m" + variableName;

                getBlock.Line("#if REQUIRES_PRIMARY_THREAD_LOADING");
                
                var ifBlock = getBlock.If("fieldName == null && FlatRedBall.FlatRedBallServices.IsThreadPrimary()");
                ifBlock.Line("FlatRedBall.FlatRedBallServices.GetContentManagerByName(ContentManager).ProcessTexturesWaitingToBeLoaded();");
                
                getBlock.Line("#endif");

                getBlock.Line("return " + fieldName + ";");
            }
        }
        private static InstanceMember CreateInstanceMember(NamedObjectSave instance, IElement container, TypedMemberBase typedMember, AssetTypeInfo ati)
        {
            bool shouldBeSkipped = GetIfShouldBeSkipped(typedMember, instance, ati);

            DataGridItem instanceMember = null;

            if (!shouldBeSkipped)
            {
                var typeConverter = PluginManager.GetTypeConverter(
                     container, instance, typedMember);

                bool isObjectInFile = typeConverter is IObjectsInFileConverter;

                var memberType = typedMember.MemberType;

                VariableDefinition variableDefinition = null;

                if (ati != null)
                {
                    variableDefinition = ati.VariableDefinitions.FirstOrDefault(item => item.Name == typedMember.MemberName);
                }

                if(isObjectInFile)
                {
                    var fileInstanceMember = new FileInstanceMember();
                    instanceMember = fileInstanceMember;


                    fileInstanceMember.View += () =>
                    {
                        var rfs = (typeConverter as IObjectsInFileConverter).ReferencedFileSave;

                        if (rfs != null)
                        {
                            var value = fileInstanceMember.Value as string;

                            GlueCommands.Self.SelectCommands.Select(
                                rfs,
                                value);
                        }
                    };

                    instanceMember.PreferredDisplayer = typeof(FileReferenceComboBox);

                }
                else
                {
                    instanceMember = new DataGridItem();


                }

                instanceMember.FirstGridLength = new System.Windows.GridLength(140);

                instanceMember.UnmodifiedVariableName = typedMember.MemberName;
                string displayName = StringFunctions.InsertSpacesInCamelCaseString(typedMember.MemberName);
                instanceMember.DisplayName = displayName;

                instanceMember.TypeConverter = typeConverter;

                instanceMember.CustomRefreshOptions += () =>
                {
                    if (typeConverter != null)
                    {
                        instanceMember.CustomOptions.Clear();

                        var values = typeConverter.GetStandardValues();

                        foreach (var value in values)
                        {
                            instanceMember.CustomOptions.Add(value);
                        }
                    }

                };


                instanceMember.CustomGetTypeEvent += (throwaway) => memberType;


                instanceMember.IsDefault = instance.GetInstructionFromMember(typedMember.MemberName) == null;



                instanceMember.CustomGetEvent += (throwaway) =>
                {

                    var instruction = instance.GetInstructionFromMember(typedMember.MemberName);

                    if (instruction == null)
                    {
                        if (variableDefinition != null)
                        {
                            var toReturn = variableDefinition.DefaultValue;
                            if (memberType == typeof(bool))
                            {
                                bool boolToReturn = false;

                                bool.TryParse(variableDefinition.DefaultValue, out boolToReturn);

                                return boolToReturn;
                            }
                            else
                            {
                                return toReturn;
                            }
                        }
                        else
                        {
                            return null;
                        }
                    }
                    else
                    {
                        return instruction.Value;
                    }
                };

                instanceMember.CustomSetEvent += (owner, value) =>
                {
                    NamedObjectVariableChangeLogic.ReactToValueSet(instance, typedMember, value, instanceMember, memberType);
                };

                instanceMember.IsDefaultSet += (owner, args) =>
                    {
                        MakeDefault(instance, typedMember.MemberName);
                    };

                instanceMember.SetValueError += (newValue) =>
                    {
                        if (newValue is string && string.IsNullOrEmpty(newValue as string))
                        {
                            MakeDefault(instance, typedMember.MemberName);
                        }
                    };


            }
            return instanceMember;
        }
Example #55
0
        public string GetOptionFor(AssetTypeInfo ati)
        {
            string type = GetObjectTypeFromAti(ati);

            return GetOptionFor(type);
        }
        private static MemberCategory GetOrCreateCategoryToAddTo(List<MemberCategory> categories, AssetTypeInfo ati, TypedMemberBase typedMember)
        {
            // By defaut make the last category get used (this is "Variables")
            var categoryToAddTo = categories.Last();
            // If there is an AssetTypeInfo...
            if (ati != null)
            {
                // ... see if there is avariable definition for this variable...
                var foundVariableDefinition = ati.VariableDefinitions.FirstOrDefault(item => item.Name == typedMember.MemberName);
                if (foundVariableDefinition != null)
                {
                    //... if so, see the category that it's a part of...
                    string categoryName = foundVariableDefinition.Category;

                    if (!string.IsNullOrEmpty(categoryName))
                    {
                        //... if a category is defined, see if we have a MemberCategory that we've created for it...
                        categoryToAddTo = categories.FirstOrDefault(item => item.Name == categoryName);

                        if (categoryToAddTo == null)
                        {
                            //... if not, make one, and insert it before the last:
                            categoryToAddTo = new MemberCategory(categoryName);
                            categoryToAddTo.FontSize = 14;

                            categories.Insert(categories.Count - 1, categoryToAddTo);
                        }
                    }
                }
            }
            return categoryToAddTo;
        }
Example #57
0
        public static ICodeBlock GetLoadCallsForRfs(ReferencedFileSave referencedFile, string fileName, AssetTypeInfo ati, string variableName, ICodeBlock codeBlock, bool useGlobalContent, bool isContentPipeline)
        {
            var currentBlock = codeBlock;
            if (referencedFile.IsCsvOrTreatedAsCsv == false)
            {
                string modifiedFileName = fileName.ToLower();

                string contentManagerString = GetContentManagerString(referencedFile);

                string fileNameToLoad = ProjectBase.AccessContentDirectory + modifiedFileName;

                // If the file isn't part of the content pipeline we have
                // to manually unload it
                if (!useGlobalContent && !isContentPipeline)
                {
                    currentBlock = currentBlock
                        .If(string.Format("!FlatRedBall.FlatRedBallServices.IsLoaded<{2}>(@\"{0}\", {1})", ProjectBase.AccessContentDirectory + modifiedFileName, contentManagerString, ati.QualifiedRuntimeTypeName.QualifiedType));
                    if (referencedFile.GetContainerType() == ContainerType.Entity)
                    {
                        currentBlock.Line("registerUnload = true;");
                    }

                    currentBlock = currentBlock.End();
                }

                ReferencedFileSaveCodeGenerator.GetLoadCallForAtiFile(referencedFile,  ati, variableName, contentManagerString, fileNameToLoad, codeBlock);
            }
            return currentBlock;
        }
        public static ReferencedFileSave AddReferencedFile(this IElement instance, string fileName, AssetTypeInfo ati, EditorObjects.SaveClasses.BuildToolAssociation bta = null)
        {

            var referencedFileSave = new ReferencedFileSave();

            if (ati != null)
            {
                referencedFileSave.RuntimeType = ati.QualifiedRuntimeTypeName.QualifiedType;
            }




            referencedFileSave.IsSharedStatic = true;

            referencedFileSave.SetNameNoCall(fileName);
#if GLUE
            if (ati != null && !string.IsNullOrEmpty(ati.CustomBuildToolName) && bta != null)
            {
                referencedFileSave.BuildTool = ati.CustomBuildToolName;

                referencedFileSave.SourceFile = referencedFileSave.Name;

                string newName = FileManager.RemoveExtension(referencedFileSave.Name);
                newName += "." + bta.DestinationFileType;

                referencedFileSave.SetNameNoCall(newName);
            }
#endif
            instance.ReferencedFiles.Add(referencedFileSave);


            referencedFileSave.IsSharedStatic = true;


            return referencedFileSave;
        }
Example #59
0
        internal static string CreateNewFile(AssetTypeInfo assetTypeInfo, object extraData, string directory, string name)
        {
            string createdFile = null;
            bool created = false;

            foreach (PluginManager pluginManager in mInstances)
            {
                if (created)
                {
                    break;
                }

                foreach (INewFile plugin in pluginManager.NewFilePlugins)
                {
                    PluginContainer container = pluginManager.mPluginContainers[plugin];

                    if (container.IsEnabled)
                    {
                        var exit = false;

                        INewFile plugin1 = plugin;
                        PluginCommand(() =>
                                          {
                                              if (plugin1.CreateNewFile(assetTypeInfo, extraData, directory, name, out createdFile))
                                              {
                                                  created = true;
                                                  exit = true;
                                              }
                                          }, container, "Failed in CreateNewFile");

                        if (exit) break;
                    }
                }

                // Execute the new style plugins
                if (!created)
                {
                    var plugins = pluginManager.ImportedPlugins.Where(x => x.CreateNewFileHandler != null);
                    foreach (var plugin in plugins)
                    {
                        var container = pluginManager.mPluginContainers[plugin];
                        if (container.IsEnabled)
                        {
                            PluginBase plugin1 = plugin;
                            bool exit = false;
                            PluginCommand(() =>
                                              {
                                                  if (plugin1.CreateNewFileHandler(assetTypeInfo, extraData, directory, name, out createdFile))
                                                  {
                                                      created = true;
                                                      exit = true;
                                                  }
                                              }, container, "Failed in CreateNewFile");

                            if (exit) break;
                        }
                    }
                }
            }

            return createdFile;
        }
        private static void WriteCopyToAbsoluteInInitializeCode(NamedObjectSave namedObject, ICodeBlock codeBlock, List<string[]> referencedFilesAlreadyUsingFullFile, AssetTypeInfo ati, string objectName, ReferencedFileSave rfs)
        {
            if ((ati != null && ati.ShouldAttach) ||
                namedObject.SourceType == SourceType.Entity &&
                !string.IsNullOrEmpty(namedObject.SourceClassType)
                )
            {
                bool isEntireFile = namedObject.SourceName != null && namedObject.SourceName.StartsWith("Entire File (");
                string copyRelativeToAbsolute;

                if (namedObject.InstanceType == "Scene" ||
                    namedObject.InstanceType == "ShapeCollection"
                    )
                {
                    copyRelativeToAbsolute = ".CopyAbsoluteToRelative(false)";
                }
                else
                {
                    copyRelativeToAbsolute = ".CopyAbsoluteToRelative()";
                }
                string namedObjectToPullFrom = null;


                if (rfs != null)
                {
                    foreach (string[] stringPair in referencedFilesAlreadyUsingFullFile)
                    {
                        if (stringPair[0] == rfs.Name && !isEntireFile)
                        {
                            namedObjectToPullFrom = stringPair[1];
                            break;
                        }
                    }
                }

                if (string.IsNullOrEmpty(namedObjectToPullFrom))
                {
                    codeBlock.Line(string.Format("{0}{1};",
                                                 objectName,
                                                 copyRelativeToAbsolute));
                }
            }
        }