Ejemplo n.º 1
0
        private byte[] GetSpritesFromSpec(string spec)
        {
            var bytes = new List <byte>();

            bytes.AddRange(Enumerable.Repeat((byte)0, 16));
            var spriteConfig = SpriteConfig.Read(spec, Palettes.Read(this.palettesTextBox.Text));

            for (var i = 1; i < 256; i++)
            {
                var sprite = spriteConfig.Sprites.FirstOrDefault(s => s.Id == i);
                if (sprite != null)
                {
                    var lowBits  = new List <byte>();
                    var highBits = new List <byte>();
                    var image    = sprite.GetSprite();

                    for (var y = 0; y < Constants.SpriteHeight; y++)
                    {
                        byte lowBit  = 0;
                        byte highBit = 0;

                        for (var x = 0; x < Constants.SpriteWidth; x++)
                        {
                            lowBit  = (byte)(lowBit << 1);
                            highBit = (byte)(highBit << 1);

                            var pixel = spriteConfig.PaletteMappings[sprite.Mapping].ColorMappings.First(c => c.Color == image.GetPixel(x, y)).To;

                            if (pixel == 1 || pixel == 3)
                            {
                                // low bit set
                                lowBit |= 1;
                            }

                            if (pixel == 2 || pixel == 3)
                            {
                                // high bit set
                                highBit |= 1;
                            }
                        }

                        lowBits.Add(lowBit);
                        highBits.Add(highBit);
                    }

                    bytes.AddRange(lowBits);
                    bytes.AddRange(highBits);
                }
                else
                {
                    bytes.AddRange(Enumerable.Repeat((byte)0, 16));
                }
            }

            return(bytes.ToArray());
        }
Ejemplo n.º 2
0
        private void LoadFiles()
        {
            this.palettes = Palettes.Read(palettesTextBox.Text);
            this.config   = SpriteConfig.Read(specTextBox.Text, this.palettes);

            this.framesListBox.Items.Clear();
            this.animationListBox.Items.Clear();
            foreach (var animation in config.Animations)
            {
                this.animationListBox.Items.Add(animation);
            }

            this.animationListBox.SelectedIndex = 0;
        }
Ejemplo n.º 3
0
        private void LoadFiles()
        {
            this.palettes = Palettes.Read(palettesTextBox.Text);
            this.config   = SpriteConfig.Read(specTextBox.Text, this.palettes);
            CreateCachedBitmaps();

            this.bulletsListBox.Items.Clear();
            foreach (var bullet in config.Bullets)
            {
                this.bulletsListBox.Items.Add(bullet);
            }

            this.bulletsListBox.SelectedIndex = 0;

            ValidateBullets();
        }
Ejemplo n.º 4
0
 private void LoadTilesetList(int?selectTileset = null, int?selectPalette = null)
 {
     this.disableRedrawing = true;
     this.config           = Tilesets.Read(FileConstants.Tilesets);
     this.palettes         = Palettes.Read(FileConstants.PalettesSpec);
     this.tilesetComboBox.Items.Clear();
     foreach (var id in this.config.LoadedSets.Select(ls => ls.Id).ToArray())
     {
         this.tilesetComboBox.Items.Add(id);
     }
     this.tilesetComboBox.SelectedIndex = selectTileset ?? 0;
     this.paletteComboBox.Items.Clear();
     foreach (var id in this.palettes.BackgroundPalettes.Select(ls => ls.Id).ToArray())
     {
         this.paletteComboBox.Items.Add(id);
     }
     this.paletteComboBox.SelectedIndex = selectPalette ?? 0;
     this.disableRedrawing = false;
     this.Redraw();
 }
Ejemplo n.º 5
0
        private void Process(bool writeFiles)
        {
            var palettesConfig     = Palettes.Read(this.palettesTextBox.Text);
            var spritesPalette     = new List <byte>();
            var backgroundPalettes = new List <byte>();

            spritesPalette.AddRange(palettesConfig.SpritesPalette.SelectMany(p => p.Colors).Select(c => (byte)c));
            foreach (var bgPalette in palettesConfig.BackgroundPalettes)
            {
                backgroundPalettes.AddRange(bgPalette.Palettes.SelectMany(p => p.Colors).Select(c => (byte)c));
            }

            if (writeFiles)
            {
                if (File.Exists(spritesTextBox.Text))
                {
                    File.Delete(spritesTextBox.Text);
                }

                File.WriteAllBytes(spritesTextBox.Text, spritesPalette.ToArray());

                if (File.Exists(backgroundTextBox.Text))
                {
                    File.Delete(backgroundTextBox.Text);
                }

                File.WriteAllBytes(backgroundTextBox.Text, backgroundPalettes.ToArray());
            }

            const int HorizontalPadding = 6;
            const int VerticalPadding   = 12;
            const int RectangleSize     = 32;

            Func <Palette, Bitmap> bitmapCreator = palette =>
            {
                var bitmap = new Bitmap(RectangleSize * 4, RectangleSize);
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    for (var i = 0; i < 4; i++)
                    {
                        graphics.FillRectangle(new SolidBrush(palette.ActualColors[i]), i * RectangleSize, 0, RectangleSize, RectangleSize);
                        graphics.DrawRectangle(new Pen(MyBitmap.GridColor, 1), i * RectangleSize, 0, RectangleSize - 1, RectangleSize - 1);
                    }
                }

                var bitmapWithPadding = new Bitmap(bitmap.Width + HorizontalPadding, bitmap.Height + HorizontalPadding);
                using (var graphics = Graphics.FromImage(bitmapWithPadding))
                {
                    graphics.DrawImage(bitmap, HorizontalPadding / 2, HorizontalPadding / 2);
                }

                return(bitmapWithPadding);
            };

            Func <Bitmap[], Bitmap> bigBitmapCreator = bitmaps =>
            {
                var bitmap = new Bitmap(bitmaps.Sum(b => b.Width), bitmaps[0].Height);
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    var x = 0;
                    foreach (var b in bitmaps)
                    {
                        graphics.DrawImage(b, x, 0);
                        x += b.Width;
                    }
                }

                return(bitmap);
            };

            var spriteBitmap      = bigBitmapCreator(palettesConfig.SpritesPalette.Select(bitmapCreator).ToArray());
            var backgroundBitmaps = palettesConfig.BackgroundPalettes.Select(p => bigBitmapCreator(p.Palettes.Select(bitmapCreator).ToArray())).ToArray();

            // Default height is just for one bg pallete, resize
            var paletteHeight = spriteBitmap.Height + VerticalPadding;
            var resize        = (backgroundBitmaps.Length - 1) * paletteHeight;

            this.Height = this.WindowDefaultHeight + resize;
            this.palettesPictureBox.Height = this.PictureBoxDefaultHeight + resize;

            var resultBitmap = new Bitmap(spriteBitmap.Width, paletteHeight * (backgroundBitmaps.Length + 1));

            using (var graphics = Graphics.FromImage(resultBitmap))
            {
                graphics.DrawImage(spriteBitmap, 0, 0);
                var y = paletteHeight;
                foreach (var bgBitmap in backgroundBitmaps)
                {
                    graphics.DrawImage(bgBitmap, 0, y);
                    y += paletteHeight;
                }
            }

            this.palettesPictureBox.Image = resultBitmap;
        }