Ejemplo n.º 1
0
        public void CreateSpriteObject(string path)
        {
            spriteInfo         = new string[] { };
            spriteInfo_Texture = new string[] { };
            bm           = new Bitmap[] { };
            bm_processed = new Bitmap[] { };
            bm_order     = new string[] { };

            try
            {
                string json = File.ReadAllText(path);
                sprite = new SpriteReader();
                sprite = SpriteReader.FromJson(json);

                Visualizer_PictureBox.Image = null;
                ReadJSON();

                if (Sprites_ListBox.Items.Count > 0)
                {
                    Sprites_ListBox.Items.Clear();
                }
                CreateSprite();

                if (bm_processed.Length > 0)
                {
                    var c = ImageProcessing.CombineBitmap(bm_processed);
                    Visualizer_PictureBox.Image = c;
                }
            }
            catch
            {
                ConsoleHandler.append_CanRepeat("Something went wrong when trying to read that JSON file... Does it have invalid JSON?");
            }
        }
Ejemplo n.º 2
0
        private void Reload_Button_Click(object sender, EventArgs e)
        {
            string p    = Environment.CurrentDirectory + "\\" + Serializer.cfg.LastProject + "\\Assets\\JSON\\";// + path;
            string path = p + Folder_ComboBox.SelectedItem + "\\" + File_ComboBox.SelectedItem;

            sprite = SpriteReader.FromJson(File.ReadAllText(path));

            if (Folder_ComboBox.Items.Count > 0 && Folder_ComboBox.SelectedItem != null)
            {
                if (File_ComboBox.Items.Count > 0 && File_ComboBox.SelectedItem != null)
                {
                    bool sameSprites = true;
                    foreach (var a in sprite.Actors)
                    {
                        if (!Sprites_ListBox.Items.Contains(a.Sprite.ToString()))
                        {
                            ConsoleHandler.append_CanRepeat("Missing a sprite");
                            sameSprites = false;
                            break;
                        }
                    }
                    if (sameSprites)
                    {
                        Sprites_ListBox.Items.Clear();
                        Visualizer_PictureBox.Image = null;

                        bm_processed = new Bitmap[] { };
                        CreateSprite();

                        var c = ImageProcessing.CombineBitmap(bm_processed);
                        Visualizer_PictureBox.Image = c;
                    }
                    else
                    {
                        bm_processed = new Bitmap[] { };
                        Sprites_ListBox.Items.Clear();
                        Visualizer_PictureBox.Image = null;

                        string y = p + Folder_ComboBox.SelectedItem + "\\" + File_ComboBox.SelectedItem;
                        CreateSpriteObject(y);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void CreateSprite()
        {
            string p    = Environment.CurrentDirectory + "\\" + Serializer.cfg.LastProject + "\\Assets\\JSON\\";// + path;
            string path = p + Folder_ComboBox.SelectedItem + "\\" + File_ComboBox.SelectedItem;

            sprite = SpriteReader.FromJson(File.ReadAllText(path));

            if (sprite.Actors != null)
            {
                int maxWidth  = 0;
                int maxHeight = 0;
                //get the max size of canvas
                foreach (var m in bm)
                {
                    maxWidth  = m.Width > maxWidth ? m.Width : maxWidth;
                    maxHeight = m.Height > maxHeight ? m.Height : maxHeight;
                }

                Point total_center = new Point(maxWidth / 2, maxHeight / 2);
                foreach (var a in sprite.Actors)
                {
                    int i = 0;
                    foreach (var b in bm_order)
                    {
                        if (b == a.Sprite)
                        {
                            Sprites_ListBox.Items.Add(b);
                            //ConsoleHandler.append_CanRepeat(a.Sprite.ToString());

                            int  posX_int  = 0;
                            int  posY_int  = 0;
                            long posX_long = a.Position[1];
                            long posY_long = a.Position[0];
                            try
                            {
                                posX_int = Int32.Parse(posX_long.ToString());
                                posY_int = Int32.Parse(posY_long.ToString());
                            }
                            catch { ConsoleHandler.append_CanRepeat("One of the numbers being entered is not a valid number..."); };

                            Bitmap spr = new Bitmap(bm[i]);
                            spr.MakeTransparent();

                            /*width += spr.Width;
                             * height = spr.Height > height ? spr.Height : height;*/



                            int   x             = 0;
                            int   y             = 0;
                            Point sprite_center = new Point(spr.Width / 2, spr.Height / 2);
                            switch (a.Alignment[0])
                            {
                            case 1:
                                x = maxWidth;
                                break;

                            case 2:
                                //x = maxWidth;
                                break;

                            default:
                                x = total_center.X - (sprite_center.X);
                                break;
                            }

                            switch (a.Alignment[1])
                            {
                            case 1:
                                y = maxHeight;
                                break;

                            case 2:
                                //y = maxHeight;
                                break;

                            default:
                                y = total_center.Y - (sprite_center.Y / 2);
                                break;
                            }
                            posX_int += x;
                            posY_int += y;

                            if (a.Flip == 1)
                            {
                                spr.RotateFlip(RotateFlipType.RotateNoneFlipX);
                                posX_int += spr.Width;
                            }
                            if (a.Flip == 2)
                            {
                                spr.RotateFlip(RotateFlipType.RotateNoneFlipY);//.RotateNoneFlipX);
                                posY_int += spr.Height;
                            }
                            if (a.Flip == 3)
                            {
                                spr.RotateFlip(RotateFlipType.RotateNoneFlipX);
                                spr.RotateFlip(RotateFlipType.RotateNoneFlipY);
                                posX_int += spr.Width;
                                posY_int += spr.Height;
                            }



                            if (a.Shown == true)
                            {
                                System.Drawing.Bitmap finalImage = null;
                                finalImage = new System.Drawing.Bitmap(posX_int + spr.Width, posY_int + spr.Height);
                                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
                                {
                                    g.Clear(System.Drawing.Color.Transparent);
                                    g.DrawImage(spr,
                                                new System.Drawing.Rectangle(posX_int, posY_int, spr.Width, spr.Height));
                                }
                                Array.Resize(ref bm_processed, bm_processed.Length + 1);
                                bm_processed[bm_processed.Length - 1] = finalImage;
                            }

                            /*if (a.Alignment[0] == 0 && a.Alignment[1] == 0)
                             * {
                             *//*int x = 0;
                             *  int y = 0;
                             *  Point sprite_center = new Point(spr.Width / 2, spr.Height / 2);
                             *
                             *  x = total_center.X - (sprite_center.X);///2);// + posX_int);*//*
                             *  y = total_center.Y - (sprite_center.Y);///2);// + posY_int);
                             *
                             *
                             *//*if (posX_int < 0)
                             *  {
                             *      posX_int = x - posX_int;
                             *  }
                             *  else
                             *  {
                             *      posX_int += x;
                             *  }
                             *
                             *  if (posY_int < 0)
                             *  {
                             *      posY_int = y - posY_int;
                             *  }
                             *  else
                             *  {
                             *      posY_int += y;
                             *  }*//*
                             *
                             * }
                             *
                             *//*if (a.Flip == 1)
                             * {
                             *  spr.RotateFlip(RotateFlipType.RotateNoneFlipX);
                             *  posX += spr.Width;
                             * }
                             * if (a.Flip == 2)
                             * {
                             *  spr.RotateFlip(RotateFlipType.RotateNoneFlipY);//.RotateNoneFlipX);
                             *  posY += spr.Height;
                             * }
                             * if (a.Flip == 3)
                             * {
                             *  spr.RotateFlip(RotateFlipType.RotateNoneFlipX);
                             *  spr.RotateFlip(RotateFlipType.RotateNoneFlipY);
                             *  posX += spr.Width;
                             *  posY += spr.Height;
                             * }*/

                            /*width += spr.Width;
                             * height = spr.Height > height ? spr.Height : height;
                             * Point finalImage_center = new Point(posX + spr.Width/2, posY + spr.Height/2);
                             * Point sprite_center = new Point(spr.Width/2,spr.Height/2);*/
                        }
                        i++;
                    }
                }
            }
        }