Пример #1
0
        void UpdateRenderedSpriteInner(CPos cell, RendererCellContents content)
        {
            var density    = content.Density;
            var renderType = content.Type;

            if (density > 0 && renderType != null)
            {
                // The call chain for this method (that starts with AddDirtyCell()) guarantees
                // that the new content type would still be suitable for this renderer,
                // but that is a bit too fragile to rely on in case the code starts changing.
                if (!Info.RenderTypes.Contains(renderType.Info.Type))
                {
                    return;
                }

                var clear = FindClearSides(renderType, cell);
                int index;

                if (clear == ClearSides.None)
                {
                    var sprites = Variants[content.Variant];
                    var frame   = density > ResourceLayer.GetMaxResourceDensity(cell) / 2 ? 1 : 0;

                    UpdateSpriteLayers(cell, renderType.Variants.First().Value, sprites[frame], renderType.Palette);
                }
                else if (SpriteMap.TryGetValue(clear, out index))
                {
                    UpdateSpriteLayers(cell, renderType.Variants.First().Value, index, renderType.Palette);
                }
                else
                {
                    throw new InvalidOperationException("SpriteMap does not contain an index for ClearSides type '{0}'".F(clear));
                }
            }
            else
            {
                UpdateSpriteLayers(cell, null, 0, null);
            }
        }