private void DeserializeNodeTemplate(BinaryReader binaryReader, ushort index, TbXml tbXml) { TbXmlNodeTemplate nodeTemplate = new TbXmlNodeTemplate(); tbXml.nodeTemplates.Add(nodeTemplate); nodeTemplate.id = binaryReader.ReadUInt16(); nodeTemplate.name = binaryReader.ReadString(); ushort numAttributes = binaryReader.ReadUInt16(); if (numAttributes > 0) { nodeTemplate.attributeNames = new List <string>(numAttributes); nodeTemplate.attributeNameIndexMapping = new Dictionary <string, int>(numAttributes); for (int i = 0; i < numAttributes; ++i) { string attributeName = binaryReader.ReadString(); nodeTemplate.attributeNames.Add(attributeName); nodeTemplate.attributeNameIndexMapping[attributeName] = i; } nodeTemplate.attributeTypes = new List <TB_XML_ATTRIBUTE_TYPE>(numAttributes); for (int i = 0; i < numAttributes; ++i) { nodeTemplate.attributeTypes.Add((TB_XML_ATTRIBUTE_TYPE)binaryReader.ReadByte()); } } }
private void DeserializeNodeTemplate(BinaryReader binaryReader, ushort index, TbXml tbXml) { TbXmlNodeTemplate tbXmlNodeTemplate = new TbXmlNodeTemplate(); tbXml.nodeTemplates.Add(tbXmlNodeTemplate); tbXmlNodeTemplate.id = binaryReader.ReadUInt16(); tbXmlNodeTemplate.name = binaryReader.ReadString(); ushort num = binaryReader.ReadUInt16(); if (num > 0) { tbXmlNodeTemplate.attributeNames = new List <string>((int)num); tbXmlNodeTemplate.attributeNameIndexMapping = new Dictionary <string, int>((int)num); for (int i = 0; i < (int)num; i++) { string text = binaryReader.ReadString(); tbXmlNodeTemplate.attributeNames.Add(text); tbXmlNodeTemplate.attributeNameIndexMapping[text] = i; } tbXmlNodeTemplate.attributeTypes = new List <TB_XML_ATTRIBUTE_TYPE>((int)num); for (int j = 0; j < (int)num; j++) { tbXmlNodeTemplate.attributeTypes.Add((TB_XML_ATTRIBUTE_TYPE)binaryReader.ReadByte()); } } }
private void DeserializeNode(BinaryReader binaryReader, ushort index, TbXml tbXml) { TbXmlNode tbXmlNode = new TbXmlNode(); tbXml.nodes.Add(tbXmlNode); tbXmlNode.id = binaryReader.ReadUInt16(); tbXmlNode.templateId = binaryReader.ReadUInt16(); ushort num = binaryReader.ReadUInt16(); if (num > 0) { tbXmlNode.childrenIds = new List <ushort>((int)num); for (int i = 0; i < (int)num; i++) { tbXmlNode.childrenIds.Add(binaryReader.ReadUInt16()); } } TbXmlNodeTemplate tbXmlNodeTemplate = tbXml.nodeTemplates[(int)tbXmlNode.templateId]; ushort num2 = (ushort)((tbXmlNodeTemplate.attributeNames != null) ? tbXmlNodeTemplate.attributeNames.Count : 0); if (num2 > 0) { tbXmlNode.attributeValues = new List <int>((int)num2); for (ushort num3 = 0; num3 < num2; num3 += 1) { tbXmlNode.attributeValues.Add(binaryReader.ReadInt32()); } } byte b = binaryReader.ReadByte(); if (b == 1) { tbXmlNode.text = binaryReader.ReadInt32(); } }
private void SerializeNode(BinaryWriter binaryWriter, TbXmlNode node) { TbXmlNodeTemplate nodeTemplate = GetNodeTemplate(node.templateId); binaryWriter.Write(node.id); binaryWriter.Write(node.templateId); binaryWriter.Write((ushort)node.childrenIds.Count); foreach (ushort childId in node.childrenIds) { binaryWriter.Write(childId); } int attributeIndex = 0; foreach (int attributeValue in node.attributeValues) { binaryWriter.Write(attributeValue); ++attributeIndex; } if (node.text == -1) { binaryWriter.Write((byte)0); } else { binaryWriter.Write((byte)1); binaryWriter.Write(node.text); } }
private bool XmlNodeMatchTemplate(XmlNode xmlNode, TbXmlNodeTemplate nodeTemplate) { if (nodeTemplate.name != xmlNode.Name) { return(false); } XmlAttributeCollection xmlAttributes = xmlNode.Attributes; int numAttributes = xmlAttributes == null ? 0 : xmlAttributes.Count; for (int i = 0; i < numAttributes; ++i) { XmlAttribute xmlAttribute = xmlAttributes[i]; if (nodeTemplate.attributeNames != null && !nodeTemplate.attributeNames[i].Equals(xmlAttribute.Name)) { return(false); } double attributeDouble; bool isAttributeDouble = double.TryParse(xmlAttribute.Value, out attributeDouble); if ((isAttributeDouble && nodeTemplate.attributeTypes[i] != TB_XML_ATTRIBUTE_TYPE.DOUBLE) || (!isAttributeDouble && nodeTemplate.attributeTypes[i] == TB_XML_ATTRIBUTE_TYPE.DOUBLE)) { return(false); } } return(xmlNode.Attributes.Count == nodeTemplate.attributeNames.Count); }
public object GetValue(ref string name) { TbXmlNodeTemplate tbXmlNodeTemplate = this.tbXml.nodeTemplates[(int)this.templateId]; int index; if (!tbXmlNodeTemplate.attributeNameIndexMapping.TryGetValue(name, out index)) { return(null); } if (tbXmlNodeTemplate.attributeTypes[index] == TB_XML_ATTRIBUTE_TYPE.DOUBLE) { return(this.tbXml.valuePool[this.attributeValues[index]]); } return(this.tbXml.stringPool[this.attributeValues[index]]); }
private void SerializeNodeTemplate(BinaryWriter binaryWriter, TbXmlNodeTemplate nodeTemplate) { binaryWriter.Write(nodeTemplate.id); binaryWriter.Write(nodeTemplate.name); binaryWriter.Write((ushort)nodeTemplate.attributeNames.Count); foreach (string attributeName in nodeTemplate.attributeNames) { binaryWriter.Write(attributeName); } foreach (TB_XML_ATTRIBUTE_TYPE attributeType in nodeTemplate.attributeTypes) { binaryWriter.Write((byte)attributeType); } }
private void DeserializeNode(BinaryReader binaryReader, ushort index, TbXml tbXml) { TbXmlNode node = new TbXmlNode(); tbXml.nodes.Add(node); node.id = binaryReader.ReadUInt16(); node.templateId = binaryReader.ReadUInt16(); if (binaryReader.ReadByte() == 1) { ushort numChildren = binaryReader.ReadUInt16(); if (numChildren > 0) { node.childrenIds = new List <ushort>(numChildren); for (int i = 0; i < numChildren; ++i) { node.childrenIds.Add(binaryReader.ReadUInt16()); } } } TbXmlNodeTemplate nodeTemplate = tbXml.nodeTemplates[node.templateId]; ushort numAttributes = (ushort)(nodeTemplate.attributeNames == null ? 0 : nodeTemplate.attributeNames.Count); if (numAttributes > 0) { node.attributeValues = new List <int>(numAttributes); for (ushort i = 0; i < numAttributes; ++i) { node.attributeValues.Add(binaryReader.ReadInt32()); } } byte hasText = binaryReader.ReadByte(); if (hasText == 1) { node.text = binaryReader.ReadInt32(); } }
private object GetValue(ref string name) { TbXmlNodeTemplate nodeTemplate = tbXml.nodeTemplates[templateId]; int attributeIndex; if (nodeTemplate.attributeNameIndexMapping.TryGetValue(name, out attributeIndex)) { if (nodeTemplate.attributeTypes[attributeIndex] == TB_XML_ATTRIBUTE_TYPE.DOUBLE) { return(tbXml.valuePool[attributeValues[attributeIndex]]); } else { return(tbXml.stringPool[attributeValues[attributeIndex]]); } } else { return(null); } }
private void ProcessXmlNode(TbXmlNode parentNode, XmlNode xmlNode) { TbXmlNodeTemplate nodeTemplate = GetNodeTemplate(xmlNode); if (nodeTemplate == null) { nodeTemplate = new TbXmlNodeTemplate(); nodeTemplates.Add(nodeTemplate); nodeTemplate.attributeNames = new List <string>(); nodeTemplate.attributeTypes = new List <TB_XML_ATTRIBUTE_TYPE>(); nodeTemplate.id = nodeTemplateIdInc++; nodeTemplate.name = xmlNode.Name; foreach (XmlAttribute xmlAttribute in xmlNode.Attributes) { string attributeString = xmlAttribute.Value; double attributeDouble; if (double.TryParse(attributeString, out attributeDouble)) { nodeTemplate.attributeTypes.Add(TB_XML_ATTRIBUTE_TYPE.DOUBLE); } else { nodeTemplate.attributeTypes.Add(TB_XML_ATTRIBUTE_TYPE.STRING); } nodeTemplate.attributeNames.Add(xmlAttribute.Name); } } TbXmlNode node = new TbXmlNode(); nodes.Add(node); node.attributeValues = new List <int>(); node.childrenIds = new List <ushort>(); node.id = nodeIdInc++; node.templateId = nodeTemplate.id; parentNode.childrenIds.Add(node.id); foreach (XmlAttribute xmlAttribute in xmlNode.Attributes) { string attributeString = xmlAttribute.Value; double attributeDouble; if (double.TryParse(attributeString, out attributeDouble)) { int valueIndex = MatchValueIndex(attributeDouble); if (valueIndex == -1) { valuePool.Add(attributeDouble); node.attributeValues.Add(valuePool.Count - 1); } else { node.attributeValues.Add(valueIndex); } } else { int stringIndex = MatchStringIndex(attributeString); if (stringIndex == -1) { stringPool.Add(attributeString); node.attributeValues.Add(stringPool.Count - 1); } else { node.attributeValues.Add(stringIndex); } } } foreach (XmlNode subXmlNode in xmlNode.ChildNodes) { if (subXmlNode.NodeType == XmlNodeType.Element) { ProcessXmlNode(node, subXmlNode); } else if (subXmlNode.NodeType == XmlNodeType.Text || subXmlNode.NodeType == XmlNodeType.CDATA) { if (node.text == -1) { int stringIndex = MatchStringIndex(subXmlNode.Value); if (stringIndex == -1) { stringPool.Add(subXmlNode.Value); node.text = stringPool.Count - 1; } else { node.text = stringIndex; } } else { Console.WriteLine("Ignore yyy of <nodeA>xxx<nodeB/>yyy<nodeA/>"); Console.WriteLine(subXmlNode.InnerText); // UnityEngine.Debug.LogError("Ignore yyy of <nodeA>xxx<nodeB/>yyy<nodeA/>"); // UnityEngine.Debug.LogError(subXmlNode.InnerText); } } } }
private void DeserializeNodeTemplate(BinaryReader binaryReader, ushort index, TbXml tbXml) { TbXmlNodeTemplate nodeTemplate = new TbXmlNodeTemplate(); tbXml.nodeTemplates.Add(nodeTemplate); nodeTemplate.id = binaryReader.ReadUInt16(); nodeTemplate.name = binaryReader.ReadString(); ushort numAttributes = binaryReader.ReadUInt16(); if(numAttributes > 0) { nodeTemplate.attributeNames = new List<string>(numAttributes); nodeTemplate.attributeNameIndexMapping = new Dictionary<string, int>(numAttributes); for(int i = 0; i < numAttributes; ++i) { string attributeName = binaryReader.ReadString(); nodeTemplate.attributeNames.Add(attributeName); nodeTemplate.attributeNameIndexMapping[attributeName] = i; } nodeTemplate.attributeTypes = new List<TB_XML_ATTRIBUTE_TYPE>(numAttributes); for(int i = 0; i < numAttributes; ++i) { nodeTemplate.attributeTypes.Add((TB_XML_ATTRIBUTE_TYPE)binaryReader.ReadByte()); } } }
private bool XmlNodeMatchTemplate(XmlNode xmlNode, TbXmlNodeTemplate nodeTemplate) { if(nodeTemplate.name != xmlNode.Name) { return false; } XmlAttributeCollection xmlAttributes = xmlNode.Attributes; int numAttributes = xmlAttributes == null ? 0 : xmlAttributes.Count; for (int i = 0; i < numAttributes; ++i) { XmlAttribute xmlAttribute = xmlAttributes[i]; if (nodeTemplate.attributeNames != null && !nodeTemplate.attributeNames[i].Equals(xmlAttribute.Name)) { return false; } double attributeDouble; bool isAttributeDouble = double.TryParse(xmlAttribute.Value, out attributeDouble); if ((isAttributeDouble && nodeTemplate.attributeTypes[i] != TB_XML_ATTRIBUTE_TYPE.DOUBLE) || (!isAttributeDouble && nodeTemplate.attributeTypes[i] == TB_XML_ATTRIBUTE_TYPE.DOUBLE)) { return false; } } return xmlNode.Attributes.Count == nodeTemplate.attributeNames.Count; }
private void SerializeNodeTemplate(BinaryWriter binaryWriter, TbXmlNodeTemplate nodeTemplate) { binaryWriter.Write(nodeTemplate.id); binaryWriter.Write(nodeTemplate.name); binaryWriter.Write((ushort)nodeTemplate.attributeNames.Count); foreach(string attributeName in nodeTemplate.attributeNames) { binaryWriter.Write(attributeName); } foreach(TB_XML_ATTRIBUTE_TYPE attributeType in nodeTemplate.attributeTypes) { binaryWriter.Write((byte)attributeType); } }
private void ProcessXmlNode(TbXmlNode parentNode, XmlNode xmlNode) { TbXmlNodeTemplate nodeTemplate = GetNodeTemplate(xmlNode); if(nodeTemplate == null) { nodeTemplate = new TbXmlNodeTemplate(); nodeTemplates.Add(nodeTemplate); nodeTemplate.attributeNames = new List<string>(); nodeTemplate.attributeTypes = new List<TB_XML_ATTRIBUTE_TYPE>(); nodeTemplate.id = nodeTemplateIdInc++; nodeTemplate.name = xmlNode.Name; foreach(XmlAttribute xmlAttribute in xmlNode.Attributes) { string attributeString = xmlAttribute.Value; double attributeDouble; if(double.TryParse(attributeString, out attributeDouble)) { nodeTemplate.attributeTypes.Add(TB_XML_ATTRIBUTE_TYPE.DOUBLE); } else { nodeTemplate.attributeTypes.Add(TB_XML_ATTRIBUTE_TYPE.STRING); } nodeTemplate.attributeNames.Add(xmlAttribute.Name); } } TbXmlNode node = new TbXmlNode(); nodes.Add(node); node.attributeValues = new List<int>(); node.childrenIds = new List<ushort>(); node.id = nodeIdInc++; node.templateId = nodeTemplate.id; parentNode.childrenIds.Add(node.id); foreach(XmlAttribute xmlAttribute in xmlNode.Attributes) { string attributeString = xmlAttribute.Value; double attributeDouble; if(double.TryParse(attributeString, out attributeDouble)) { int valueIndex = MatchValueIndex(attributeDouble); if (valueIndex == -1) { valuePool.Add(attributeDouble); node.attributeValues.Add(valuePool.Count - 1); } else { node.attributeValues.Add(valueIndex); } } else { int stringIndex = MatchStringIndex(attributeString); if (stringIndex == -1) { stringPool.Add(attributeString); node.attributeValues.Add(stringPool.Count - 1); } else { node.attributeValues.Add(stringIndex); } } } foreach(XmlNode subXmlNode in xmlNode.ChildNodes) { if(subXmlNode.NodeType == XmlNodeType.Element) { ProcessXmlNode(node, subXmlNode); } else if(subXmlNode.NodeType == XmlNodeType.Text || subXmlNode.NodeType == XmlNodeType.CDATA) { if(node.text == -1) { int stringIndex = MatchStringIndex(subXmlNode.Value); if (stringIndex == -1) { stringPool.Add(subXmlNode.Value); node.text = stringPool.Count - 1; } else { node.text = stringIndex; } } else { Console.WriteLine("Ignore yyy of <nodeA>xxx<nodeB/>yyy<nodeA/>"); Console.WriteLine(subXmlNode.InnerText); // UnityEngine.Debug.LogError("Ignore yyy of <nodeA>xxx<nodeB/>yyy<nodeA/>"); // UnityEngine.Debug.LogError(subXmlNode.InnerText); } } } }