Exemplo n.º 1
0
 /// <summary>
 /// Convert JSON-serializable _TileMap format to the more usable TileMap format.
 /// </summary>
 /// <param name="tileMap">Pre-existing TileMap object to use.</param>
 /// <param name="path">Path that contains the tile map and tilesheet (texture) files.</param>
 /// <param name="textureLibrary">ResourceLibrary for storing textures.</param>
 public void Solidify(TileMap tileMap, string path, TextureLibrary textureLibrary)
 {
     textureLibrary.Load(Path.Combine(path, TileMapImage), out Texture2D item);
     tileMap.TileMapImage = item;
     tileMap.TileWidth    = TileSize[0];
     tileMap.TileHeight   = TileSize[1];
     Tile[] tiles = new Tile[Tiles.Count];
     for (int i = 0; i < Tiles.Count; i++)
     {
         tiles[i]             = Tiles[i];
         tiles[i].Position    = new int[2];
         tiles[i].Position[0] = Tiles[i].Index[0] * TileSize[0];
         tiles[i].Position[1] = Tiles[i].Index[1] * TileSize[1];
     }
     tileMap.Tiles = tiles;
     tileMap.MakeLookup();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Prepare _Sprite format for conversion to Sprite format.
        /// </summary>
        /// <param name="path">Path that contains the sprite and spritesheet (texture) files.</param>
        /// <param name="textureLibrary">ResourceLibrary for storing textures.</param>
        public void Finalize(string path, TextureLibrary textureLibrary)
        {
            if (CollisionBox == null)
            {
                CollisionBox = new CollisionBox();
            }
            if (DefaultFrame == null)
            {
                DefaultFrame = new _FrameRange();
            }
            if (DefaultFrame.Spritesheet != null)
            {
                textureLibrary.Load(Path.Combine(path, DefaultFrame.Spritesheet), out Texture2D item);
                DefaultFrame.Texture = item;
            }
            if (DefaultFrame.X == null)
            {
                DefaultFrame.X = 0;
            }
            if (DefaultFrame.Y == null)
            {
                DefaultFrame.Y = 0;
            }
            if (DefaultFrame.Texture != null)
            {
                if (DefaultFrame.Width == null)
                {
                    DefaultFrame.Width = DefaultFrame.Texture.Width;
                }
                if (DefaultFrame.Height == null)
                {
                    DefaultFrame.Height = DefaultFrame.Texture.Height;
                }
            }
            else
            {
                DefaultFrame.Width  = 0;
                DefaultFrame.Height = 0;
            }
            if (DefaultFrame.AnchorX == null)
            {
                DefaultFrame.AnchorX = 0f;
            }
            if (DefaultFrame.AnchorY == null)
            {
                DefaultFrame.AnchorY = 0f;
            }
            if (DefaultFrame.Count == null)
            {
                DefaultFrame.Count = 1;
            }
            if (DefaultFrame.Frametime == null)
            {
                DefaultFrame.Frametime = 1f;
            }
            if (DefaultFrame.FlipX == null)
            {
                DefaultFrame.FlipX = false;
            }
            if (DefaultFrame.FlipY == null)
            {
                DefaultFrame.FlipY = false;
            }

            if (Animations == null)
            {
                Animations = new List <_Animation>(new _Animation[] { new _Animation() });
            }
            foreach (_Animation animation in Animations)
            {
                if (animation.Name == null)
                {
                    animation.Name = "default";
                }
                if (animation.Speed == null)
                {
                    animation.Speed = 1f;
                }
                if (animation.FrameRanges == null)
                {
                    animation.FrameRanges = new List <_FrameRange>();
                    animation.FrameRanges.Add(DefaultFrame);
                }
                else
                {
                    foreach (_FrameRange frame in animation.FrameRanges)
                    {
                        if (frame.Spritesheet == null)
                        {
                            frame.Spritesheet = DefaultFrame.Spritesheet;
                            frame.Texture     = DefaultFrame.Texture;
                        }
                        else
                        {
                            textureLibrary.Load(Path.Combine(path, frame.Spritesheet), out Texture2D item);
                            frame.Texture = item;
                        }
                        if (frame.X == null)
                        {
                            frame.X = DefaultFrame.X;
                        }
                        if (frame.Y == null)
                        {
                            frame.Y = DefaultFrame.Y;
                        }
                        if (frame.Width == null)
                        {
                            frame.Width = DefaultFrame.Width;
                        }
                        if (frame.Height == null)
                        {
                            frame.Height = DefaultFrame.Height;
                        }
                        if (frame.AnchorX == null)
                        {
                            frame.AnchorX = DefaultFrame.AnchorX;
                        }
                        if (frame.AnchorY == null)
                        {
                            frame.AnchorY = DefaultFrame.AnchorY;
                        }
                        if (frame.Count == null)
                        {
                            frame.Count = DefaultFrame.Count;
                        }
                        if (frame.Frametime == null)
                        {
                            frame.Frametime = 1f;                          // Do not inherit this from DefaultFrame.
                        }
                        if (frame.FlipX == null)
                        {
                            frame.FlipX = false;                      // Do not inherit this from DefaultFrame.
                        }
                        if (frame.FlipY == null)
                        {
                            frame.FlipY = false;                      // Do not inherit this from DefaultFrame.
                        }
                    }
                }

                if (DefaultAnimation == null)
                {
                    DefaultAnimation = animation.Name;
                }
            }
        }