Пример #1
0
        public void DrawToUI(int[] pixelData, int x, int y, int width, int height, bool flipH = false, bool flipV = false, int colorOffset = 0)
        {
            // Update pixel data

            y = _height - height - y;

//            if (pixelData != null)
//            {
            if (flipH || flipV)
            {
                SpriteChipUtil.FlipSpriteData(ref pixelData, width, height, flipH, flipV);
            }



            // TODO Need to make sure we offset colors if a new offset is set
            if (colorOffset > 0)
            {
                var total = pixelData.Length;
                for (int i = 0; i < total; i++)
                {
                    pixelData[i] += colorOffset;
                }
            }

            uiLayer.SetPixels(x, y, width, height, pixelData);
        }
Пример #2
0
        public virtual void PrepareSprites()
        {
            cps = spriteChip.colorsPerSprite;

            colorData = chips.GetChip(ColorMapParser.chipName, false) is ColorChip colorMapChip
                ? colorMapChip.colors
                : chips.colorChip.colors;

            maskColor  = ColorUtils.HexToColor(chips.colorChip.maskColor);
            maxSprites = SpriteChipUtil.CalculateTotalSprites(spriteChip.textureWidth, spriteChip.textureHeight,
                                                              spriteWidth, spriteHeight);

            // Create tmp arrays for color and reference data
            totalPixels = spriteChip.width * spriteChip.height;
            tmpPixels   = new Color[totalPixels];
            spriteData  = new int[totalPixels];

            // Keep track of number of sprites added
            spritesAdded = 0;

            //TODO this should be set by the parser
            srcColors = imageParser.colorPixels; //data.Select(c => new ColorAdapter(c) as Color).ToArray();

            currentStep++;
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="colorOffset"></param>
        public void DrawSprite(int id, int x, int y, int colorOffset = 0)
        {
            // This only works when the canvas has a reference to the gameChip
            if (gameChip == null)
            {
                return;
            }

            var pixelData = gameChip.Sprite(id);

            if (colorOffset > 0)
            {
                var total = pixelData.Length;

                for (int i = 0; i < total; i++)
                {
                    pixelData[i] = pixelData[i] + colorOffset;
                }
            }

            // Canvas is reversed, so flip the pixel data
            SpriteChipUtil.FlipSpriteData(ref pixelData, spriteSize.x, spriteSize.y);

            SetPixels(x, y, spriteSize.x, spriteSize.y, pixelData);
        }
Пример #4
0
        public override void PrepareSprites()
        {
            // Get the total number of sprites
            totalSpritesInTexture = SpriteChipUtil.CalculateTotalSprites(tex.width, tex.height, spriteChip.width, spriteChip.height);

            ids = Enumerable.Repeat(-1, totalSpritesInTexture).ToArray();

            base.PrepareSprites();
        }
Пример #5
0
        /// <summary>
        ///     Updates the sprite data at a given position in the
        ///     <see cref="texture" /> data.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="pixels"></param>
        public void UpdateSpriteAt(int index, int[] pixels)
        {
            if (index < 0)
            {
                return;
            }

            SpriteChipUtil.AddSpriteToTextureData(index, pixels, _texture, width, height);
            CacheSprite(index, pixels);
        }
Пример #6
0
        /// <summary>
        ///     This caches a sprite for easier look up and duplicate detection.
        ///     Each sprite is cached as a string.
        /// </summary>
        /// <param name="index">
        ///     Index where the sprite's cached value should be stored in the
        ///     <see cref="cache" /> array.
        /// </param>
        /// <param name="data">
        ///     An array of ints that represents the sprite's color data.
        /// </param>
        private void CacheSprite(int index, int[] data)
        {
            cache[index] = SpriteChipUtil.SpriteDataToString(data);

            var totalPixels = width * height;

            var tmpPixels = new int[totalPixels];

            Array.Copy(data, tmpPixels, totalPixels);
            pixelDataCache[index] = tmpPixels;
        }
Пример #7
0
        /// <summary>
        ///     Finds a sprite by looking it up against the cache. Returns -1 if no
        ///     sprite is found. This is used for insuring duplicate sprites aren't
        ///     added to the TextureData.
        /// </summary>
        /// <param name="pixels">
        ///     An array of ints representing the sprite's color data.
        /// </param>
        /// <returns>
        /// </returns>
        public int FindSprite(int[] pixels, bool emptyCheck = false)
        {
            if (emptyCheck)
            {
                if (IsEmpty(pixels))
                {
                    return(-1);
                }
            }

            var sprite = SpriteChipUtil.SpriteDataToString(pixels);

            return(Array.IndexOf(cache, sprite));
        }
Пример #8
0
        public virtual void PrepareSprites()
        {
            cps = spriteChip.colorsPerSprite;

            totalSprites = image.TotalSprites;

            maxSprites = SpriteChipUtil.CalculateTotalSprites(spriteChip.textureWidth, spriteChip.textureHeight,
                                                              spriteWidth, spriteHeight);

            // // Keep track of number of sprites added
            spritesAdded = 0;

            StepCompleted();
        }
Пример #9
0
        // TODO this should be a step in the exporter
        public void ConfigurePixelData()
        {
            var spriteChip = engine.spriteChip;

            var totalSprite = spriteChip.totalSprites - 1;

            var width   = spriteChip.textureWidth;
            var height  = spriteChip.textureHeight;
            var sWidth  = spriteChip.width;
            var sHeight = spriteChip.height;

            var emptyCount = 0;
            var tmpData    = new int[sWidth * sHeight];
            var cols       = (int)Math.Floor((float)width / sWidth);

            for (int i = totalSprite; i > -1; i--)
            {
                spriteChip.ReadSpriteAt(i, tmpData);

                if (spriteChip.IsEmpty(tmpData))
                {
                    emptyCount++;
                }

                if (i % cols == 0)
                {
                    if (emptyCount == cols)
                    {
                        height -= sHeight;
                    }

                    emptyCount = 0;
                }
            }

            var pixelData = new int[width * height];

            spriteChip.texture.CopyPixels(ref pixelData, 0, 0, width, height);

            SpriteChipUtil.FlipSpriteData(ref pixelData, width, height, false, true);

            var colorMapChip = engine.chipManager.GetChip(ColorMapParser.chipName, false) as ColorChip;

            var colors = colorMapChip == null ? engine.colorChip.colors : colorMapChip.colors;

            exporter = new PixelDataExporter(fullFileName, pixelData, width, height, colors, textureFactory);
        }
Пример #10
0
        /// <summary>
        ///     Returns an array of ints that represent a sprite. Each
        ///     int should be mapped to a color
        ///     <paramref name="index" /> to display in the renderer.
        /// </summary>
        /// <param name="index">
        ///     Anint representing the location in memory of the
        ///     sprite.
        /// </param>
        /// <param name="pixelData"></param>
        /// <returns>
        /// </returns>
        public void ReadSpriteAt(int index, int[] pixelData)
        {
//            if (index > pixelDataCache.GetLength(0))
            if (index == -1)
            {
                return;
            }

//            try
//            {
            var cachedSprite = pixelDataCache[index];

            var totalSpritePixels = width * height;

            if (cachedSprite == null)
            {
                var tmpPixelData = new int[totalSpritePixels];

                SpriteChipUtil.CalculateSpritePos(index, _texture.width, _texture.height, width, height, out tmpX, out tmpY);

                _texture.GetPixels(tmpX, tmpY, width, height, ref tmpPixelData);

                pixelDataCache[index] = tmpPixelData;
                cachedSprite          = pixelDataCache[index];
            }

//            if(pixelData == null)
//                Debug.Log("pixelData is null");

            // Make sure that the pixelData array is the correct size.
            if (pixelData.Length != cachedSprite.Length)
            {
//                Debug.Log("pixelData " + pixelData.Length + " cachedSprite " +cachedSprite.Length);
                Array.Resize(ref pixelData, cachedSprite.Length);
            }

            // Copy the contents of the cached pixel data into the new array.
            Array.Copy(cachedSprite, pixelData, totalSpritePixels);
//            }
//            catch (Exception e)
//            {
//                Debug.Log("Out of range" + pixelDataCache.GetLength(0) + " " + index);
//            }
        }
Пример #11
0
        /// <summary>
        ///     Creates a new draw by copying the supplied pixel data over
        ///     to the Display's TextureData.
        /// </summary>
        /// <param name="pixelData"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="flipH"></param>
        /// <param name="flipV"></param>
        /// <param name="flipY"></param>
        /// <param name="layerOrder"></param>
        /// <param name="masked"></param>
        /// <param name="colorOffset"></param>
        public void NewDrawCall(int[] pixelData, int x, int y, int width, int height, bool flipH, bool flipV, bool flipY, int layerOrder = 0, bool masked = false, int colorOffset = 0)
        {
            var drawCalls = width / engine.spriteChip.width * (height / engine.spriteChip.height);

            //currentSprites += drawCalls;

            if (currentSprites + drawCalls > maxSpriteCount)
            {
                return;
            }

            currentSprites += drawCalls;

            //TODO need to add in layer merge logic, -1 is behind, 0 is normal, 1 is above

            //layerOrder = layerOrder.Clamp(-1, 1);

            // flip y coordinate space
            if (flipY)
            {
                y = _height - engine.spriteChip.height - y;
            }

            if (pixelData != null)
            {
                if (flipH || flipV)
                {
                    SpriteChipUtil.FlipSpriteData(ref pixelData, width, height, flipH, flipV);
                }

                var draw = NextDrawRequest();
                draw.x           = x;
                draw.y           = y;
                draw.width       = width;
                draw.height      = height;
                draw.pixelData   = pixelData;
                draw.order       = layerOrder;
                draw.colorOffset = colorOffset;
                drawRequests.Add(draw);


                //texturedata.MergePixels(x, y, width, height, pixelData);
            }
        }
Пример #12
0
        public virtual void PrepareSprites()
        {
            cps = spriteChip.colorsPerSprite;

            var colorMapChip = chips.chipManager.GetChip(ColorMapParser.chipName, false) as ColorChip;

            colorData  = colorMapChip != null ? colorMapChip.colors : chips.colorChip.colors;
            maskColor  = new ColorData(chips.colorChip.maskColor);
            maxSprites = SpriteChipUtil.CalculateTotalSprites(spriteChip.textureWidth, spriteChip.textureHeight, sWidth, sHeight);

            // Create tmp arrays for color and reference data
            totalPixels = spriteChip.width * spriteChip.height;
            tmpPixels   = new IColor[totalPixels];
            spriteData  = new int[totalPixels];

            // Keep track of number of sprites added
            spritesAdded = 0;

            currentStep++;
        }
Пример #13
0
 protected override void FlipPixels()
 {
     // TODO maybe the base class should just expect to have the pixel data so this doens't need to override it
     SpriteChipUtil.FlipSpriteData(ref pixelData, width, height, false, true);
     currentStep++;
 }
Пример #14
0
 protected virtual void FlipPixels()
 {
     pixelData = tmpTextureData.GetPixels();
     SpriteChipUtil.FlipSpriteData(ref pixelData, width, height, false, true);
     currentStep++;
 }