Exemple #1
0
        public ISpriteRun SetPixels(IDataModel model, ModelDelta token, int page, int[,] pixels)
        {
            var data = Decompress(model, Start, allowLengthErrors: true);

            page %= Pages;

            var pageLength = SpriteFormat.TileWidth * SpriteFormat.TileHeight * 8 * SpriteFormat.BitsPerPixel;

            SpriteRun.SetPixels(data, page * pageLength, pixels, SpriteFormat.BitsPerPixel);

            var newModelData = Compress(data, 0, data.Length);
            var newRun       = (ISpriteRun)model.RelocateForExpansion(token, this, newModelData.Count);

            for (int i = 0; i < newModelData.Count; i++)
            {
                token.ChangeData(model, newRun.Start + i, newModelData[i]);
            }
            for (int i = newModelData.Count; i < Length; i++)
            {
                token.ChangeData(model, newRun.Start + i, 0xFF);
            }
            newRun = new LzSpriteRun(SpriteFormat, model, newRun.Start, newRun.PointerSources);
            model.ObserveRunWritten(token, newRun);
            return(newRun);
        }
Exemple #2
0
        public static ITilesetRun SetPixels(ITilesetRun run, IDataModel model, ModelDelta token, IReadOnlyList <int[, ]> tiles, Func <int, SortedSpan <int>, ITilesetRun> construct)
        {
            var tileSize = 8 * run.TilesetFormat.BitsPerPixel;
            var data     = new byte[tiles.Count * tileSize];

            for (int i = 0; i < tiles.Count; i++)
            {
                SpriteRun.SetPixels(data, i * tileSize, tiles[i], run.TilesetFormat.BitsPerPixel);
            }

            var newModelData = Compress(data, 0, data.Length);
            var newRun       = model.RelocateForExpansion(token, run, newModelData.Count);

            for (int i = 0; i < newModelData.Count; i++)
            {
                token.ChangeData(model, newRun.Start + i, newModelData[i]);
            }
            for (int i = newModelData.Count; i < run.Length; i++)
            {
                token.ChangeData(model, newRun.Start + i, 0xFF);
            }
            newRun = construct(newRun.Start, newRun.PointerSources);
            model.ObserveRunWritten(token, newRun);
            return(newRun);
        }
Exemple #3
0
        public ISpriteRun SetPixels(IDataModel model, ModelDelta token, int page, int[,] pixels)
        {
            // TODO handle the fact that pixels[,] may contain a different number of tiles compared to the existing tileset
            var data = Decompress(model, Start);

            for (int x = 0; x < pixels.GetLength(0); x++)
            {
                for (int y = 0; y < pixels.GetLength(1); y++)
                {
                    pixels[x, y] %= (int)Math.Pow(2, TilesetFormat.BitsPerPixel);
                }
            }
            SpriteRun.SetPixels(data, 0, pixels, TilesetFormat.BitsPerPixel);
            var newModelData = Compress(data, 0, data.Length);
            var newRun       = model.RelocateForExpansion(token, this, newModelData.Count);

            for (int i = 0; i < newModelData.Count; i++)
            {
                token.ChangeData(model, newRun.Start + i, newModelData[i]);
            }
            for (int i = newModelData.Count; i < Length; i++)
            {
                token.ChangeData(model, newRun.Start + i, 0xFF);
            }
            newRun = new LzTilesetRun(TilesetFormat, model, newRun.Start, newRun.PointerSources);
            model.ObserveRunWritten(token, newRun);
            return(newRun);
        }
Exemple #4
0
        public ISpriteRun SetPixels(IDataModel model, ModelDelta token, int[][,] tiles)
        {
            var tileSize = 8 * Format.BitsPerPixel;
            var data     = new byte[tiles.Length * tileSize];

            for (int i = 0; i < tiles.Length; i++)
            {
                SpriteRun.SetPixels(data, i * tileSize, tiles[i], Format.BitsPerPixel);
            }

            var newModelData = Compress(data, 0, data.Length);
            var newRun       = (LzTilesetRun)model.RelocateForExpansion(token, this, newModelData.Count);

            for (int i = 0; i < newModelData.Count; i++)
            {
                token.ChangeData(model, newRun.Start + i, newModelData[i]);
            }
            for (int i = newModelData.Count; i < Length; i++)
            {
                token.ChangeData(model, newRun.Start + i, 0xFF);
            }
            newRun = new LzTilesetRun(Format, model, newRun.Start, newRun.PointerSources);
            model.ObserveRunWritten(token, newRun);
            return(newRun);
        }
Exemple #5
0
        public ISpriteRun SetPixels(IDataModel model, ModelDelta token, int page, int[,] pixels)
        {
            var data = new byte[Length];

            SpriteRun.SetPixels(data, 0, pixels, TilesetFormat.BitsPerPixel);
            for (int i = 0; i < Length; i++)
            {
                token.ChangeData(model, Start + i, data[i]);
            }
            return(this);
        }