Exemple #1
0
        public void LoadFromData(BinaryReader reader, int totalByteSize)
        {
            frameData  = new FrameData();
            animations = new Dictionary <FrameType, Dictionary <Enums.Direction, Surface> >();

            foreach (FrameType frameType in Enum.GetValues(typeof(FrameType)))
            {
                if (FrameTypeHelper.IsFrameTypeDirectionless(frameType) == false)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        Enums.Direction dir        = GraphicsManager.GetAnimIntDir(i);
                        int             frameCount = reader.ReadInt32();
                        frameData.SetFrameCount(frameType, dir, frameCount);
                        int size = reader.ReadInt32();
                        if (size > 0)
                        {
                            byte[] imgData = reader.ReadBytes(size);
                            using (MemoryStream stream = new MemoryStream(imgData))
                            {
                                Bitmap  bitmap       = (Bitmap)Image.FromStream(stream);
                                Surface sheetSurface = new Surface(bitmap);
                                sheetSurface.Transparent = true;

                                AddSheet(frameType, dir, sheetSurface);

                                frameData.SetFrameSize(sheetSurface.Width, sheetSurface.Height, frameCount);
                            }
                        }
                    }
                }
                else
                {
                    int frameCount = reader.ReadInt32();
                    frameData.SetFrameCount(frameType, Enums.Direction.Down, frameCount);
                    int size = reader.ReadInt32();
                    if (size > 0)
                    {
                        byte[] imgData = reader.ReadBytes(size);

                        using (MemoryStream stream = new MemoryStream(imgData))
                        {
                            Bitmap  bitmap       = (Bitmap)Image.FromStream(stream);
                            Surface sheetSurface = new Surface(bitmap);
                            sheetSurface.Transparent = true;

                            AddSheet(frameType, Enums.Direction.Down, sheetSurface);

                            frameData.SetFrameSize(sheetSurface.Width, sheetSurface.Height, frameCount);
                        }
                    }
                }
            }

            this.sizeInBytes = totalByteSize;
        }
Exemple #2
0
        public void Load(SpriteSheet sheet, FrameData frameData, string overrideForm)
        {
            string formDirectory = "Forms/" + overrideForm + "/";

            frameData.SetFrameSize(FrameWidth, FrameHeight);
            using (ZipFile zipFile = ZipFile.Read(path))
            {

                foreach (FrameType frameType in Enum.GetValues(typeof(FrameType)))
                {
                    if (FrameTypeHelper.IsFrameTypeDirectionless(frameType) == false)
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            Enums.Direction dir = GraphicsManager.GetAnimIntDir(i);

                            using (MemoryStream ms = new MemoryStream())
                            {
                                string fullImageString = formDirectory + GetFrameTypeString(frameType) + "-" + GetDirectionString(dir) + ".png";

                                if (zipFile.ContainsEntry(fullImageString))
                                {
                                    zipFile[fullImageString].Extract(ms);

                                    ms.Seek(0, SeekOrigin.Begin);
                                    Bitmap bitmap = (Bitmap)Image.FromStream(ms);
                                    Surface sheetSurface = new Surface(bitmap);
                                    sheetSurface.Transparent = true;

                                    sheet.AddSheet(frameType, dir, sheetSurface);

                                    frameData.SetFrameCount(frameType, dir, bitmap.Width / frameData.FrameWidth);
                                }
                                else
                                {
                                    frameData.SetFrameCount(frameType, dir, 0);
                                }
                            }
                        }
                    }
                    else
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            string fullImageString = formDirectory + GetFrameTypeString(frameType) + "-" + GetDirectionString(Enums.Direction.Down) + ".png";

                            if (zipFile.ContainsEntry(fullImageString))
                            {
                                zipFile[fullImageString].Extract(ms);

                                ms.Seek(0, SeekOrigin.Begin);
                                Bitmap bitmap = (Bitmap)Image.FromStream(ms);
                                Surface sheetSurface = new Surface(bitmap);
                                sheetSurface.Transparent = true;

                                sheet.AddSheet(frameType, Enums.Direction.Down, sheetSurface);

                                frameData.SetFrameCount(frameType, Enums.Direction.Down, bitmap.Width / frameData.FrameWidth);
                            }
                            else
                            {
                                frameData.SetFrameCount(frameType, Enums.Direction.Down, 0);
                            }
                        }
                    }
                }
            }
        }
        ////Duplicate code!
        public void Load(SpriteSheet sheet, FrameData frameData, string overrideForm)
        {
            string formDirectory = "Forms/" + overrideForm + "/";

            frameData.SetFrameSize(FrameWidth, FrameHeight);
            using (ZipFile zipFile = ZipFile.Read(path))
            {
                foreach (FrameType frameType in Enum.GetValues(typeof(FrameType)))
                {
                    if (FrameTypeHelper.IsFrameTypeDirectionless(frameType) == false)
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            Enums.Direction dir = GraphicsManager.GetAnimIntDir(i);

                            using (MemoryStream ms = new MemoryStream()) {
                                //string fullImageString = formDirectory + GetFrameTypeString(frameType) + "-" + GetDirectionString(dir) + ".png";
                                string fullImageString = formDirectory + frameType.ToString() + "-" + dir.ToString() + ".png";

                                if (zipFile.ContainsEntry(fullImageString))
                                {
                                    zipFile[fullImageString].Extract(ms);

                                    ms.Seek(0, SeekOrigin.Begin);
                                    Bitmap  bitmap       = (Bitmap)Image.FromStream(ms);
                                    Surface sheetSurface = new Surface(bitmap);
                                    sheetSurface.Transparent = true;

                                    //still loads from these
                                    sheet.AddSheet(frameType, dir, sheetSurface);

                                    frameData.SetFrameCount(frameType, dir, bitmap.Width / frameData.FrameWidth);
                                }
                                else
                                {
                                    frameData.SetFrameCount(frameType, dir, 0);
                                }
                            }
                        }
                    }
                    else
                    {
                        using (MemoryStream ms = new MemoryStream()) {
                            //string fullImageString = formDirectory + GetFrameTypeString(frameType) + "-" + GetDirectionString(Enums.Direction.Down) + ".png";
                            string fullImageString = formDirectory + frameType.ToString() + "-Down.png";

                            if (zipFile.ContainsEntry(fullImageString))
                            {
                                zipFile[fullImageString].Extract(ms);

                                ms.Seek(0, SeekOrigin.Begin);
                                Bitmap  bitmap       = (Bitmap)Image.FromStream(ms);
                                Surface sheetSurface = new Surface(bitmap);
                                sheetSurface.Transparent = true;

                                sheet.AddSheet(frameType, Enums.Direction.Down, sheetSurface);

                                frameData.SetFrameCount(frameType, Enums.Direction.Down, bitmap.Width / frameData.FrameWidth);
                            }
                            else
                            {
                                frameData.SetFrameCount(frameType, Enums.Direction.Down, 0);
                            }
                        }
                    }
                }
            }
        }
        public void LoadFromData(BinaryReader reader, int totalByteSize)
        {
            frameData = new FrameData();
            animations = new Dictionary<FrameType, Dictionary<Enums.Direction, Surface>>();

            foreach (FrameType frameType in Enum.GetValues(typeof(FrameType))) {
                if (FrameTypeHelper.IsFrameTypeDirectionless(frameType) == false) {
                    for (int i = 0; i < 8; i++)
                    {
                        Enums.Direction dir = GraphicsManager.GetAnimIntDir(i);
                        int frameCount = reader.ReadInt32();
                        frameData.SetFrameCount(frameType, dir, frameCount);
                        int size = reader.ReadInt32();
                        if (size > 0)
                        {
                            byte[] imgData = reader.ReadBytes(size);
                            using (MemoryStream stream = new MemoryStream(imgData))
                            {

                                Bitmap bitmap = (Bitmap)Image.FromStream(stream);
                                Surface sheetSurface = new Surface(bitmap);
                                sheetSurface.Transparent = true;

                                AddSheet(frameType, dir, sheetSurface);

                                frameData.SetFrameSize(sheetSurface.Width, sheetSurface.Height, frameCount);
                            }
                        }
                    }
                } else {
                    int frameCount = reader.ReadInt32();
                    frameData.SetFrameCount(frameType, Enums.Direction.Down, frameCount);
                    int size = reader.ReadInt32();
                    if (size > 0)
                    {
                        byte[] imgData = reader.ReadBytes(size);

                        using (MemoryStream stream = new MemoryStream(imgData))
                        {

                            Bitmap bitmap = (Bitmap)Image.FromStream(stream);
                            Surface sheetSurface = new Surface(bitmap);
                            sheetSurface.Transparent = true;

                            AddSheet(frameType, Enums.Direction.Down, sheetSurface);

                            frameData.SetFrameSize(sheetSurface.Width, sheetSurface.Height, frameCount);
                        }
                    }
                }
            }

            this.sizeInBytes = totalByteSize;
        }
        public void Load(SpriteSheet sheet, FrameData frameData, string overrideForm)
        {
            string formDirectory = "Forms/" + overrideForm + "/";

            frameData.SetFrameSize(FrameWidth, FrameHeight);
            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var zipFile = new ZipArchive(fileStream))
                {
                    foreach (FrameType frameType in Enum.GetValues(typeof(FrameType)))
                    {
                        if (FrameTypeHelper.IsFrameTypeDirectionless(frameType) == false)
                        {
                            for (int i = 0; i < 8; i++)
                            {
                                Enums.Direction dir = GraphicsManager.GetAnimIntDir(i);

                                using (MemoryStream ms = new MemoryStream())
                                {
                                    string fullImageString = formDirectory + GetFrameTypeString(frameType) + "-" + GetDirectionString(dir) + ".png";

                                    var entry = zipFile.GetEntry(fullImageString);
                                    if (entry != null)
                                    {
                                        using (var entryStream = entry.Open())
                                        {
                                            entryStream.CopyTo(ms);
                                        }

                                        ms.Seek(0, SeekOrigin.Begin);
                                        Bitmap  bitmap       = (Bitmap)Image.FromStream(ms);
                                        Surface sheetSurface = new Surface(bitmap);
                                        sheetSurface.Transparent = true;

                                        sheet.AddSheet(frameType, dir, sheetSurface);

                                        frameData.SetFrameCount(frameType, dir, bitmap.Width / frameData.FrameWidth);
                                    }
                                    else
                                    {
                                        frameData.SetFrameCount(frameType, dir, 0);
                                    }
                                }
                            }
                        }
                        else
                        {
                            using (MemoryStream ms = new MemoryStream())
                            {
                                string fullImageString = formDirectory + GetFrameTypeString(frameType) + "-" + GetDirectionString(Enums.Direction.Down) + ".png";

                                var entry = zipFile.GetEntry(fullImageString);
                                if (entry != null)
                                {
                                    using (var entryStream = entry.Open())
                                    {
                                        entryStream.CopyTo(ms);
                                    }

                                    ms.Seek(0, SeekOrigin.Begin);
                                    Bitmap  bitmap       = (Bitmap)Image.FromStream(ms);
                                    Surface sheetSurface = new Surface(bitmap);
                                    sheetSurface.Transparent = true;

                                    sheet.AddSheet(frameType, Enums.Direction.Down, sheetSurface);

                                    frameData.SetFrameCount(frameType, Enums.Direction.Down, bitmap.Width / frameData.FrameWidth);
                                }
                                else
                                {
                                    frameData.SetFrameCount(frameType, Enums.Direction.Down, 0);
                                }
                            }
                        }
                    }
                }
            }
        }