Ejemplo n.º 1
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);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }