Exemplo n.º 1
0
        public TextureCoordinateRect TileAreaForCardinalDirection(IntDimension ts, CardinalIndex dir)
        {
            var w     = ts.Width;
            var h     = ts.Height;
            var wHalf = ts.Width / 2;
            var hHalf = ts.Height / 2;

            switch (dir)
            {
            case CardinalIndex.West:
                return(new TextureCoordinateRect(0, 0, wHalf, hHalf));

            case CardinalIndex.North:
                return(new TextureCoordinateRect(wHalf, 0, w - wHalf, hHalf));

            case CardinalIndex.East:
                return(new TextureCoordinateRect(wHalf, hHalf, w - wHalf, h - hHalf));

            case CardinalIndex.South:
                return(new TextureCoordinateRect(0, hHalf, wHalf, h - hHalf));

            default:
                throw new ArgumentException();
            }
        }
Exemplo n.º 2
0
        bool TryFindSourceMask(CardinalIndex dir, out BoundedTextureData <TColor> colorData, out IntPoint anchor)
        {
            var idx = (int)dir;
            var ce  = maskCache[idx];

            colorData = ce.ColorData;
            anchor    = ce.Anchor;
            return(ce.Exists);
        }
Exemplo n.º 3
0
        public bool TryGenerate(string tag, CardinalIndex direction, out TTile tile)
        {
            var etag = $"{prefix}{tag}_{direction}";

            if (tileRegistry.TryFind(etag, out var predefined))
            {
                tile = predefined;
                return(true);
            }

            var sourceArea = textureOperations.TileAreaForCardinalDirection(tileSize, direction);

            if (!TryFindSourceMask(direction, out var effectiveMask, out var anchor))
            {
                tile = default;
                return(false);
            }

            if (!tileRegistry.TryFind(tag, out var terrain) ||
                !terrain.HasTexture)
            {
                tile = default;
                return(false);
            }

            var data   = textureOperations.ExtractData(terrain.Texture, sourceArea);
            var result = textureOperations.CombineMask(data, effectiveMask);

            var wrappedTextureSize = new IntDimension(tileSize.Width, tileSize.Height);
            var wrappedTexture     = textureOperations.CreateTexture(etag, wrappedTextureSize);

            textureOperations.ApplyTextureData(wrappedTexture, result, sourceArea.Origin);

            tile = tileProducer.Produce(tileSize, anchor, etag, wrappedTexture);
            return(true);
        }
Exemplo n.º 4
0
        CacheEntry CacheTryFindSourceMask(CardinalIndex dir)
        {
            if (cardinalMaskRegistry.TryFind("mask.blending", dir, out var providedTile) &&
                providedTile.HasTexture)
            {
                return(new CacheEntry(true,
                                      textureOperations.ExtractData(providedTile.Texture, providedTile.Texture.Bounds),
                                      providedTile.Anchor));
            }

            var sourceArea = textureOperations.TileAreaForCardinalDirection(tileSize, dir);

            if (renderType.IsIsometric())
            {
                if (ditherMask.HasTexture)
                {
                    return(new CacheEntry(true,
                                          textureOperations.ExtractData(ditherMask.Texture, sourceArea),
                                          ditherMask.Anchor));
                }
            }

            return(new CacheEntry(false, null, default));
        }
Exemplo n.º 5
0
 public static int AsInt(this CardinalIndex c)
 {
     return((int)c);
 }
Exemplo n.º 6
0
 public bool TryFind(string tag, CardinalIndex selector, out TRenderTile tile)
 {
     return(baseRegistry.TryFind(string.Format(CultureInfo.InvariantCulture, format, tag, suffixMapping.Lookup(selector).Tag), out tile));
 }