Esempio n. 1
0
        public static SceneSave FromFile(string fileName)
        {
            SceneSave tempScene = null;

#if !FRB_MDX
            if (ManualDeserialization)
            {
                tempScene = DeserializeManually(fileName);
            }
            else
#endif
            {
                tempScene = FileManager.XmlDeserialize <SceneSave>(fileName);
            }

            tempScene.mFileName = fileName;
            if (FileManager.IsRelative(fileName))
            {
                tempScene.mSceneDirectory = FileManager.GetDirectory(FileManager.RelativeDirectory + fileName);
            }
            else
            {
                tempScene.mSceneDirectory = FileManager.GetDirectory(fileName);
            }


            return(tempScene);
        }
Esempio n. 2
0
        public void AddNonDisposable(string objectName, object objectToAdd)
        {
            if (FileManager.IsRelative(objectName))
            {
                objectName = FileManager.MakeAbsolute(objectName);
            }

            string modifiedName = objectName + objectToAdd.GetType().Name;

            bool shouldAdd = true;

            if (mNonDisposableDictionary.ContainsKey(modifiedName))
            {
                var existing = objectToAdd;
                if (existing != objectToAdd)
                {
                    throw new InvalidOperationException($"The name {objectName} is already taken by {objectToAdd}");
                }
                else
                {
                    shouldAdd = false;
                }
            }

            if (shouldAdd)
            {
                mNonDisposableDictionary.Add(modifiedName, objectToAdd);
            }
        }
Esempio n. 3
0
        public List <SourceReferencingFile> GetSourceReferencingReferencedFiles(RelativeType relativeType)
        {
            List <SourceReferencingFile> referencedFiles = new List <SourceReferencingFile>();

            if (relativeType == RelativeType.Absolute)
            {
                string directory = this.ScenePath;

                string oldRelativeDirectory = FileManager.RelativeDirectory;
                FileManager.RelativeDirectory = directory;

                for (int i = 0; i < referencedFiles.Count; i++)
                {
                    referencedFiles[i].SourceFile =
                        FileManager.MakeAbsolute(referencedFiles[i].SourceFile);

                    referencedFiles[i].DestinationFile =
                        FileManager.MakeAbsolute(referencedFiles[i].DestinationFile);
                }

                FileManager.RelativeDirectory = oldRelativeDirectory;
            }

            return(referencedFiles);
        }
Esempio n. 4
0
        private static AnimationChainListSave DeserializeManually(string fileName)
        {
            AnimationChainListSave toReturn = new AnimationChainListSave();

            System.Xml.Linq.XDocument xDocument = null;

            using (var stream = FileManager.GetStreamForFile(fileName))
            {
                xDocument = System.Xml.Linq.XDocument.Load(stream);
            }

            System.Xml.Linq.XElement foundElement = null;

            foreach (var element in xDocument.Elements())
            {
                if (element.Name.LocalName == "AnimationChainArraySave")
                {
                    foundElement = element;
                    break;
                }
            }

            LoadFromElement(toReturn, foundElement);

            return(toReturn);
        }
Esempio n. 5
0
        public bool IsAssetLoadedByName <T>(string assetName)
        {
            if (FileManager.IsRelative(assetName))
            {
                assetName = FileManager.MakeAbsolute(assetName);
            }

            assetName = FileManager.Standardize(assetName);

            string combinedName = assetName + typeof(T).Name;

            if (mDisposableDictionary.ContainsKey(combinedName))
            {
                return(true);
            }
            else if (mNonDisposableDictionary.ContainsKey(combinedName))
            {
                return(true);
            }

            else if (mAssets.ContainsKey(combinedName))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 6
0
        public static void SaveContentLoadingHistory(string fileToSaveTo)
        {
            StringBuilder stringBuilder = new StringBuilder();

            foreach (ContentLoadHistory clh in mHistory)
            {
                if (!string.IsNullOrEmpty(clh.SpecialEvent))
                {
                    stringBuilder.AppendLine("========================================");
                    stringBuilder.AppendLine(clh.SpecialEvent);
                    stringBuilder.AppendLine("========================================");
                    stringBuilder.AppendLine();
                }
                else
                {
                    stringBuilder.AppendLine("Time:\t\t" + clh.Time);
                    stringBuilder.AppendLine("Content Type:\t" + clh.Type);
                    stringBuilder.AppendLine("Content Name:\t" + clh.ContentName);
                    stringBuilder.AppendLine("Detail:\t\t" + clh.ContentLoadDetail);
                    stringBuilder.AppendLine();
                }
            }

            FileManager.SaveText(stringBuilder.ToString(), fileToSaveTo);
        }
Esempio n. 7
0
        public void Save(string fileName)
        {
            if (FileRelativeTextures)
            {
                MakeRelative(fileName);
            }

            FileManager.XmlSerialize(this, fileName);
        }
Esempio n. 8
0
        public void AddNonDisposable(string objectName, object objectToAdd)
        {
            if (FileManager.IsRelative(objectName))
            {
                objectName = FileManager.MakeAbsolute(objectName);
            }

            string modifiedName = objectName + objectToAdd.GetType().Name;

            mNonDisposableDictionary.Add(modifiedName, objectToAdd);
        }
Esempio n. 9
0
        // This used to be internal - making it public since users use this
        public T GetNonDisposable <T>(string objectName)
        {
            if (FileManager.IsRelative(objectName))
            {
                objectName = FileManager.MakeAbsolute(objectName);
            }

            objectName += typeof(T).Name;

            return((T)mNonDisposableDictionary[objectName]);
        }
Esempio n. 10
0
        public AnimationChainList ToAnimationChainList(string contentManagerName, bool throwError)
        {
            mToRuntimeErrors.Clear();

            AnimationChainList list = new AnimationChainList();

            list.FileRelativeTextures = FileRelativeTextures;
            list.TimeMeasurementUnit  = TimeMeasurementUnit;
            list.Name = mFileName;

            string oldRelativeDirectory = FileManager.RelativeDirectory;

            try
            {
                if (this.FileRelativeTextures)
                {
                    FileManager.RelativeDirectory = FileManager.GetDirectory(mFileName);
                }

                foreach (AnimationChainSave animationChain in this.AnimationChains)
                {
                    try
                    {
                        FlatRedBall.Graphics.Animation.AnimationChain newChain = null;

                        newChain = animationChain.ToAnimationChain(contentManagerName, this.TimeMeasurementUnit, this.CoordinateType);

                        newChain.mIndexInLoadedAchx = list.Count;

                        newChain.ParentAchxFileName = mFileName;

                        list.Add(newChain);
                    }
                    catch (Exception e)
                    {
                        mToRuntimeErrors.Add(e.ToString());
                        if (throwError)
                        {
                            throw new Exception("Error loading AnimationChain", e);
                        }
                    }
                }
            }
            finally
            {
                FileManager.RelativeDirectory = oldRelativeDirectory;
            }

            return(list);
        }
Esempio n. 11
0
		// Ok, let's explain why this method uses the "new" keyword.
		// In the olden days (before September 2009) the user would call
		// FlatRedBallServices.Load<TypeToLoad> which would investigate whether
		// the user passed an assetName that had an extension or not.  Then the
		// FlatRedBallServices class would call LoadFromFile or LoadFromProject
		// depending on the presence of an extension.
		//
		// In an effort to reduce the responsibilities of the FlatRedBallServices
		// class, Vic decided to move the loading code (including the logic that branches
		// depending on whether an asset has an extension) into the ContentManager class.
		// To keep things simple, the FlatRedBallServices just has to call Load and the Load
		// method will do the branching inside the ContentManager class.  That all worked well,
		// except that the branching code also "standardizes" the name, which means it turns relative
		// paths into absolute paths.  The reason this is a problem is IF the user loads an object (such
		// as a .X file) which references another file, then the Load method will be called again on the referenced
		// asset name.
		//
		// The FRB ContentManager doesn't use relative directories - instead, it makes all assets relative to the .exe
		// by calling Standardize.  However, if Load is called by XNA code (such as when loading a .X file)
		// then any files referenced by the X will come in already made relative to the ContentManager.  
		// This means that if a .X file was "Content\myModel" and it referenced myTexture.png which was in the same
		// folder as the .X file, then Load would get called with "Content\myTexture" as the argument.  That is, the .X loading
		// code would already prepend "Content\" before "myTexture.  But the FRB content manager wouldn't know this, and it'd
		// try to standardize it as well, making the file "Content\Content\myTexture."
		//
		// So the solution?  We make Load a "new" method.  That means that if Load is called by XNA, then it'll call the
		// Load of XNA's ContentManager.  But if FRB calls it, it'll call the "new" version.  Problem solved.
		public new T Load<T>(string assetName)
		{
            var standardized = FileManager.Standardize(assetName);

            if(FileAliases.ContainsKey(standardized))
            {
                assetName = FileAliases[standardized];
            }

			// Assets can be loaded either from file or from assets referenced
			// in the project.
			string extension = FileManager.GetExtension(assetName);

            #region If there is an extension, loading from file or returning an already-loaded asset
			assetName = FileManager.Standardize(assetName);

			if (extension != String.Empty)
			{
				return LoadFromFile<T>(assetName);
			}

#endregion

            #region Else there is no extension, so the file is already part of the project.  Use a ContentManager
			else
			{
#if PROFILE
				bool exists = false;

				exists = IsAssetLoadedByName<T>(assetName);
				
				if (exists)
				{
					mHistory.Add(new ContentLoadHistory(
						TimeManager.CurrentTime, typeof(T).Name, assetName, ContentLoadDetail.Cached));
				}
				else
				{
					mHistory.Add(new ContentLoadHistory(
						TimeManager.CurrentTime, typeof(T).Name, assetName, ContentLoadDetail.HddFromContentPipeline));
				}
#endif



				return LoadFromProject<T>(assetName);
			}
#endregion

		}
Esempio n. 12
0
        //AnimationChainList ToAnimationChainList(string contentManagerName, TextureAtlas textureAtlas, bool throwError)
        //{
        //    mToRuntimeErrors.Clear();

        //    AnimationChainList list = new AnimationChainList();

        //    list.FileRelativeTextures = FileRelativeTextures;
        //    list.TimeMeasurementUnit = TimeMeasurementUnit;
        //    list.Name = mFileName;

        //    string oldRelativeDirectory = FileManager.RelativeDirectory;

        //    try
        //    {
        //        if (this.FileRelativeTextures)
        //        {
        //            FileManager.RelativeDirectory = FileManager.GetDirectory(mFileName);
        //        }

        //        foreach (AnimationChainSave animationChain in this.AnimationChains)
        //        {
        //            try
        //            {
        //                FlatRedBall.Graphics.Animation.AnimationChain newChain = null;

        //                if (textureAtlas == null)
        //                {
        //                    newChain = animationChain.ToAnimationChain(contentManagerName, this.TimeMeasurementUnit, this.CoordinateType);
        //                }
        //                else
        //                {
        //                    newChain = animationChain.ToAnimationChain(textureAtlas, this.TimeMeasurementUnit);
        //                }
        //                newChain.mIndexInLoadedAchx = list.Count;

        //                newChain.ParentAchxFileName = mFileName;

        //                list.Add(newChain);

        //            }
        //            catch (Exception e)
        //            {
        //                mToRuntimeErrors.Add(e.ToString());
        //                if (throwError)
        //                {
        //                    throw new Exception("Error loading AnimationChain", e);
        //                }
        //            }
        //        }
        //    }
        //    finally
        //    {
        //        FileManager.RelativeDirectory = oldRelativeDirectory;
        //    }

        //    return list;


        //}


        //public AnimationChainList ToAnimationChainList(Graphics.Texture.TextureAtlas textureAtlas)
        //{
        //    return ToAnimationChainList(null, textureAtlas, true);
        //}


        private void MakeRelative(string fileName)
        {
            string oldRelativeDirectory = FileManager.RelativeDirectory;

            string newRelativeDirectory = FileManager.GetDirectory(fileName);

            FileManager.RelativeDirectory = newRelativeDirectory;

            foreach (AnimationChainSave acs in AnimationChains)
            {
                acs.MakeRelative();
            }

            FileManager.RelativeDirectory = oldRelativeDirectory;
        }
Esempio n. 13
0
 public void SetSceneDirectory()
 {
     if (string.IsNullOrEmpty(mFileName))
     {
         return;
     }
     if (FileManager.IsRelative(mFileName))
     {
         mSceneDirectory = FileManager.GetDirectory(FileManager.RelativeDirectory + mFileName);
     }
     else
     {
         mSceneDirectory = FileManager.GetDirectory(mFileName);
     }
 }
Esempio n. 14
0
        public void Save(string fileName)
        {
#if FRB_MDX
            CoordinateSystem = FlatRedBall.Math.CoordinateSystem.LeftHanded;
#else
            CoordinateSystem = FlatRedBall.Math.CoordinateSystem.RightHanded;
#endif

            if (AssetsRelativeToSceneFile)
            {
                MakeAssetsRelative(fileName);
            }

            AssignNamesIfEmptyOrNull();

            FileManager.XmlSerialize(this, fileName);
        }
Esempio n. 15
0
        public void AddDisposable(string disposableName, IDisposable disposable)
        {
            if (FileManager.IsRelative(disposableName))
            {
                disposableName = FileManager.MakeAbsolute(disposableName);
            }

            disposableName = FileManager.Standardize(disposableName);

            string modifiedName = disposableName + disposable.GetType().Name;



            lock (mDisposableDictionary)
            {
                mDisposableDictionary.Add(modifiedName, disposable);
            }
        }
Esempio n. 16
0
        public List <string> GetReferencedFiles(RelativeType relativeType)
        {
            List <string> referencedFiles = new List <string>();

            foreach (AnimationChainSave acs in this.AnimationChains)
            {
                //if(acs.ParentFile
                if (acs.ParentFile != null && acs.ParentFile.EndsWith(".gif"))
                {
                    referencedFiles.Add(acs.ParentFile);
                }
                else
                {
                    foreach (AnimationFrameSave afs in acs.Frames)
                    {
                        string texture = FileManager.Standardize(afs.TextureName, null, false);

                        if (FileManager.GetExtension(texture).StartsWith("gif"))
                        {
                            texture = FileManager.RemoveExtension(texture) + ".gif";
                        }

                        if (!string.IsNullOrEmpty(texture) && !referencedFiles.Contains(texture))
                        {
                            referencedFiles.Add(texture);
                        }
                    }
                }
            }


            if (relativeType == RelativeType.Absolute)
            {
                string directory = FileManager.GetDirectory(FileName);

                for (int i = 0; i < referencedFiles.Count; i++)
                {
                    referencedFiles[i] = directory + referencedFiles[i];
                }
            }

            return(referencedFiles);
        }
Esempio n. 17
0
        public static AnimationChainListSave FromFile(string fileName)
        {
            AnimationChainListSave toReturn = null;

            if (ManualDeserialization)
            {
                toReturn = DeserializeManually(fileName);
            }
            else
            {
                toReturn =
                    FileManager.XmlDeserialize <AnimationChainListSave>(fileName);
            }

            if (FileManager.IsRelative(fileName))
            {
                fileName = FileManager.MakeAbsolute(fileName);
            }

            toReturn.mFileName = fileName;

            return(toReturn);
        }
Esempio n. 18
0
        public List <string> GetMissingFiles()
        {
            List <string> texturesNotFound = new List <string>();

            // Get a list of all files that this .scnx references.  This won't return any duplicates
            List <string> allReferencedFiles = GetReferencedFiles(RelativeType.Relative);

            #region Set the FileManager.RelativeDirectory if necessary

            string oldRelativeDirectory = FileManager.RelativeDirectory;
            if (AssetsRelativeToSceneFile)
            {
                if (string.IsNullOrEmpty(ScenePath))
                {
                    throw new Exception("You must set ScenePath first before attempting to find missing files");
                }
                FileManager.RelativeDirectory = mSceneDirectory;
            }
            #endregion

            for (int i = 0; i < allReferencedFiles.Count; i++)
            {
                if (!FileManager.FileExists(allReferencedFiles[i]))
                {
                    texturesNotFound.Add(allReferencedFiles[i]);
                }
            }

            #region Set the FileManager.RelativeDirectory back to its old value

            FileManager.RelativeDirectory = oldRelativeDirectory;

            #endregion

            return(texturesNotFound);
        }
Esempio n. 19
0
        public T LoadFromFile <T>(string assetName)
        {
            string extension = FileManager.GetExtension(assetName);

            if (FileManager.IsRelative(assetName))
            {
                // get the absolute path using the current relative directory
                assetName = FileManager.RelativeDirectory + assetName;
            }



            string fullNameWithType = assetName + typeof(T).Name;


            // get the dictionary by the contentManagerName.  If it doesn't exist, GetDisposableDictionaryByName
            // will create it.

            if (mDisposableDictionary.ContainsKey(fullNameWithType))
            {
#if PROFILE
                mHistory.Add(new ContentLoadHistory(
                                 TimeManager.CurrentTime, typeof(T).Name, fullNameWithType, ContentLoadDetail.Cached));
#endif

                return((T)mDisposableDictionary[fullNameWithType]);
            }
            else if (mNonDisposableDictionary.ContainsKey(fullNameWithType))
            {
                return((T)mNonDisposableDictionary[fullNameWithType]);
            }
            else
            {
#if PROFILE
                mHistory.Add(new ContentLoadHistory(
                                 TimeManager.CurrentTime,
                                 typeof(T).Name,
                                 fullNameWithType,
                                 ContentLoadDetail.HddFromFile));
#endif
#if DEBUG
                // The ThrowExceptionIfFileDoesntExist
                // call used to be done before the checks
                // in the dictionaries.  But whatever is held
                // in there may not really be a file so let's check
                // if the file exists after we check the dictionaries.
                FileManager.ThrowExceptionIfFileDoesntExist(assetName);
#endif

                IDisposable loadedAsset = null;

                if (typeof(T) == typeof(Texture2D) || typeof(T) == typeof(Microsoft.Xna.Framework.Graphics.Texture2D))
                {
                    // for now we'll create it here, eventually have it in a dictionary:
                    loadedAsset = textureContentLoader.Load(assetName);
                }

                #region Scene

                else if (typeof(T) == typeof(FlatRedBall.Scene))
                {
                    FlatRedBall.Scene scene = FlatRedBall.Content.Scene.SceneSave.FromFile(assetName).ToScene(mName);

                    object sceneAsObject = scene;

                    lock (mNonDisposableDictionary)
                    {
                        if (!mNonDisposableDictionary.ContainsKey(fullNameWithType))
                        {
                            mNonDisposableDictionary.Add(fullNameWithType, scene);
                        }
                    }
                    return((T)sceneAsObject);
                }

                #endregion

                #region EmitterList

                else if (typeof(T) == typeof(EmitterList))
                {
                    EmitterList emitterList = EmitterSaveList.FromFile(assetName).ToEmitterList(mName);


                    mNonDisposableDictionary.Add(fullNameWithType, emitterList);


                    return((T)((object)emitterList));
                }

                #endregion

                #region Image
#if !MONOGAME
                else if (typeof(T) == typeof(Image))
                {
                    switch (extension.ToLowerInvariant())
                    {
                    case "gif":
                        Image image = Image.FromFile(assetName);
                        loadedAsset = image;
                        break;
                    }
                }
#endif
                #endregion

                #region BitmapList
#if !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !MONOGAME
                else if (typeof(T) == typeof(BitmapList))
                {
                    loadedAsset = BitmapList.FromFile(assetName);
                }
#endif

                #endregion

                #region NodeNetwork
                else if (typeof(T) == typeof(NodeNetwork))
                {
                    NodeNetwork nodeNetwork = NodeNetworkSave.FromFile(assetName).ToNodeNetwork();

                    mNonDisposableDictionary.Add(fullNameWithType, nodeNetwork);

                    return((T)((object)nodeNetwork));
                }
                #endregion

                #region ShapeCollection

                else if (typeof(T) == typeof(ShapeCollection))
                {
                    ShapeCollection shapeCollection =
                        ShapeCollectionSave.FromFile(assetName).ToShapeCollection();

                    mNonDisposableDictionary.Add(fullNameWithType, shapeCollection);

                    return((T)((object)shapeCollection));
                }
                #endregion

                #region PositionedObjectList<Polygon>

                else if (typeof(T) == typeof(PositionedObjectList <FlatRedBall.Math.Geometry.Polygon>))
                {
                    PositionedObjectList <FlatRedBall.Math.Geometry.Polygon> polygons =
                        PolygonSaveList.FromFile(assetName).ToPolygonList();
                    mNonDisposableDictionary.Add(fullNameWithType, polygons);
                    return((T)((object)polygons));
                }

                #endregion

                #region AnimationChainList

                else if (typeof(T) == typeof(AnimationChainList))
                {
                    if (assetName.EndsWith("gif"))
                    {
#if WINDOWS_8 || UWP || DESKTOP_GL
                        throw new NotImplementedException();
#else
                        AnimationChainList acl = new AnimationChainList();
                        acl.Add(FlatRedBall.Graphics.Animation.AnimationChain.FromGif(assetName, this.mName));
                        acl[0].ParentGifFileName = assetName;
                        loadedAsset = acl;
#endif
                    }
                    else
                    {
                        loadedAsset =
                            AnimationChainListSave.FromFile(assetName).ToAnimationChainList(mName);
                    }

                    mNonDisposableDictionary.Add(fullNameWithType, loadedAsset);
                }

                #endregion

                else if (typeof(T) == typeof(Song))
                {
                    var loader = new SongLoader();
                    return((T)(object)loader.Load(assetName));
                }
#if MONOGAME
                else if (typeof(T) == typeof(SoundEffect))
                {
                    T soundEffect;

                    if (assetName.StartsWith(@".\") || assetName.StartsWith(@"./"))
                    {
                        soundEffect = base.Load <T>(assetName.Substring(2));
                    }
                    else
                    {
                        soundEffect = base.Load <T>(assetName);
                    }

                    return(soundEffect);
                }
#endif

                #region RuntimeCsvRepresentation

#if !SILVERLIGHT
                else if (typeof(T) == typeof(RuntimeCsvRepresentation))
                {
#if XBOX360
                    throw new NotImplementedException("Can't load CSV from file.  Try instead to use the content pipeline.");
#else
                    return((T)((object)CsvFileManager.CsvDeserializeToRuntime(assetName)));
#endif
                }
#endif


                #endregion

                #region SplineList

                else if (typeof(T) == typeof(List <Spline>))
                {
                    List <Spline> splineList = SplineSaveList.FromFile(assetName).ToSplineList();
                    mNonDisposableDictionary.Add(fullNameWithType, splineList);
                    object asObject = splineList;

                    return((T)asObject);
                }

                else if (typeof(T) == typeof(SplineList))
                {
                    SplineList splineList = SplineSaveList.FromFile(assetName).ToSplineList();
                    mNonDisposableDictionary.Add(fullNameWithType, splineList);
                    object asObject = splineList;

                    return((T)asObject);
                }

                #endregion

                #region BitmapFont

                else if (typeof(T) == typeof(BitmapFont))
                {
                    // We used to assume the texture is named the same as the font file
                    // But now FRB understands the .fnt file and gets the PNG from the font file
                    //string pngFile = FileManager.RemoveExtension(assetName) + ".png";
                    string fntFile = FileManager.RemoveExtension(assetName) + ".fnt";

                    BitmapFont bitmapFont = new BitmapFont(fntFile, this.mName);

                    object bitmapFontAsObject = bitmapFont;

                    return((T)bitmapFontAsObject);
                }

                #endregion


                #region Text

                else if (typeof(T) == typeof(string))
                {
                    return((T)((object)FileManager.FromFileText(assetName)));
                }

                #endregion

                #region Catch mistakes

#if DEBUG
                else if (typeof(T) == typeof(Spline))
                {
                    throw new Exception("Cannot load Splines.  Try using the List<Spline> type instead.");
                }
                else if (typeof(T) == typeof(Emitter))
                {
                    throw new Exception("Cannot load Emitters.  Try using the EmitterList type instead.");
                }
#endif

                #endregion

                #region else, exception!

                else
                {
                    throw new NotImplementedException("Cannot load content of type " +
                                                      typeof(T).AssemblyQualifiedName + " from file.  If you are loading " +
                                                      "through the content pipeline be sure to remove the extension of the file " +
                                                      "name.");
                }

                #endregion

                if (loadedAsset != null)
                {
                    lock (mDisposableDictionary)
                    {
                        // Multiple threads could try to load this content simultaneously
                        if (!mDisposableDictionary.ContainsKey(fullNameWithType))
                        {
                            mDisposableDictionary.Add(fullNameWithType, loadedAsset);
                        }
                    }
                }

                return((T)loadedAsset);
            }
        }
Esempio n. 20
0
        public T LoadFromProject <T>(string assetName)
        {
            string oldRelativePath = FileManager.RelativeDirectory;

            FlatRedBall.IO.FileManager.RelativeDirectory = FileManager.GetDirectory(assetName);



        #if DEBUG
            bool shouldCheckForXnb = true;

                #if ANDROID
            if (typeof(T) == typeof(Song))
            {
                shouldCheckForXnb = false;
            }
                #endif


            string fileToCheckFor = assetName + ".xnb";


            if (shouldCheckForXnb && !FileManager.FileExists(fileToCheckFor))
            {
                string errorString = "Could not find the file " + fileToCheckFor + "\n";

        #if !WINDOWS_8
                List <string> filesInDirectory = FileManager.GetAllFilesInDirectory(FileManager.GetDirectory(assetName), null, 0);

                errorString += "Found the following files:\n\n";

                foreach (string s in filesInDirectory)
                {
                    errorString += FileManager.RemovePath(s) + "\n";
                }
        #endif
                throw new FileNotFoundException(errorString);
            }
        #endif

        #if XNA4 && !MONOGAME
            if (!FileManager.IsRelative(assetName))
            {
                assetName = FileManager.MakeRelative(
                    assetName, System.Windows.Forms.Application.StartupPath + "/");
            }
        #endif

        #if USES_DOT_SLASH_ABOLUTE_FILES
            T asset;

            if (assetName.StartsWith(@".\") || assetName.StartsWith(@"./"))
            {
                asset = base.Load <T>(assetName.Substring(2));
            }
            else
            {
                asset = base.Load <T>(assetName);
            }
        #else
            T asset = base.Load <T>(assetName);
        #endif
            if (!mAssets.ContainsKey(assetName))
            {
                mAssets.Add(assetName, asset);
            }

            FileManager.RelativeDirectory = oldRelativePath;

            return(AdjustNewAsset(asset, assetName));
        }
Esempio n. 21
0
        public List <string> GetReferencedFiles(RelativeType relativeType)
        {
            List <string> referencedFiles = new List <string>();

            foreach (SpriteSave spriteSave in SpriteList)
            {
                spriteSave.GetReferencedFiles(referencedFiles);
            }

            foreach (SpriteGridSave spriteGridSave in SpriteGridList)
            {
                if (!string.IsNullOrEmpty(spriteGridSave.BaseTexture) && !referencedFiles.Contains(spriteGridSave.BaseTexture))
                {
                    referencedFiles.Add(spriteGridSave.BaseTexture);
                }

                foreach (string[] stringArray in spriteGridSave.GridTexturesArray)
                {
                    foreach (string texture in stringArray)
                    {
                        if (!string.IsNullOrEmpty(texture) && !referencedFiles.Contains(texture))
                        {
                            referencedFiles.Add(texture);
                        }
                    }
                }
            }

            foreach (SpriteFrameSave spriteFrameSave in SpriteFrameSaveList)
            {
                if (!string.IsNullOrEmpty(spriteFrameSave.ParentSprite.Texture) &&
                    !referencedFiles.Contains(spriteFrameSave.ParentSprite.Texture))
                {
                    referencedFiles.Add(spriteFrameSave.ParentSprite.Texture);
                }

                if (!string.IsNullOrEmpty(spriteFrameSave.ParentSprite.AnimationChainsFile) &&
                    !referencedFiles.Contains(spriteFrameSave.ParentSprite.AnimationChainsFile))
                {
                    referencedFiles.Add(spriteFrameSave.ParentSprite.AnimationChainsFile);
                }
            }

            foreach (TextSave textSave in TextSaveList)
            {
                string fontFile         = textSave.FontFile;
                bool   isThereAFontFile = !string.IsNullOrEmpty(fontFile);
                if (isThereAFontFile &&
                    !referencedFiles.Contains(fontFile))
                {
                    referencedFiles.Add(fontFile);
                }


                string textureFile = textSave.FontTexture;
                if (!string.IsNullOrEmpty(textureFile))
                {
                    if (!referencedFiles.Contains(textureFile))
                    {
                        referencedFiles.Add(textureFile);
                    }
                }
                else if (isThereAFontFile)
                {
                    // This may be a multi-texture font, so let's check for that
                    string absoluteFontDirectory = this.mSceneDirectory + fontFile;

                    if (FileManager.FileExists(absoluteFontDirectory))
                    {
                        string fontDirectory = FileManager.GetDirectory(fontFile, FlatRedBall.IO.RelativeType.Relative);

                        string contents = FileManager.FromFileText(absoluteFontDirectory);

                        string[] textures = BitmapFont.GetSourceTextures(contents);

                        for (int i = 0; i < textures.Length; i++)
                        {
                            string textureWithFontFileDirectory = textures[i];

                            //make the texture hae the font file's directory
                            textureWithFontFileDirectory = fontDirectory + textureWithFontFileDirectory;


                            if (!referencedFiles.Contains(textureWithFontFileDirectory))
                            {
                                referencedFiles.Add(textureWithFontFileDirectory);
                            }
                        }
                    }
                }
            }

            if (relativeType == RelativeType.Absolute)
            {
                string directory = this.ScenePath;

                for (int i = 0; i < referencedFiles.Count; i++)
                {
                    if (FileManager.IsRelative(referencedFiles[i]))
                    {
                        referencedFiles[i] = directory + referencedFiles[i];
                    }
                }
            }

            return(referencedFiles);
        }
Esempio n. 22
0
        private void MakeAssetsRelative(string fileName)
        {
            string oldRelativeDirectory = FileManager.RelativeDirectory;

            if (FileManager.IsRelative(fileName))
            {
                fileName = FileManager.MakeAbsolute(fileName);
            }
            FileManager.RelativeDirectory = FileManager.GetDirectory(fileName);


            #region SpriteSave - Make textures relative
            foreach (SpriteSave ss in SpriteList)
            {
                ss.MakeRelative();
            }
            #endregion


            #region SpriteFrameSave - Make the textures relative

            foreach (SpriteFrameSave sfs in SpriteFrameSaveList)
            {
                sfs.ParentSprite.Texture = FileManager.MakeRelative(sfs.ParentSprite.Texture);

                if (string.IsNullOrEmpty(sfs.ParentSprite.AnimationChainsFile) == false)
                {
                    sfs.ParentSprite.AnimationChainsFile =
                        FileManager.MakeRelative(sfs.ParentSprite.AnimationChainsFile);
                }
            }

            #endregion


            #region SpriteGridSave - Make textures realtive
            foreach (SpriteGridSave sgs in SpriteGridList)
            {
                sgs.BaseTexture       = FileManager.MakeRelative(sgs.BaseTexture);
                sgs.Blueprint.Texture = FileManager.MakeRelative(sgs.Blueprint.Texture);
                foreach (string[] row in sgs.GridTexturesArray)
                {
                    for (int i = 0; i < row.Length; i++)
                    {
                        row[i] = FileManager.MakeRelative(row[i]);
                    }
                }

                if (sgs.AnimationChainGridSave != null)
                {
                    sgs.AnimationChainGridSave.MakeRelative();
                }
            }
            #endregion

            #region TextSaves - Make textures and .fnt files relative

            foreach (TextSave textSave in TextSaveList)
            {
                textSave.FontTexture = FileManager.MakeRelative(textSave.FontTexture);
                textSave.FontFile    = FileManager.MakeRelative(textSave.FontFile);
            }

            #endregion

            FileManager.RelativeDirectory = oldRelativeDirectory;
        }