Exemplo n.º 1
0
        private XmlElement MakeObjectRefNode(XmlDocument scml, Animation.Frame frame, Animation.Element element, int frameId, int elementId, SpriteIdProvider spriteIdProvider, SymbolIdProvider symbolIdProvider)
        {
            XmlElement objectRef = scml.CreateElement(string.Empty, "object_ref", string.Empty);
            string     id        = spriteIdProvider.GetId(frame, element).ToString();

            objectRef.SetAttribute("id", id);
            objectRef.SetAttribute("parent", symbolIdProvider.GetId(frame, element).ToString());
            objectRef.SetAttribute("timeline", id);
            objectRef.SetAttribute("key", frameId.ToString());
            objectRef.SetAttribute("z_index", (frame.Elements - elementId).ToString());
            return(objectRef);
        }
        private List <XmlElement> MakeTimelineNodes(XmlDocument scml, Bank bank, FileIdProvider fileIdProvider)
        {
            var rate             = (int)(MsPerS / bank.Rate);
            var spriteIdProvider = new SpriteIdProvider(bank, AnimationFile.AnimData.HashToName);
            var idToTimeline     = new Dictionary <int, XmlElement>();

            foreach (var name in spriteIdProvider.IdMap.Keys)
            {
                var timeline = scml.CreateElement(string.Empty, "timeline", string.Empty);
                var id       = spriteIdProvider.IdMap[name];
                timeline.SetAttribute("id", id.ToString());
                timeline.SetAttribute("name", name);
                idToTimeline.Add(id, timeline);
            }

            var symbolIdProvider = new SymbolIdProvider(bank, AnimationFile.AnimData.HashToName);

            foreach (var name in symbolIdProvider.IdMap.Keys)
            {
                var timeline = scml.CreateElement(string.Empty, "timeline", string.Empty);
                var id       = symbolIdProvider.IdMap[name];
                timeline.SetAttribute("id", (id + spriteIdProvider.IdMap.Count).ToString());
                timeline.SetAttribute("name", name);
                timeline.SetAttribute("object_type", "bone");
                idToTimeline.Add(id + spriteIdProvider.IdMap.Count, timeline);
            }

            var frameId = 0;

            foreach (var frame in bank.FramesList)
            {
                foreach (var element in frame.ElementsList)
                {
                    idToTimeline[spriteIdProvider.GetId(frame, element)].AppendChild(
                        MakeTimelineKeyNode(scml, element, frameId, rate, fileIdProvider, ChildType.Sprite));
                    idToTimeline[symbolIdProvider.GetId(frame, element) + spriteIdProvider.IdMap.Count]
                    .AppendChild(MakeTimelineKeyNode(scml, element, frameId, rate, fileIdProvider, ChildType.Bone));
                }

                frameId++;
            }

            var timelines = new List <XmlElement>();

            foreach (var timeline in idToTimeline.Values)
            {
                timelines.Add(timeline);
            }
            return(timelines);
        }