object GetEquilibriumParticleCount() { string fileName = ProjectManager.MakeAbsolute(((ReferencedFileSave)Instance).Name); if (File.Exists(fileName)) { EmitterSaveList esl = EmitterSaveList.FromFile(fileName); return(esl.GetEquilibriumParticleCount()); } else { return(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); } }
public static List <string> GetNamedObjectsIn(string fileName) { string extension = FileManager.GetExtension(fileName); List <string> listToReturn = new List <string>(); switch (extension) { #region case Scene (scnx) case "scnx": SpriteEditorScene ses = SpriteEditorScene.FromFile(fileName); for (int i = 0; i < ses.PositionedModelSaveList.Count; i++) { listToReturn.Add(ses.PositionedModelSaveList[i].Name + " (PositionedModel)"); } for (int i = 0; i < ses.SpriteFrameSaveList.Count; i++) { listToReturn.Add(ses.SpriteFrameSaveList[i].ParentSprite.Name + " (SpriteFrame)"); } for (int i = 0; i < ses.SpriteGridList.Count; i++) { listToReturn.Add(ses.SpriteGridList[i].Name + " (SpriteGrid)"); } for (int i = 0; i < ses.SpriteList.Count; i++) { listToReturn.Add(ses.SpriteList[i].Name + " (Sprite)"); } for (int i = 0; i < ses.TextSaveList.Count; i++) { listToReturn.Add(ses.TextSaveList[i].Name + " (Text)"); } break; #endregion #region case ShapeCollection (shcx) case "shcx": ShapeCollectionSave scs = ShapeCollectionSave.FromFile(fileName); for (int i = 0; i < scs.AxisAlignedCubeSaves.Count; i++) { listToReturn.Add(scs.AxisAlignedCubeSaves[i].Name + " (AxisAlignedCube)"); } for (int i = 0; i < scs.AxisAlignedRectangleSaves.Count; i++) { listToReturn.Add(scs.AxisAlignedRectangleSaves[i].Name + " (AxisAlignedRectangle)"); } for (int i = 0; i < scs.CircleSaves.Count; i++) { listToReturn.Add(scs.CircleSaves[i].Name + " (Circle)"); } for (int i = 0; i < scs.PolygonSaves.Count; i++) { listToReturn.Add(scs.PolygonSaves[i].Name + " (Polygon)"); } for (int i = 0; i < scs.SphereSaves.Count; i++) { listToReturn.Add(scs.SphereSaves[i].Name + " (Sphere)"); } break; #endregion #region NodeNetwork (nntx) case "nntx": NodeNetworkSave nns = NodeNetworkSave.FromFile(fileName); for (int i = 0; i < nns.PositionedNodes.Count; i++) { listToReturn.Add(nns.PositionedNodes[i].Name + " (PositionedNode)"); } break; #endregion #region EmitterList (emix) case "emix": EmitterSaveList esl = EmitterSaveList.FromFile(fileName); for (int i = 0; i < esl.emitters.Count; i++) { listToReturn.Add(esl.emitters[i].Name + " (Emitter)"); } break; #endregion #region Case AnimationChainList (achx) case "achx": AnimationChainListSave acls = AnimationChainListSave.FromFile(fileName); for (int i = 0; i < acls.AnimationChains.Count; i++) { listToReturn.Add(acls.AnimationChains[i].Name + " (AnimationChain)"); } break; #endregion #region Case SplineList (splx) case "splx": SplineSaveList ssl = SplineSaveList.FromFile(fileName); for (int i = 0; i < ssl.Splines.Count; i++) { listToReturn.Add(ssl.Splines[i].Name + " (Spline)"); } break; #endregion } return(listToReturn); }
public static List <string> GetFilesReferencedByAsset(string file, bool readRecursively) { string fileExtension = FileManager.GetExtension(file); List <string> referencedFiles = null; // = new List<string>(); switch (fileExtension) { #region Scene (.scnx) case "scnx": SpriteEditorScene ses = SpriteEditorScene.FromFile(file); referencedFiles = ses.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region Emitter List (.emix) case "emix": EmitterSaveList esl = EmitterSaveList.FromFile(file); referencedFiles = esl.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region SpriteRig (.srgx) case "srgx": SpriteRigSave srs = SpriteRigSave.FromFile(file); referencedFiles = srs.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region AnimationChain List case "achx": AnimationChainListSave acls = AnimationChainListSave.FromFile(file); referencedFiles = acls.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region Bitmap Font Generator Config File (.bmfc) case "bmfc": referencedFiles = new List <string>(); // These are only referenced IF they actually exist string referencedFileToAdd = FileManager.RemoveExtension(file) + ".png"; if (FileManager.FileExists(referencedFileToAdd)) { referencedFiles.Add(referencedFileToAdd); } referencedFileToAdd = FileManager.RemoveExtension(file) + ".fnt"; if (FileManager.FileExists(referencedFileToAdd)) { referencedFiles.Add(referencedFileToAdd); } break; #endregion #region X File (.x) case "x": referencedFiles = GetTextureReferencesInX(file); break; #endregion #region WME File (.wme) case "wme": referencedFiles = new List <string>(); WMELoader.GetReferencedFiles(file, referencedFiles, RelativeType.Absolute); break; #endregion #region Spline List (.slpx) - falls to default case "splx": #endregion default: referencedFiles = new List <string>(); break; } if (readRecursively) { for (int i = referencedFiles.Count - 1; i > -1; i--) { referencedFiles.AddRange(GetFilesReferencedByAsset(referencedFiles[i], true)); } } // Files may include "../", so let's get rid of that stuff for (int i = 0; i < referencedFiles.Count; i++) { referencedFiles[i] = FileManager.Standardize(referencedFiles[i], "", false); } return(referencedFiles); }
public static void GetFilesReferencedByAsset(string fileName, TopLevelOrRecursive topLevelOrRecursive, List <string> referencedFiles) { List <string> newReferencedFiles = new List <string>(); if (!CanFileReferenceOtherFiles(fileName)) { return; } else if (!FileManager.FileExists(fileName)) { throw new FileNotFoundException("Could not find file " + fileName, fileName); } else { string fileExtension = FileManager.GetExtension(fileName); switch (fileExtension) { #region Scene (.scnx) case "scnx": SceneSave ses = SceneSave.FromFile(fileName); try { newReferencedFiles = ses.GetReferencedFiles(RelativeType.Absolute); } catch (InvalidOperationException e) { MessageBox.Show("There is an invalid file reference in the file\n\n" + fileName + "\n\nGlue will skip this file. You should investigate this file in a text editor " + "to identify the issue.\n\nAdditional error information:\n\n" + e.ToString()); } break; #endregion #region Emitter List (.emix) case "emix": EmitterSaveList esl = EmitterSaveList.FromFile(fileName); newReferencedFiles = esl.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region AnimationChain List case "achx": AnimationChainListSave acls = AnimationChainListSave.FromFile(fileName); newReferencedFiles = acls.GetReferencedFiles(RelativeType.Absolute); break; #endregion #region X File (.x) case "x": newReferencedFiles = GetTextureReferencesInX(fileName); break; #endregion #region Spline List (.slpx) - falls to default case "splx": #endregion #region Font File (.fnt) case "fnt": newReferencedFiles = GetTextureReferencesInFnt(fileName); break; #endregion default: break; } // We still want to construct as good of a reference structure as possible // even if there are missing files. Therefore, we'll just keep track of errors and report them // at the end of the method bool didErrorOccur = false; string errorMessage = ""; if (topLevelOrRecursive == TopLevelOrRecursive.Recursive) { for (int i = newReferencedFiles.Count - 1; i > -1; i--) { // If this file can't reference other files, no need to even do a file check or throw errors. if (CanFileReferenceOtherFiles(newReferencedFiles[i]) == true) { if (File.Exists(newReferencedFiles[i])) { try { GetFilesReferencedByAsset(newReferencedFiles[i], topLevelOrRecursive, newReferencedFiles); } catch (Exception e) { didErrorOccur = true; errorMessage += e.Message; } } else { didErrorOccur = true; errorMessage += "Could not find the file " + newReferencedFiles[i] + " which is referenced in the file " + fileName + "\n"; } } } } // Files may include "../", so let's get rid of that stuff for (int i = 0; i < newReferencedFiles.Count; i++) { newReferencedFiles[i] = FileManager.Standardize(newReferencedFiles[i], "", false); } referencedFiles.AddRange(newReferencedFiles); if (didErrorOccur) { throw new Exception(errorMessage); } } }
object GetBurstParticleCount() { EmitterSaveList esl = EmitterSaveList.FromFile(ProjectManager.MakeAbsolute(((ReferencedFileSave)Instance).Name)); return(esl.GetBurstParticleCount()); }
public void LoadEmitters(string fileName) { #region Clear all Emitters in memory while (AppState.Self.Emitters.Count != 0) { SpriteManager.RemoveEmitter(AppState.Self.Emitters[0]); } AppState.Self.CurrentEmitter = null; #endregion #region Load the Emitters and add them to the SpriteManager EmitterSaveList emitterSaveList = EmitterSaveList.FromFile(fileName); AppState.Self.Emitters = emitterSaveList.ToEmitterList(AppState.Self.PermanentContentManager); foreach (Emitter emitter in AppState.Self.Emitters) { SpriteManager.AddEmitter(emitter); ShapeManager.AddPolygon(emitter.EmissionBoundary); } CurrentEmixFileName = FileManager.RemoveExtension(fileName); #endregion bool haveAttachments = false; #if FRB_MDX FlatRedBallServices.Owner.Text = "ParticleEditor - Currently editing " + CurrentEmixFileName; #else FlatRedBallServices.Game.Window.Title = "ParticleEditor - Currently editing " + CurrentEmixFileName; #endif for (int i = 0; i < AppState.Self.Emitters.Count; i++) { if (emitterSaveList.emitters[i].ParentSpriteName != null) { // see if the emitter exists in the gameData.emitterArray and set the attachments. If not, then // we need to set haveAttachments to true, indicating there are attachments to .scn Sprites Emitter e = AppState.Self.Emitters.FindWithNameContaining(emitterSaveList.emitters[i].ParentSpriteName); if (e != null) { AppState.Self.Emitters[i].AttachTo(e, false); } else { haveAttachments = true; } } } // TODO: Handle when the ParticleEditor can't find attachments. if (haveAttachments) { EditorData.lastLoadedFile = emitterSaveList; if (EditorData.Scene == null || EditorData.Scene.Sprites.Count == 0) { MultiButtonMessageBox mbmb = GuiManager.AddMultiButtonMessageBox(); mbmb.Name = ".emi attachments found"; mbmb.Text = fileName + " has one or more attachments. There are no " + "Sprites loaded. What would you like to do with the attachment information?"; mbmb.ScaleX = 15; mbmb.AddButton("Forget all attachment information.", new GuiMessage(FileMenuWindow.ForgetAttachmentInfo)); mbmb.AddButton("Remember attachment information, I will load a .scnx file later.", new GuiMessage(FileMenuWindow.RememberAttachmentInfo)); mbmb.AddButton("Manually search for .scnx file now.", new GuiMessage(FileMenuWindow.LoadScnxButtonClick)); mbmb.AddButton("Automatically search for .scnx with Sprites matching attachments.", new GuiMessage(FileMenuWindow.AutoSearchScn)); } else { FileMenuWindow.AttemptEmitterAttachment(""); } } string settingsFileName = FileManager.RemoveExtension(fileName) + ".ess"; bool doesSettingsFileExist = System.IO.File.Exists(settingsFileName); if (doesSettingsFileExist) { EmitterEditorSettingsSave settings = EmitterEditorSettingsSave.Load(settingsFileName); settings.Camera.SetCamera(Camera.Main); if (settings.Camera.OrthogonalHeight < 0) { Camera.Main.UsePixelCoordinates(); } else { Camera.Main.FixAspectRatioYConstant(); } } }