Esempio n. 1
0
        private static Pat.Frame ImportFrame(Pat.Project proj, GSPat.GSPatFile pat, GSPat.Frame frame)
        {
            var hasIM = frame.ImageManipulation != null;

            return(new Pat.Frame
            {
                ImageID = AddImageToProject(proj, pat.Images[frame.SpriteID], frame).ImageID,
                OriginX = frame.OriginX,
                OriginY = frame.OriginY,
                ScaleX = hasIM ? frame.ImageManipulation.ScaleX : 100,
                ScaleY = hasIM ? frame.ImageManipulation.ScaleY : 100,
                Alpha = hasIM ? frame.ImageManipulation.Alpha / 255.0f : 1.0f,
                Red = hasIM ? frame.ImageManipulation.Red / 255.0f : 1.0f,
                Green = hasIM ? frame.ImageManipulation.Green / 255.0f : 1.0f,
                Blue = hasIM ? frame.ImageManipulation.Blue / 255.0f : 1.0f,
                Duration = frame.DisplayTime,
                //TODO check if rotation should be inversed
                Rotation = hasIM ? frame.ImageManipulation.Rotation : 0,
                PhysicalBox = ImportPhysicalBox(frame.PhysicsBox),
                HitBoxes = frame.HitBoxes.Select(ImportBox).ToList(),
                AttackBoxes = frame.AttackBoxes.Select(ImportBox).ToList(),
                Points = new List <FramePoint>()
                {
                    ImportPoint(frame.Point0),
                    ImportPoint(frame.Point1),
                    ImportPoint(frame.Point2),
                },
            });
        }
Esempio n. 2
0
        private static List <Pat.AnimationSegment> ImportSegment(Pat.Project proj, GSPat.GSPatFile pat, int index, int segment)
        {
            var start = pat.Animations.FindLastIndex(a => a.AnimationID == index + pat.Animations[0].AnimationID);

            return(pat.Animations
                   .Skip(start + segment).Take(1)
                   .Select(a => ImportSegment(proj, pat, a)).ToList());
        }
Esempio n. 3
0
 public static AnimationSegment ImportSegment(Pat.Project proj, GSPat.GSPatFile pat, GSPat.Animation animation)
 {
     return(new AnimationSegment()
     {
         Damage = ImportDamageInfo(animation),
         CancelLevel = ImportCancelLevelEnum(animation.CancelLevel),
         IsLoop = animation.IsLoop,
         JumpCancellable = ImportCancellable(animation, 0x200000),
         SkillCancellable = ImportCancellable(animation, 0x20),
         Frames = animation.Frames.Select(f => ImportFrame(proj, pat, f)).ToList(),
     });
 }
Esempio n. 4
0
        public static GSPatFile ReadFromStream(Stream stream)
        {
            using (var br = new BinaryReader(stream))
            {
                if (br.ReadByte() != 5)
                {
                    throw new Exception("File format incorrect.");
                }

                var ret = new GSPatFile
                {
                    Images     = new List <string>(),
                    Animations = new List <Animation>(),
                };

                {
                    int imageCount = br.ReadInt16();
                    ret.Images.Capacity = imageCount;

                    var    encoding = Encoding.GetEncoding(932);
                    byte[] buffer   = new byte[0x80];
                    for (int i = 0; i < imageCount; ++i)
                    {
                        if (br.Read(buffer, 0, 0x80) != 0x80)
                        {
                            throw new Exception("File format incorrect.");
                        }
                        int countBytes = Array.FindIndex(buffer, b => b == 0);
                        ret.Images.Add(encoding.GetString(buffer, 0, countBytes));
                    }
                }
                {
                    int animationCount = br.ReadInt32();
                    ret.Animations.Capacity = animationCount;

                    for (int i = 0; i < animationCount; ++i)
                    {
                        ret.Animations.Add(ReadAnimation(br));

                        //sometimes the stream ends before getting all the animations
                        if (br.BaseStream.Position == br.BaseStream.Length)
                        {
                            break;
                        }
                    }
                }

                return(ret);
            }
        }
Esempio n. 5
0
        public static void Write(GSPatFile file, BinaryWriter writer)
        {
            writer.Write((byte)5);

            writer.Write((short)file.Images.Count);
            var encoding = Encoding.GetEncoding(932);

            byte[] buffer = new byte[0x80];
            foreach (var img in file.Images)
            {
                int c = encoding.GetBytes(img, 0, img.Length, buffer, 0);
                buffer[c] = 0;
                writer.Write(buffer);
            }

            writer.Write((int)file.Animations.Count);
            foreach (var animation in file.Animations)
            {
                writer.Write((int)animation.AnimationID);

                if (animation.Type == AnimationType.Clone)
                {
                    writer.Write((short)animation.CloneFrom);
                    writer.Write((short)animation.CloneTo);
                    continue;
                }

                writer.Write((short)animation.AttackLevel);
                writer.Write((short)animation.CancelLevel);
                writer.Write((bool)animation.IsLoop);

                writer.Write((int)animation.Frames.Count);
                foreach (var f in animation.Frames)
                {
                    WriteFrame(writer, f);
                }
            }
        }
Esempio n. 6
0
 public ImageManager(GSPatFile file, string path, Color[] palette)
 {
     _File    = file;
     _Path    = path;
     _Palette = palette;
 }