Exemple #1
0
        private void InitializeFromFileLocation(String fileLocation, TileType tileType)
        {
            _fileLocation = fileLocation;

            //load the image bytes
            var source = new OriginalImage(fileLocation);

            //ensure the source file is correct
            var fileName = Path.GetFileName(fileLocation);
            AssertValidFile(fileName, source);

            ConstructTiles(source, tileType);

            ConstructTags(fileName);
        }
Exemple #2
0
        private void ConstructTiles(OriginalImage source, TileType tileType)
        {
            Tiles = new ObservableCollection<Tile>();

            //break it down into x-number pixel square tiles
            for (var tileRow = 0; tileRow < source.Height / Constants.TILE_PIXELS; tileRow++)
            {
                for (var tileColumn = 0; tileColumn < Constants.UNMANAGED_TILE_PIXEL_WIDTH / Constants.TILE_PIXELS; tileColumn++)
                {
                    //we want to go one frame at a time
                    var tile = new Tile() { Type = tileType };
                    for (var frame = 0; frame * Constants.UNMANAGED_TILE_PIXEL_WIDTH < source.Width; frame++)
                    {
                        var tileFrame = new TileFrame();
                        var newBytes = new List<Byte>();
                        for (var row = 0; row < Constants.TILE_PIXELS; row++)
                        {
                            //for each row of this tile, grab the pixels from imagebytes
                            var totalRowOffset = tileRow * Constants.TILE_PIXELS + row;
                            var totalColumnOffset = Constants.UNMANAGED_TILE_PIXEL_WIDTH * frame + tileColumn * Constants.TILE_PIXELS;
                            var offset = source.CalculateImageByteArrayOffset(totalRowOffset, totalColumnOffset);
                            newBytes.AddRange(source.ImageBytes.Skip(offset).Take(4 * Constants.TILE_PIXELS)); //4 bytes per tile
                        }
                        tileFrame.SetSource(Constants.TILE_PIXELS, Constants.TILE_PIXELS, newBytes.ToArray());
                        tile.Frames.Add(tileFrame);
                    }
                    Tiles.Add(tile);
                }
            }
        }
Exemple #3
0
 public Sprite(OriginalImage originalImage)
 {
     _originalImage = originalImage;
     ImageBytes = null;
 }
Exemple #4
0
 private void AssertValidFile(String fileName, OriginalImage source)
 {
     if (fileName.Contains(Constants.UNMANAGED_TILE_ANIMATED_IDENTIFIER))
     {
         //if a tile is animated, the pixel width should be a multiple of the anticipated width > 1
         if (source.Width % Constants.UNMANAGED_TILE_PIXEL_WIDTH != 0 || source.Width / Constants.UNMANAGED_TILE_PIXEL_WIDTH <= 1)
         {
             throw new Exception(String.Format("New animated tile source width of {0} pixels is invalid.", source.Width));
         }
     }
     else
     {
         //if a tile is not animated, it should have the expected width
         if (source.Width != Constants.UNMANAGED_TILE_PIXEL_WIDTH)
         {
             throw new Exception(String.Format("New tile source width of {0} pixels is invalid.", source.Width));
         }
     }
 }
Exemple #5
0
 public void Reset(OriginalImage originalImage)
 {
     _originalImage = originalImage;
     Width = Height = 0;
     BitmapSource = null;
 }