示例#1
0
        public static KAnimation CreateFromModuleNode(XmlNode moduleNode)
        {
            if (moduleNode.Name != "animation")
            {
                throw new KmlParseException($"Expected 'animation' node, got '{moduleNode.Name}'.");
            }

            var animation = new KAnimation();

            animation.AddRequired(moduleNode, "reacton", "type");
            animation.AddRequired(moduleNode, "action", "action");
            animation.AddOptional(moduleNode, "ease", "ease");
            animation.AddOptional(moduleNode, "anchor", "anchor");
            animation.AddOptional(moduleNode, "rule", "rule");
            animation.AddOptional(moduleNode, "center", "center");
            animation.AddOptional(moduleNode, "filter", "filter");
            animation.AddOptional <double>(moduleNode, "duration", "duration");
            animation.AddOptional <double>(moduleNode, "amount", "amount");
            animation.AddOptional <double>(moduleNode, "speed", "speed");
            animation.AddOptional <double>(moduleNode, "delay", "delay");
            animation.AddOptional <double>(moduleNode, "angle", "angle");
            animation.AddOptional <double>(moduleNode, "trigger", "trigger");

            var keyframeNodes = moduleNode.SelectNodes("keyframe");

            foreach (XmlNode keyframeNode in keyframeNodes)
            {
                animation.Animator.Add(KAnimationKeyframe.CreateFromNode(keyframeNode));
            }

            return(animation);
        }
示例#2
0
        public static KAnimationKeyframe CreateFromNode(XmlNode node)
        {
            if (node.Name != "keyframe")
            {
                throw KmlParseException.ExpectedDifferentNode("keyframe", node);
            }

            var keyframe = new KAnimationKeyframe();

            var propertyAttr = node.Attributes["property"];

            if (propertyAttr == null)
            {
                throw KmlParseException.MissingRequiredAttribute("property", node);
            }
            else
            {
                keyframe.Property = propertyAttr.Value;
            }

            double dbl;

            var positionAttr = node.Attributes["position"];

            if (positionAttr == null)
            {
                throw KmlParseException.MissingRequiredAttribute("position", node);
            }
            else
            {
                if (double.TryParse(positionAttr.Value, out dbl))
                {
                    keyframe.Position = dbl;
                }
                else
                {
                    throw KmlParseException.CouldNotParseValueAsType(positionAttr.Value, typeof(double));
                }
            }

            var valueAttr = node.Attributes["value"];

            if (valueAttr == null)
            {
                throw KmlParseException.MissingRequiredAttribute("value", node);
            }
            else
            {
                if (double.TryParse(valueAttr.Value, out dbl))
                {
                    keyframe.Value = dbl;
                }
                else
                {
                    throw KmlParseException.CouldNotParseValueAsType(valueAttr.Value, typeof(double));
                }
            }

            // ease is the only non-required attribute here
            var easeAttr = node.Attributes["ease"];

            if (easeAttr != null)
            {
                keyframe.Ease = easeAttr.Value;
            }

            return(keyframe);
        }