BrashMonkey.Spriter.Data.IO.SCMLParser.ReadTimeline C# (CSharp) Method

ReadTimeline() private method

private ReadTimeline ( XmlElement element, SpriterAnimation animation ) : void
element System.Xml.XmlElement
animation BrashMonkey.Spriter.Data.ObjectModel.SpriterAnimation
return void
        void ReadTimeline(XmlElement element, SpriterAnimation animation)
        {
            SpriterTimeline timeline = new SpriterTimeline();
            animation.timelines.Add(timeline);

            foreach(XmlAttribute attribute in element.Attributes)
            {
                // id
                if (attribute.Name.Equals("id"))
                    timeline.ID = int.Parse(attribute.Value);

                // name
                else if (attribute.Name.Equals("name"))
                    timeline.name = attribute.Value;

                // object_type
                else if (attribute.Name.Equals("object_type"))
                {
                    timeline.objectTypeRaw = attribute.Value;
                    timeline.objectType = SpriterDataHelpers.ParseSpriterEnum<ObjectType>(timeline.objectTypeRaw);
                }

                // variable_type
                else if (attribute.Name.Equals("variable_type"))
                {
                    timeline.variableTypeRaw = attribute.Value;
                    timeline.variableType = SpriterDataHelpers.ParseSpriterEnum<VariableType>(timeline.variableTypeRaw);
                }

                // usage
                else if (attribute.Name.Equals("usage"))
                {
                    timeline.usageRaw = attribute.Value;
                    timeline.usage = SpriterDataHelpers.ParseSpriterEnum<UsageType>(timeline.usageRaw);
                }
            }

            foreach(XmlElement child in element)
            {
                // meta_data
                if (child.Name.Equals("meta_data"))
                    ReadMetaData(child, timeline.metaData);

                // key
                else if (child.Name.Equals("key"))
                {
                    SpriterTimelineKey key = new SpriterTimelineKey();
                    timeline.keys.Add(key);

                    Vector2 tangents = Vector2.zero;

                    foreach(XmlAttribute attribute in child.Attributes)
                    {
                        // id
                        if (attribute.Name.Equals("id"))
                            key.ID = int.Parse(attribute.Value);

                        // time
                        else if (attribute.Name.Equals("time"))
                            key.time = int.Parse(attribute.Value);

                        // curve_type
                        else if (attribute.Name.Equals("curve_type"))
                        {
                            key.curveTypeRaw = attribute.Value;
                            key.curveType = SpriterDataHelpers.ParseSpriterEnum<CurveType>(key.curveTypeRaw);
                        }

                        // c1, c2
                        else if (attribute.Name.Equals("c1"))
                            tangents.x = float.Parse(attribute.Value);
                        else if (attribute.Name.Equals("c2"))
                            tangents.y = float.Parse(attribute.Value);

                        // spin
                        else if (attribute.Name.Equals("spin"))
                            key.spin = int.Parse(attribute.Value);
                    }

                    // Assign vector values
                    key.curveTangents = tangents;

                    foreach(XmlElement child2 in child)
                    {
                        // meta_data
                        if (child2.Name.Equals("meta_data"))
                            ReadMetaData(child2, key.metaData);

                        // bone
                        else if (child2.Name.Equals("bone"))
                            ReadTimelineBone(child2, key);

                        // object
                        else if (child2.Name.Equals("object"))
                            ReadTimelineObject(child2, key, timeline.variableType);
                    }
                }
            }
        }