Exemplo n.º 1
0
 public Anim Copy(Sprite _parent)
 {
     Anim anim = new Anim(_parent);
     anim.fps = fps;
     anim.size = size;
     foreach (var f in frames)
     {
         anim.frames.Add(f.Copy());
     }
     return anim;
 }
Exemplo n.º 2
0
        public static Sprite Load(string inpath)
        {
            Sprite spr = new Sprite(inpath);

            if (inpath == null) return spr;
            spr.seeds.Clear();//LoadSeeds
            {
                if (System.IO.Path.DirectorySeparatorChar == '\\')
                    inpath = inpath.Replace("/", "\\");
                else
                    inpath = inpath.Replace("\\", "/");
                string file = System.IO.Path.Combine(inpath, "seeds.bin.bytes");
                using (System.IO.Stream os = TitleContainer.OpenStream(file))
                {
            #if USECompression
                    using (GZipStream s = new GZipStream(os, CompressionMode.Decompress))
            #else
                    var s = os;
            #endif
                    {
                        byte[] bb = new byte[256];

                        s.Read(bb, 0, 2);
                        UInt16 len = BitConverter.ToUInt16(bb, 0);
                        for (int i = 0; i < len; i++)
                        {
                            int slen = s.ReadByte();
                            s.Read(bb, 0, slen);
                            Seed seed = new Seed();
                            seed.Read(s);
                            string name = System.Text.Encoding.UTF8.GetString(bb, 0, slen);
                            spr.seeds[name] = seed;
                        }
                    }
                }
            }
            string[] files = null;
            {
                using (System.IO.Stream s = TitleContainer.OpenStream(System.IO.Path.Combine( inpath , "anims.txt")))
                {
                    byte[] buf = new byte[65536];
                    int buflen = (int)s.Read(buf, 0, 65536);
                    //byte[] b = new byte[s.Length];
                    //s.Read(b, 0, b.Length);
                    string txt = System.Text.Encoding.UTF8.GetString(buf,0,buflen);
                    files = txt.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    while(!char.IsLetter(files[0][0]))
                    {
                        files[0]=files[0].Substring(1);
                    }
                }
            }
            //string[] files = System.IO.Directory.GetFiles(inpath, "*.anim.bin");
            foreach (var _f in files)
            {
                string f =_f;
                if(System.IO.Path.DirectorySeparatorChar=='/')
                {
                    f=f.Replace('\\','/');
                }
                string fname =System.IO.Path.GetFileName(f);
                fname = System.IO.Path.Combine(inpath,fname);
                using (System.IO.Stream ss = TitleContainer.OpenStream(fname))
                {
                    Anim ani = new Anim(spr);
                    ani.Read(ss);
                    string name = System.IO.Path.GetFileNameWithoutExtension(f);
                    name = System.IO.Path.GetFileNameWithoutExtension(name);
                    spr.anims[name] = ani;
                }
            }
            return spr;
        }
Exemplo n.º 3
0
        public Anim FillAni()
        {
            Anim anim = new Anim(cursprite);
            if (this.datadom.listTimeLine.Count == 0)
            {
                logger.Log(LogLevel.Error, "this.datadom.listTimeLine.Count == 0");
                return null;
            }
            anim.size.X = datadom.width;
            anim.size.Y = datadom.height;
            int maxframe = 0;

            //Dictionary<string, string> part2bone = new Dictionary<string, string>();
            //foreach (var p in data.Parts)
            //{
            //    part2bone[p.type] = p.bone;
            //}

            foreach (var l in this.datadom.listTimeLine[0].layers)//不使用层名称
            {
                int frameid = 0;
                // List<aniconv.xfl.data_domdoc.DOMTimeline.DOMLayer.DOMFrame> framesneedcopy = new List<data_domdoc.DOMTimeline.DOMLayer.DOMFrame>();
                foreach (var f in l.frames)
                {
                    if (f.duration > 1)
                    {
                        frameid = f.index + f.duration - 1;
                        //framesneedcopy.Add(f);
                    }
                    frameid = Math.Max(f.index, frameid);
                }
                maxframe = Math.Max(frameid, maxframe);
            }

            anim.frames.Clear();
            while (anim.frames.Count <= maxframe)
            {
                anim.frames.Add(new Frame());
            }

            // anim.ResetFrameCount(maxframe);

            foreach (var l in this.datadom.listTimeLine[0].layers)
            {
                foreach (var f in l.frames)
                {
                    if (f.element.listbelements.Count > 0)
                    {
                        Element elem = new Element();
                        anim.frames[f.index].elems.Add(elem);

                        Matrix mat;
                        if (f.__elements[0].matrix.Count > 0)
                            mat = f.__elements[0].matrix[0];
                        else
                            mat = new Matrix();
                        elem.pos.X = mat.tx;// +f.elements[0].transformationPoint.;// -data.SizeX / 2;
                        elem.pos.Y = mat.ty;// +data.SizeY;

                        var s = mat.GetScale();
                        elem.scale.X = s.X;
                        elem.scale.Y = s.Y;
                        if (s.Y < 0)
                        {

                        }
                        elem.rotate = -mat.GetRotate();// / (float)Math.PI * -180.0f;

                        //f.elements[0].libraryItemName 类型
                        string seedoname = System.IO.Path.GetFileNameWithoutExtension(f.__elements[0].libraryItemName);
                        string seedname = seedoname + "_b";
                        GenSeed_R(f.__elements[0].libraryItemName, mainpath);
                        if (cursprite.seeds.ContainsKey(seedname)==false)
                        {
                            Seed seed = new Seed();
                            seed.size = cursprite.seeds[seedoname].size;
                            seed.orient = new Microsoft.Xna.Framework.Vector2();
                            seed.texname = cursprite.seeds[seedoname].texname;
                            cursprite.seeds[seedname] = seed;
                        }
                        elem.seed = seedname;
                        elem.seednow = elem.seed;
                        elem.sound = f.soundName;
                        elem.tag = f.name;
                        //if (f._elements[0].color.Count > 0)
                        //{
                        //    elem.color.A = (byte)(f.__elements[0].color[0].alphaMultiplier * 255);
                        //    elem.color.R = (byte)(f.__elements[0].color[0].redMultiplier * 255);
                        //    elem.color.G = (byte)(f.__elements[0].color[0].greenMultiplier * 255);
                        //    elem.color.B = (byte)(f.__elements[0].color[0].blueMultiplier * 255);
                        //    int i = f._elements[0].color[0].redOffset;
                        //    if (i > 255) i = 255;
                        //    elem.coloradd.R = (byte)i;
                        //    i = f._elements[0].color[0].greenOffset;
                        //    if (i > 255) i = 255;
                        //    elem.coloradd.G = (byte)i;
                        //    i = f._elements[0].color[0].blueOffset;
                        //    if (i > 255) i = 255;
                        //    elem.coloradd.B = (byte)i;

                        //}
                        if (f.duration > 0)
                        {
                            for (int i = 1; i < f.duration; i++)
                            {
                                anim.frames[f.index + i].elems.Add(elem.Copy());
                            }
                        }
                    }
                    else if (f._elements.Count > 0)
                    {
                        Element elem = new Element();
                        anim.frames[f.index].elems.Add(elem);

                        Matrix mat;
                        if (f._elements[0].matrix.Count > 0)
                            mat = f._elements[0].matrix[0];
                        else
                            mat = new Matrix();
                        elem.pos.X = mat.tx;// +f.elements[0].transformationPoint.;// -data.SizeX / 2;
                        elem.pos.Y = mat.ty;// +data.SizeY;

                        var s = mat.GetScale();
                        elem.scale.X = s.X;
                        elem.scale.Y = s.Y;
                        if (s.Y < 0)
                        {

                        }
                        elem.rotate = -mat.GetRotate();// / (float)Math.PI * -180.0f;

                        //f.elements[0].libraryItemName 类型
                        elem.seed = seedchange[f._elements[0].libraryItemName];// cursprite.seeds[f.elements[0].libraryItemName];
                        elem.seednow = elem.seed;
                        elem.sound = f.soundName;
                        elem.tag = f.name;
                        if (f._elements[0].color.Count > 0)
                        {
                            elem.color.A = (byte)(f._elements[0].color[0].alphaMultiplier * 255);
                            elem.color.R = (byte)(f._elements[0].color[0].redMultiplier * 255);
                            elem.color.G = (byte)(f._elements[0].color[0].greenMultiplier * 255);
                            elem.color.B = (byte)(f._elements[0].color[0].blueMultiplier * 255);
                            int i = f._elements[0].color[0].redOffset;
                            if (i > 255) i = 255;
                            elem.coloradd.R = (byte)i;
                            i = f._elements[0].color[0].greenOffset;
                            if (i > 255) i = 255;
                            elem.coloradd.G = (byte)i;
                            i = f._elements[0].color[0].blueOffset;
                            if (i > 255) i = 255;
                            elem.coloradd.B = (byte)i;

                        }
                        if (f.duration > 0)
                        {
                            for (int i = 1; i < f.duration; i++)
                            {
                                anim.frames[f.index + i].elems.Add(elem.Copy());
                            }
                        }
                    }

                    if(string.IsNullOrEmpty( f.name)==false)
                    {
                        anim.frames[f.index].AddTag(f.name);
                        for (int i = 1; i < f.duration; i++)
                        {
                            anim.frames[f.index+i].AddTag(f.name);
                        }
                    }

                }

            }
            return anim;
        }
Exemplo n.º 4
0
        //public DrawFrame GetFrameByAdvTime(float delta)
        //{
        //    int lastid = (int)(timer * fps);
        //    if (play)
        //    {
        //        timer += delta;
        //    }
        //    int newid = (int)(timer * fps);
        //    while (newid - lastid > 1)
        //    {
        //        timer -= 1.0f / fps;//限制不跳帧
        //        newid --;
        //    }



        //    return frames[newid];
        //}
        public static SpriteAni CreateAni(Anim data, TextureMgr tmgr, string texpath = "")
        {
            SpriteAni ani = new SpriteAni();

            ani.fps = data.fps;
            while (ani.frames.Count < data.frames.Count)
            {
                ani.frames.Add(new DrawFrame(data.size));
            }
            int lastframe = 0;

            for (int i = 0; i < data.frames.Count; i++)
            {
                //while (ani.frames[i].drawElements.Count < data.frames[i].elems.Count)
                //{
                //    ani.frames[i].drawElements.Add(new DrawElement());
                //}
                #region fill frame
                for (int j = data.frames[i].elems.Count - 1; j >= 0; j--)
                {
                    if (string.IsNullOrEmpty(data.frames[i].elems[j].seednow))
                    {
                        continue;
                    }
                    DrawElement e = new DrawElement();
                    //在这里要反转层顺序


                    Element se = data.frames[i].elems[j];
                    if (string.IsNullOrEmpty(se.sound) == false)
                    {
                        ani.frames[i].sounds.Add(se.sound);
                        Console.WriteLine("find sound:" + se.sound);
                    }
                    e.Fill(data, se, tmgr, texpath);
                    if (e.isdummy == true || string.IsNullOrWhiteSpace(se.seedasdummy) == false)
                    {
                        Dummy dm = new Dummy();
                        dm.pos    = e.pos;
                        dm.rotate = e.rotate;
                        dm.name   = e.tag;
                        if (string.IsNullOrWhiteSpace(se.seedasdummy) == false)
                        {
                            dm.name = se.seedasdummy;
                        }
                        dm.seed = se.seed;
                        dm.elem = e;
                        ani.frames[i].dummys.Add(dm);
                    }
                    if (!e.isdummy)
                    {
                        ani.frames[i].drawElements.Add(e);

                        string tag = "";
                        if (string.IsNullOrEmpty(se.tag) == false)
                        {
                            tag = se.tag;
                        }
                        else
                        {
                            tag = "";
                        }
                        if (tag != "")
                        {
                            if (ani.frames[i].bounds.ContainsKey("") == false)
                            {
                                ani.frames[i].bounds[""] = e.bounds;
                            }
                            else
                            {
                                RectangleF src = ani.frames[i].bounds[""];
                                ani.frames[i].bounds[""] = RectangleF.Union(src, e.bounds);
                            }
                        }
                        if (ani.frames[i].bounds.ContainsKey(tag) == false)
                        {
                            ani.frames[i].bounds[tag] = e.bounds;
                        }
                        else
                        {
                            RectangleF src = ani.frames[i].bounds[tag];
                            ani.frames[i].bounds[tag] = RectangleF.Union(src, e.bounds);
                        }
                    }
                }
                #endregion
                if (i == 0 && data.frames[0].frametags.Count == 0)
                {
                    ani.elements["in"] = new AniElement(ani, 0, data.frames.Count - 1, false);
                }
                if (i == data.frames.Count - 1 && data.frames[i].frametags.Count == 0 && lastframe > 0)
                {
                    ani.elements["out"] = new AniElement(ani, lastframe + 1, data.frames.Count - 1, false);
                }
                if (data.frames[i].frametags.Count > 0)
                {
                    lastframe = i;
                    if (ani.elements.ContainsKey("in"))
                    {
                        if (ani.elements["in"].frameend == data.frames.Count - 1)
                        {
                            ani.elements["in"].frameend = i - 1;
                            ani.elements["in"].FixLife();
                        }
                    }
                }
                foreach (var tag in data.frames[i].frametags)
                {
                    if (ani.elements.ContainsKey(tag))
                    {
                        ani.elements[tag].frameend = i;
                        ani.elements[tag].FixLife();
                    }
                    else
                    {
                        ani.elements[tag] = new AniElement(ani, i, i, true);
                    }
                }
            }
            string[] ttags = new string[ani.framecount];
            foreach (var e in ani.elements)
            {
                for (int i = e.Value.framestart; i <= e.Value.frameend; i++)
                {
                    ttags[i] = e.Key;
                }
            }
            string begintag = "";
            int    begini   = 0;
            for (int i = 0; i < ani.framecount; i++)
            {
                if (string.IsNullOrEmpty(ttags[i]) == false)
                {
                    if (begintag != ttags[i])
                    {
                        if (begintag == "")
                        {
                        }
                        else
                        {
                            string endtag = ttags[i];
                            if (begini + 1 <= i - 1)
                            {
                                ani.elements[begintag + "-" + endtag] = new AniElement(ani, begini + 1, i - 1, false);
                            }
                        }
                    }
                    begintag = ttags[i];
                    begini   = i;
                }
            }
            ani.allelement = new AniElement(ani, 0, ani.framecount - 1, true);
            return(ani);
        }
Exemplo n.º 5
0
        public static Sprite Load(string inpath)
        {
            Sprite spr = new Sprite(inpath);

            if (inpath == null)
            {
                return(spr);
            }
            spr.seeds.Clear();//LoadSeeds
            {
                if (System.IO.Path.DirectorySeparatorChar == '\\')
                {
                    inpath = inpath.Replace("/", "\\");
                }
                else
                {
                    inpath = inpath.Replace("\\", "/");
                }
                string file = System.IO.Path.Combine(inpath, "seeds.bin.bytes");
                using (System.IO.Stream os = TitleContainer.OpenStream(file))
                {
#if USECompression
                    using (GZipStream s = new GZipStream(os, CompressionMode.Decompress))
#else
                    var s = os;
#endif
                    {
                        byte[] bb = new byte[256];

                        s.Read(bb, 0, 2);
                        UInt16 len = BitConverter.ToUInt16(bb, 0);
                        for (int i = 0; i < len; i++)
                        {
                            int slen = s.ReadByte();
                            s.Read(bb, 0, slen);
                            Seed seed = new Seed();
                            seed.Read(s);
                            string name = System.Text.Encoding.UTF8.GetString(bb, 0, slen);
                            spr.seeds[name] = seed;
                        }
                    }
                }
            }
            string[] files = null;
            {
                using (System.IO.Stream s = TitleContainer.OpenStream(System.IO.Path.Combine(inpath, "anims.txt")))
                {
                    byte[] buf    = new byte[65536];
                    int    buflen = (int)s.Read(buf, 0, 65536);
                    //byte[] b = new byte[s.Length];
                    //s.Read(b, 0, b.Length);
                    string txt = System.Text.Encoding.UTF8.GetString(buf, 0, buflen);
                    files = txt.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    while (!char.IsLetter(files[0][0]))
                    {
                        files[0] = files[0].Substring(1);
                    }
                }
            }
            //string[] files = System.IO.Directory.GetFiles(inpath, "*.anim.bin");
            foreach (var _f in files)
            {
                string f = _f;
                if (System.IO.Path.DirectorySeparatorChar == '/')
                {
                    f = f.Replace('\\', '/');
                }
                string fname = System.IO.Path.GetFileName(f);
                fname = System.IO.Path.Combine(inpath, fname);
                using (System.IO.Stream ss = TitleContainer.OpenStream(fname))
                {
                    Anim ani = new Anim(spr);
                    ani.Read(ss);
                    string name = System.IO.Path.GetFileNameWithoutExtension(f);
                    name            = System.IO.Path.GetFileNameWithoutExtension(name);
                    spr.anims[name] = ani;
                }
            }
            return(spr);
        }