Example #1
0
        IntDimension ComputeContentSize()
        {
            var tileCount = MatchTypeStrategyFactory.StrategyFor(grid.MatcherType).GetTileArea(grid);
            var maxX      = tileCount.Width;
            var maxY      = tileCount.Height;

            var cs          = grid.EffectiveCellSize;
            var pixelWidth  = cs.Width * maxX;
            var pixelHeight = cs.Height * maxY;

            var paddedWidth  = Math.Max(0, maxX - 1) * grid.CellSpacing;
            var paddedHeight = Math.Max(0, maxY - 1) * grid.CellSpacing;

            return(new IntDimension(pixelWidth + paddedWidth, pixelHeight + paddedHeight));
        }
Example #2
0
        public static void Regenerate(TextureGrid grid)
        {
            if (grid.MatcherType == MatcherType.Basic)
            {
                return;
            }

            // preserve any tiles a user has placed manually
            // should not happen via the UI, but if they added something via
            // the XML file, we try our best to keep it alive.
            var preservedTiles = grid.Tiles.Where(t => !t.AutoGenerated).ToList();
            var newTiles       = MatchTypeStrategyFactory.StrategyFor(grid.MatcherType)
                                 .Generate(grid);

            foreach (var t in newTiles.Where(t => !TileAlreadyExists(preservedTiles, t)))
            {
                preservedTiles.Add(t);
            }

            grid.Tiles.ReplaceAll(preservedTiles);
        }