Esempio n. 1
0
        public static Rect Calc_Bound(KAnim.Anim anim, KAnim.Element elem)
        {
            //if(anim.parent.seeds.ContainsKey(elem.seednow)==false)
            //{
            //    Debug.LogError("failed Calc_Bound:" + elem.seednow);
            //}
            var seed = anim.parent.seeds[elem.seednow];
            //string filename = System.IO.Path.GetFileNameWithoutExtension(elem.seed.texname);
            //block = tmgr.GetTexture(System.IO.Path.Combine(texpath, seed.texname));
            var seedorient = seed.orient;
            //seedsize = seed.size;
            //color = elem.color;
            var pos   = elem.pos;
            var scale = elem.scale;

            var     rotate    = elem.rotate;
            Vector2 seed_size = seed.size;

            seed_size.x *= scale.x;
            seed_size.y *= scale.y;
            Vector2 seed_orient = seed.orient;

            seed_orient.x *= scale.x;
            seed_orient.y *= scale.y;
            var bounds = Seed.CalcRotate(seed_size, seed_orient, rotate);

            //bounds.Offset(pos.X, pos.Y);
            bounds.x += pos.x;
            bounds.y += pos.y;
            return(bounds);
        }
Esempio n. 2
0
        public void Update(KAnim.Element element, AnimHashTable animHashes)
        {
            var name = element.FindName(animHashes);

            if (!ContainsKey(name))
            {
                this[name] = 0;
            }
            else
            {
                this[name] += 1;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Takes in an element in a frame and determines what a preceding file name would be.
        /// This is necessary because for some reason in some select animations, klei only exports
        /// every other frame of an animation into the sprite atlas and build file but references
        /// every frame in the animation.
        ///
        /// Ex. in the oilfloater the skirt has like twenty animation states but only skirt_0, skirt_2, skirt_4, etc...
        /// are defined but the animation looks for skirt_0, skirt_1, skirt_2, skirt_3, etc...
        ///
        /// So when we find an undefined filename like skirt_3 rather than immediately erroring we go back in idices to
        /// see if another frame for this symbol exists, so first we check skirt_2 (b/c 2 = 3 - 1) and then if that
        /// didn't exist we would try skirt_1 ... all the way to skirt_0 before stopping.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        private Filename GetPrecedingFilename(KAnim.Element element)
        {
            int index = element.Index - 1;

            while (index >= 0)
            {
                var filename = element.FindNameWithGivenIndex(AnimHashes, index).ToFilename();
                if (filenameindex.ContainsKey(filename))
                {
                    return(filename);
                }
                index--;
            }
            return(null);
        }
Esempio n. 4
0
        public SpriterObjectName FindObjectName(KAnim.Element element, AnimHashTable animHashes)
        {
            var name = element.FindName(animHashes);

            return(name.ToSpriterObjectName(this[name]));
        }
Esempio n. 5
0
        private void ParseAnims(BinaryReader reader)
        {
            var animData = new KAnim.Anim
            {
                Version      = reader.ReadInt32(),
                ElementCount = reader.ReadInt32(),
                FrameCount   = reader.ReadInt32(),
                AnimCount    = reader.ReadInt32(),
                Anims        = new List <KAnim.AnimBank>()
            };

            Utilities.LogToDump(
                $"  Version: {animData.Version}\n" +
                $"  # elements: {animData.ElementCount}\n" +
                $"  # frames: {animData.FrameCount}\n" +
                $"  # anims: {animData.AnimCount}\n" +
                "\n<Anims>", Logger);

            for (var i = 0; i < animData.AnimCount; i++)
            {
                var name = reader.ReadPString();
                var hash = reader.ReadInt32();
                var bank = new KAnim.AnimBank
                {
                    Name       = name,
                    Hash       = hash,
                    Rate       = reader.ReadSingle(),
                    FrameCount = reader.ReadInt32(),
                    Frames     = new List <KAnim.Frame>()
                };

                Utilities.LogToDump(
                    $"  Anim \"{bank.Name}\" (hash {bank.Hash}): {bank.FrameCount} frames @ {bank.Rate} fps", Logger);

                for (var j = 0; j < bank.FrameCount; j++)
                {
                    var frame = new KAnim.Frame
                    {
                        X            = reader.ReadSingle(),
                        Y            = reader.ReadSingle(),
                        Width        = reader.ReadSingle(),
                        Height       = reader.ReadSingle(),
                        ElementCount = reader.ReadInt32(),
                        Elements     = new List <KAnim.Element>()
                    };
                    Utilities.LogToDump(
                        $"    Frame @ ({frame.X}, {frame.Y}) is {frame.Width}x{frame.Height}. {frame.ElementCount} sub-elements.",
                        Logger);

                    for (var k = 0; k < frame.ElementCount; k++)
                    {
                        var element = new KAnim.Element
                        {
                            ImageHash = reader.ReadInt32(),
                            Index     = reader.ReadInt32(),
                            Layer     = reader.ReadInt32(),
                            Flags     = reader.ReadInt32(),
                            A         = reader.ReadSingle(),
                            B         = reader.ReadSingle(),
                            G         = reader.ReadSingle(),
                            R         = reader.ReadSingle(),
                            M1        = reader.ReadSingle(),
                            M2        = reader.ReadSingle(),
                            M3        = reader.ReadSingle(),
                            M4        = reader.ReadSingle(),
                            M5        = reader.ReadSingle(),
                            M6        = reader.ReadSingle(),
                            Order     = reader.ReadSingle()
                        };

                        string plainName;
                        try
                        {
                            plainName = $"(\"{BuildHashes[element.ImageHash]}\")";
                        } catch (KeyNotFoundException)
                        {
                            plainName = "(plain name not found)";
                        }
                        Utilities.LogToDump(
                            $"      Sub-element #{element.Index} is {element.ImageHash} {plainName} @ layer {element.Layer}\n" +
                            $"        Matrix: ({element.M1} {element.M2} {element.M3} {element.M4}), translate {element.M5} {element.M6}. Order {element.Order}",
                            Logger);

                        frame.Elements.Add(element);
                    }

                    bank.Frames.Add(frame);
                }

                animData.Anims.Add(bank);
            }

            animData.MaxVisibleSymbolFrames = reader.ReadInt32();
            Utilities.LogToDump($"  Max visible frames: {animData.MaxVisibleSymbolFrames}", Logger);

            AnimData = animData;
        }