Ejemplo n.º 1
0
            // Trying to find the maximum occurances per frame of each sprite, so we know how many
            // spriteName_#s we need to account for.
            // E.g. if foo_0 is used up to twice a frame, we need foo_0_0 and foo_0_1.
            // Otherwise we only need foo_0
            public Dictionary <SpriteName, int> BuildHistogram(AnimHashTable animHashes)
            {
                var overallHistogram = new Dictionary <SpriteName, int>();

                // Count the frequency of spriteNames used.
                foreach (var frame in Frames)
                {
                    var perFrameHistogram = new Dictionary <SpriteName, int>();
                    foreach (var element in frame.Elements)
                    {
                        var name = element.FindName(animHashes);
                        if (perFrameHistogram.ContainsKey(name))
                        {
                            perFrameHistogram[name] += 1;
                        }
                        else
                        {
                            perFrameHistogram[name] = 1;
                        }
                    }

                    // merge the frame's entries to the overall anim's entries
                    foreach (var entry in perFrameHistogram)
                    {
                        if (!overallHistogram.ContainsKey(entry.Key) || overallHistogram[entry.Key] < entry.Value)
                        {
                            overallHistogram[entry.Key] = entry.Value;
                        }
                    }
                }

                return(overallHistogram);
            }
Ejemplo n.º 2
0
        public static void LogDebug(Logger logger, AnimHashTable hashes)
        {
            var builder = new StringBuilder();

            foreach (var entry in hashes)
            {
                builder.Append($"value {entry.Key} maps onto symbol {entry.Value}\n");
            }
            logger.Debug(builder.ToString());
        }
Ejemplo n.º 3
0
        public void Update(KAnim.Element element, AnimHashTable animHashes)
        {
            var name = element.FindName(animHashes);

            if (!ContainsKey(name))
            {
                this[name] = 0;
            }
            else
            {
                this[name] += 1;
            }
        }
Ejemplo n.º 4
0
            // Build a map of object indexes.
            // We sequentially assign an object index to each object.
            // So foo_0_0 and foo_0_1 will have different indices, but
            // foo_0_0 in a different frame will reference the same object... i think
            public Dictionary <SpriterObjectName, int> BuildIdMap(AnimHashTable animHashes)
            {
                if (animHashes == prevHashTable)
                {
                    return(ObjectIdMap);
                }
                var histogram = BuildHistogram(animHashes);
                var idMap     = new Dictionary <SpriterObjectName, int>();
                var index     = 0;

                foreach (var entry in histogram)
                {
                    var name        = entry.Key;
                    var occurrences = entry.Value;
                    for (var i = 0; i < occurrences; i++)
                    {
                        idMap[name.ToSpriterObjectName(i)] = index++;
                    }
                }

                ObjectIdMap   = idMap;
                prevHashTable = animHashes;
                return(idMap);
            }
Ejemplo n.º 5
0
        public SpriterObjectName FindObjectName(KAnim.Element element, AnimHashTable animHashes)
        {
            var name = element.FindName(animHashes);

            return(name.ToSpriterObjectName(this[name]));
        }
Ejemplo n.º 6
0
 // This gets the name of the sprite but at any given index in the symbol. This is important for testing if certain indices
 // exist within a given symbol
 public SpriteName FindNameWithGivenIndex(AnimHashTable animHashes, int index)
 {
     return(new SpriteName($"{animHashes[ImageHash]}_{index}"));
 }
Ejemplo n.º 7
0
 // This method gets the name of the sprite plus its index which we don't use when building our internal
 // representation of the animation but we need to use in order to reference the sprite on disk for actually
 // indicating which sprite out of the symbol's frames we need to swap to on any given frame
 public SpriteName FindNameWithIndex(AnimHashTable animHashes)
 {
     return(new SpriteName($"{animHashes[ImageHash]}_{Index}"));
 }
Ejemplo n.º 8
0
 // Finding the name of a sprite should only look at the sprite itself, not its index in the
 // symbol because this way all indices of a symbol can be part of the same timeline and just
 // be sprite-swapped between in the SCML
 public SpriteName FindName(AnimHashTable animHashes)
 {
     return(new SpriteName(animHashes[ImageHash]));
 }