Esempio n. 1
0
        public static object GetValueForProperty(string fileName, string objectName, string propertyName)
        {
            string extension = FileManager.GetExtension(fileName);

            switch (extension)
            {
                #region case Scene (scnx)
            case "scnx":

                SpriteEditorScene ses = SpriteEditorScene.FromFile(fileName);

                string oldRelative = FileManager.RelativeDirectory;
                FileManager.RelativeDirectory = FileManager.GetDirectory(fileName);

                object returnValue = GetValueForPropertyInScene(ses, objectName, propertyName);

                FileManager.RelativeDirectory = oldRelative;

                return(returnValue);

                //break;
                #endregion

                #region case ShapeCollection (shcx)

            case "shcx":
                ShapeCollectionSave scs = ShapeCollectionSave.FromFile(fileName);
                return(GetValueForPropertyInShapeCollection(scs, objectName, propertyName));

                //break;

                #endregion
            }
            return(null);
        }
Esempio n. 2
0
        void SetFrom(ShapeCollectionSave shapeCollectionSave)
        {
            Clear();

            foreach (var saveObject in shapeCollectionSave.AxisAlignedRectangleSaves)
            {
                var runtime = saveObject.ToAxisAlignedRectangle();

                var vm = new AxisAlignedRectangleViewModel(runtime);

                Rectangles.Add(vm);
            }

            foreach (var saveObject in shapeCollectionSave.CircleSaves)
            {
                var runtime = saveObject.ToCircle();

                var vm = new CircleViewModel(runtime);

                Circles.Add(vm);
            }

            foreach (var saveObject in shapeCollectionSave.PolygonSaves)
            {
                var runtime = saveObject.ToPolygon();

                var vm = new PolygonViewModel(runtime);

                Polygons.Add(vm);
            }
        }
Esempio n. 3
0
        void SaveShapeListOk(Window callingWindow)
        {
            string fileName = ((FileWindow)callingWindow).Results[0];

            ShapeCollectionSave shapeSaveList = new ShapeCollectionSave();

            shapeSaveList.AddPolygonList(EditorData.Polygons);
            shapeSaveList.AddAxisAlignedRectangleList(EditorData.AxisAlignedRectangles);
            shapeSaveList.AddCircleList(EditorData.Circles);
            shapeSaveList.AddAxisAlignedCubeList(EditorData.AxisAlignedCubes);
            shapeSaveList.AddSphereList(EditorData.Spheres);
            shapeSaveList.Save(fileName);

#if FRB_MDX
            GameForm.TitleText = "PolygonEditor - Editing " + fileName;
#else
            FlatRedBallServices.Game.Window.Title = "PolygonEditor Editing - " + fileName;
#endif

            fileName  = FileManager.RemoveExtension(fileName);
            fileName += ".pesix";
            PolygonEditorSettings savedInformation = new PolygonEditorSettings(EditorData.LineGrid);
            savedInformation.BoundsCameraSave    = CameraSave.FromCamera(EditorData.BoundsCamera);
            savedInformation.UsePixelCoordinates = SpriteManager.Camera.Orthogonal;
            savedInformation.Save(fileName);
        }
Esempio n. 4
0
        public void Load(string absoluteFileName)
        {
            fileName = absoluteFileName;

            var shapeCollectionSave = ShapeCollectionSave.FromFile(absoluteFileName);

            SetFrom(shapeCollectionSave);
        }
Esempio n. 5
0
        public static void AddShapeCollection(string fileName)
        {
            if (mShapeCollection != null)
            {
                mShapeCollection.RemoveFromManagers();
            }

            ShapeCollectionSave scs = ShapeCollectionSave.FromFile(fileName);

            mShapeCollection = scs.ToShapeCollection();
            mShapeCollection.AddToManagers();
        }
        protected override TRead Read(ContentReader input, TRead existingInstance)
        {
            if (existingInstance != null)
            {
                return(existingInstance);
            }

            ShapeCollectionSave shapeCollectionSave = ObjectReader.ReadObject <FlatRedBall.Content.Math.Geometry.ShapeCollectionSave>(input);

            shapeCollectionSave.FileName = input.AssetName;

            return(shapeCollectionSave.ToShapeCollection());
        }
Esempio n. 7
0
 static object GetValueForPropertyInShapeCollection(ShapeCollectionSave shapeCollection, string objectName, string property)
 {
     for (int i = 0; i < shapeCollection.AxisAlignedCubeSaves.Count; i++)
     {
         if (shapeCollection.AxisAlignedCubeSaves[i].Name == objectName)
         {
             return(GetValueForPropertyOnObject(shapeCollection.AxisAlignedCubeSaves[i], property));
         }
     }
     for (int i = 0; i < shapeCollection.AxisAlignedRectangleSaves.Count; i++)
     {
         if (shapeCollection.AxisAlignedRectangleSaves[i].Name == objectName)
         {
             return(GetValueForPropertyOnObject(shapeCollection.AxisAlignedRectangleSaves[i], property));
         }
     }
     for (int i = 0; i < shapeCollection.CircleSaves.Count; i++)
     {
         if (shapeCollection.CircleSaves[i].Name == objectName)
         {
             return(GetValueForPropertyOnObject(shapeCollection.CircleSaves[i], property));
         }
     }
     for (int i = 0; i < shapeCollection.PolygonSaves.Count; i++)
     {
         if (shapeCollection.PolygonSaves[i].Name == objectName)
         {
             return(GetValueForPropertyOnObject(shapeCollection.PolygonSaves[i], property));
         }
     }
     for (int i = 0; i < shapeCollection.SphereSaves.Count; i++)
     {
         if (shapeCollection.SphereSaves[i].Name == objectName)
         {
             return(GetValueForPropertyOnObject(shapeCollection.SphereSaves[i], property));
         }
     }
     return(null);
 }
Esempio n. 8
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. 9
0
        public static ShapeCollectionSave ToShapeCollectionSave(this TiledMapSave tiledMapSave, string layerName)
        {
            MapLayer mapLayer = null;

            if (!string.IsNullOrEmpty(layerName))
            {
                mapLayer = tiledMapSave.Layers.FirstOrDefault(l => l.Name.Equals(layerName));
            }
            var shapes = new ShapeCollectionSave();

            if ((mapLayer != null && !mapLayer.IsVisible && mapLayer.VisibleBehavior == TMXGlueLib.TiledMapSave.LayerVisibleBehavior.Skip) ||
                tiledMapSave.objectgroup == null || tiledMapSave.objectgroup.Count == 0)
            {
                return(shapes);
            }

            foreach (mapObjectgroup group in tiledMapSave.objectgroup)
            {
                if (group.@object != null && !string.IsNullOrEmpty(group.Name) && (string.IsNullOrEmpty(layerName) || group.Name.Equals(layerName)))
                {
                    foreach (mapObjectgroupObject @object in group.@object)
                    {
                        ///November 8th, 2015
                        ///Jesse Crafts-Finch
                        ///If a polygon has a gid, and therefore an image associate with it, it will be turned into a spritesave, not a polygon.
                        if (@object.gid != null)
                        {
                            continue;
                        }

                        if (@object.polygon != null)
                        {
                            foreach (mapObjectgroupObjectPolygon polygon in @object.polygon)
                            {
                                // TODO: Make this a rectangle object
                                PolygonSave p = tiledMapSave.ConvertTmxObjectToFrbPolygonSave(@object.Name,
                                                                                              @object.x, @object.y, @object.Rotation, polygon.points, true);
                                if (p != null)
                                {
                                    shapes.PolygonSaves.Add(p);
                                }
                            }
                        }

                        if (@object.polyline != null)
                        {
                            foreach (mapObjectgroupObjectPolyline polyline in @object.polyline)
                            {
                                PolygonSave p = tiledMapSave.ConvertTmxObjectToFrbPolygonSave(@object.Name,
                                                                                              @object.x, @object.y, @object.Rotation, polyline.points, false);
                                if (p != null)
                                {
                                    shapes.PolygonSaves.Add(p);
                                }
                            }
                        }



                        if (@object.polygon == null && @object.polyline == null)
                        {
                            PolygonSave p = tiledMapSave.ConvertTmxObjectToFrbPolygonSave(@object.Name, @object.x, @object.y, @object.width, @object.height, @object.Rotation, @object.ellipse);
                            if (p != null)
                            {
                                shapes.PolygonSaves.Add(p);
                            }
                        }
                    }
                }
            }
            return(shapes);
        }
Esempio n. 10
0
        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);
        }