示例#1
0
        /// <summary>
        ///     Handles an element which describes how a value
        ///     should be read from the cache file.
        /// </summary>
        /// <param name="reader">The XmlReader that read the element.</param>
        /// <param name="elementName">The element's name.</param>
        /// <param name="visitor">The IPluginVisitor to call to.</param>
        private static void HandleValueElement(XmlReader reader, string elementName, IPluginVisitor visitor)
        {
            string name        = "Unknown";
            uint   offset      = 0;
            var    xmlLineInfo = reader as IXmlLineInfo;

            if (xmlLineInfo == null)
            {
                return;
            }
            var  pluginLine = (uint)xmlLineInfo.LineNumber;
            bool visible    = true;

            if (reader.MoveToAttribute("name"))
            {
                name = reader.Value;
            }
            if (reader.MoveToAttribute("offset"))
            {
                offset = ParseUInt(reader.Value);
            }
            if (reader.MoveToAttribute("visible"))
            {
                visible = ParseBool(reader.Value);
            }

            reader.MoveToElement();
            switch (elementName.ToLower())             // FIXME: Using ToLower() here violates XML standards
            {
            case "uint8":
                visitor.VisitUInt8(name, offset, visible, pluginLine);
                break;

            case "int8":
                visitor.VisitInt8(name, offset, visible, pluginLine);
                break;

            case "uint16":
                visitor.VisitUInt16(name, offset, visible, pluginLine);
                break;

            case "int16":
                visitor.VisitInt16(name, offset, visible, pluginLine);
                break;

            case "uint32":
                visitor.VisitUInt32(name, offset, visible, pluginLine);
                break;

            case "int32":
                visitor.VisitInt32(name, offset, visible, pluginLine);
                break;

            case "float32":
            case "float":
                visitor.VisitFloat32(name, offset, visible, pluginLine);
                break;

            case "undefined":
                visitor.VisitUndefined(name, offset, visible, pluginLine);
                break;

            case "vector3":
                visitor.VisitVector3(name, offset, visible, pluginLine);
                break;

            case "degree":
                visitor.VisitDegree(name, offset, visible, pluginLine);
                break;

            case "stringid":
                visitor.VisitStringID(name, offset, visible, pluginLine);
                break;

            case "tagref":
                ReadTagRef(reader, name, offset, visible, visitor, pluginLine);
                break;

            case "range":
                ReadRange(reader, name, offset, visible, visitor, pluginLine);
                break;

            case "ascii":
                ReadAscii(reader, name, offset, visible, visitor, pluginLine);
                break;

            case "utf16":
                ReadUtf16(reader, name, offset, visible, visitor, pluginLine);
                break;

            case "bitfield8":
                if (visitor.EnterBitfield8(name, offset, visible, pluginLine))
                {
                    ReadBits(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "bitfield16":
                if (visitor.EnterBitfield16(name, offset, visible, pluginLine))
                {
                    ReadBits(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "bitfield32":
                if (visitor.EnterBitfield32(name, offset, visible, pluginLine))
                {
                    ReadBits(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "enum8":
                if (visitor.EnterEnum8(name, offset, visible, pluginLine))
                {
                    ReadOptions(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "enum16":
                if (visitor.EnterEnum16(name, offset, visible, pluginLine))
                {
                    ReadOptions(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "enum32":
                if (visitor.EnterEnum32(name, offset, visible, pluginLine))
                {
                    ReadOptions(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            //case "color8": case "colour8":
            //case "color16": case "colour16":
            case "color":
            case "colour":
                visitor.VisitColorInt(name, offset, visible, ReadColorFormat(reader), pluginLine);
                break;

            case "color24":
            case "colour24":
                visitor.VisitColorInt(name, offset, visible, "rgb", pluginLine);
                break;

            case "color32":
            case "colour32":
                visitor.VisitColorInt(name, offset, visible, "argb", pluginLine);
                break;

            case "colorf":
            case "colourf":
                visitor.VisitColorF(name, offset, visible, ReadColorFormat(reader), pluginLine);
                break;

            case "dataref":
                ReadDataRef(reader, name, offset, visible, visitor, pluginLine);
                break;

            case "reflexive":
                ReadReflexive(reader, name, offset, visible, visitor, pluginLine);
                break;

            case "raw":
                ReadRaw(reader, name, offset, visible, visitor, pluginLine);
                break;

            case "shader":
                ReadShader(reader, name, offset, visible, visitor, pluginLine);
                break;

            case "uniclist":
                ReadUnicList(reader, name, offset, visible, visitor, pluginLine);
                break;

            case "packedint8":
                if (visitor.EnterPackedInt8(name, offset, visible, pluginLine))
                {
                    ReadPackedInts(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "packedint16":
                if (visitor.EnterPackedInt16(name, offset, visible, pluginLine))
                {
                    ReadPackedInts(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            case "packedint32":
                if (visitor.EnterPackedInt32(name, offset, visible, pluginLine))
                {
                    ReadPackedInts(reader, visitor);
                }
                else
                {
                    reader.Skip();
                }
                break;

            default:
                throw new ArgumentException("Unknown element \"" + elementName + "\"." + PositionInfo(reader));
            }
        }