示例#1
0
        public static KTouchEvent CreateFromEventNode(XmlNode eventNode)
        {
            if (eventNode.Name != "event")
            {
                throw KmlParseException.ExpectedDifferentNode("event", eventNode);
            }

            var ev = new KTouchEvent();

            var typeAttr = eventNode.Attributes["type"];

            if (typeAttr == null)
            {
                throw KmlParseException.MissingRequiredAttribute("type", eventNode);
            }
            ev.Type = typeAttr.Value;

            var actionAttr = eventNode.Attributes["action"];

            if (actionAttr == null)
            {
                throw KmlParseException.MissingRequiredAttribute("action", eventNode);
            }
            ev.Action = actionAttr.Value;

            var globalAttr = eventNode.Attributes["global"];

            if (globalAttr != null)
            {
                ev.Switch = globalAttr.Value;
            }

            ev.SwitchText = eventNode.InnerText.Trim();

            return(ev);
        }
示例#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);
        }