Exemple #1
0
        static bool TryGetAttribute(XmlNode node, string attribute, out CapnpGen.CapBlendMode value)
        {
            value = CapnpGen.CapBlendMode.zero;

            if (node.Attributes[attribute] == null)
            {
                return(false);
            }

            return(Enum.TryParse <CapnpGen.CapBlendMode>(node.Attributes[attribute].Value, out value));
        }
Exemple #2
0
        public static bool ParseBlender(XmlNode blenderNode, List <CapnpGen.CapBlender> blenders, out string error)
        {
            error = "";
            CapnpGen.CapBlender blender = new CapnpGen.CapBlender();

            string name = "";

            if (!TryGetAttribute(blenderNode, "name", out name))
            {
                error = "Blender node does not have a name attribute";
                return(false);
            }
            blender.Name = name;

            bool enabled = false;

            if (!TryGetAttribute(blenderNode, "enabled", out enabled))
            {
                error = "Blender node \"" + blender.Name + "\" does not have a valid enabled attribute, valid values: true false";
                return(false);
            }
            blender.Enabled = enabled;

            bool logicOpEnabled = false;

            if (!TryGetAttribute(blenderNode, "logicOpEnabled", out logicOpEnabled))
            {
                error = "Blender node \"" + blender.Name + "\" does not have a valid logicOpEnabled attribute, valid values: true false";
                return(false);
            }
            blender.LogicOpEnabled = logicOpEnabled;

            CapnpGen.CapBlendMode srcBlendMode = CapnpGen.CapBlendMode.zero;
            if (!TryGetAttribute(blenderNode, "srcBlendMode", out srcBlendMode))
            {
                error = "Blender node \"" + blender.Name + "\" does not have a valid srcBlendMode attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapBlendMode));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            blender.SrcBlendMode = srcBlendMode;

            CapnpGen.CapBlendMode destBlendMode = CapnpGen.CapBlendMode.zero;
            if (!TryGetAttribute(blenderNode, "destBlendMode", out destBlendMode))
            {
                error = "Blender node \"" + blender.Name + "\" does not have a valid destBlendMode attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapBlendMode));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            blender.DestBlendMode = destBlendMode;

            CapnpGen.CapBlendOp blendOp = CapnpGen.CapBlendOp.add;
            if (!TryGetAttribute(blenderNode, "blendOp", out blendOp))
            {
                error = "Blender node \"" + blender.Name + "\" does not have a valid blendOp attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapBlendOp));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            blender.BlendOp = blendOp;

            CapnpGen.CapBlendMode srcAlphaBlendMode = CapnpGen.CapBlendMode.zero;
            if (!TryGetAttribute(blenderNode, "srcAlphaBlendMode", out srcAlphaBlendMode))
            {
                error = "Blender node \"" + blender.Name + "\" does not have a valid srcAlphaBlendMode attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapBlendMode));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            blender.SrcAlphaBlendMode = srcAlphaBlendMode;

            CapnpGen.CapBlendMode destAlphaBlendMode = CapnpGen.CapBlendMode.zero;
            if (!TryGetAttribute(blenderNode, "destAlphaBlendMode", out destAlphaBlendMode))
            {
                error = "Blender node \"" + blender.Name + "\" does not have a valid destAlphaBlendMode attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapBlendMode));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            blender.DestAlphaBlendMode = destAlphaBlendMode;

            CapnpGen.CapBlendOp alphaBlendOp = CapnpGen.CapBlendOp.add;
            if (!TryGetAttribute(blenderNode, "alphaBlendOp", out alphaBlendOp))
            {
                error = "Blender node \"" + blender.Name + "\" does not have a valid alphaBlendOp attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapBlendOp));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            blender.AlphaBlendOp = alphaBlendOp;

            blenders.Add(blender);
            return(true);
        }