public static List <BattleWord> parse(XElement node) { List <BattleWord> blist = new List <BattleWord>(); foreach (XElement subnode in Tools.GetXmlElements(node, "BattleWord")) { BattleWord battleWord = new BattleWord(); battleWord.word = Tools.GetXmlAttribute(subnode, "word"); battleWord.color.A = (byte)Tools.GetXmlAttributeInt(subnode, "colorA"); battleWord.color.B = (byte)Tools.GetXmlAttributeInt(subnode, "colorB"); battleWord.color.G = (byte)Tools.GetXmlAttributeInt(subnode, "colorG"); battleWord.color.R = (byte)Tools.GetXmlAttributeInt(subnode, "colorR"); blist.Add(battleWord); } return(blist); }
public void parse(string rootString) { XElement root = XElement.Parse(rootString); //战斗前数据 preRoles.Clear(); XElement preRolesXML = Tools.GetXmlElement(root, "preRoles"); foreach (XElement preRoleXML in Tools.GetXmlElements(preRolesXML, "preRole")) { int ID = Tools.GetXmlAttributeInt(preRoleXML, "ID"); Role role = Role.Parse(Tools.GetXmlElement(preRoleXML, "role")); preRoles.Add(ID, role); } preSpiritInfos.Clear(); XElement preSpiritInfosXML = Tools.GetXmlElement(root, "preSpiritInfos"); foreach (XElement preSpiritInfoXML in Tools.GetXmlElements(preSpiritInfosXML, "preSpiritInfo")) { int ID = Tools.GetXmlAttributeInt(preSpiritInfoXML, "ID"); SpiritInfo spInfo = SpiritInfo.parse(preSpiritInfoXML); preSpiritInfos.Add(ID, spInfo); } preRoleWords.Clear(); XElement preRoleWordsXML = Tools.GetXmlElement(root, "preRoleWords"); foreach (XElement preRoleWordXML in Tools.GetXmlElements(preRoleWordsXML, "preRoleWord")) { int ID = Tools.GetXmlAttributeInt(preRoleWordXML, "ID"); string word = Tools.GetXmlAttribute(preRoleWordXML, "word"); preRoleWords.Add(ID, word); } preRoleAttackInfo.Clear(); XElement preRoleAttackInfosXML = Tools.GetXmlElement(root, "preRoleAttackInfos"); foreach (XElement preRoleAttackInfoXML in Tools.GetXmlElements(preRoleAttackInfosXML, "preRoleAttackInfo")) { int ID = Tools.GetXmlAttributeInt(preRoleAttackInfoXML, "ID"); List <BattleWord> blist = BattleWord.parse(Tools.GetXmlElement(preRoleAttackInfoXML, "battleWords")); preRoleAttackInfo.Add(ID, blist); } //战斗时数据 XElement moveInfo = Tools.GetXmlElement(root, "moveInfos"); x = Tools.GetXmlAttributeInt(moveInfo, "x"); y = Tools.GetXmlAttributeInt(moveInfo, "y"); faceright = (Tools.GetXmlAttributeInt(moveInfo, "faceright") == 0?false:true); currentSkill = SkillInfo.parse(root); //战斗结果数据 roles.Clear(); XElement rolesXML = Tools.GetXmlElement(root, "roles"); foreach (XElement roleXML in Tools.GetXmlElements(rolesXML, "role")) { int ID = Tools.GetXmlAttributeInt(roleXML, "ID"); Role role = Role.Parse(Tools.GetXmlElement(roleXML, "role")); roles.Add(ID, role); } spiritInfos.Clear(); XElement spiritInfosXML = Tools.GetXmlElement(root, "spiritInfos"); foreach (XElement spiritInfoXML in Tools.GetXmlElements(spiritInfosXML, "spiritInfo")) { int ID = Tools.GetXmlAttributeInt(spiritInfoXML, "ID"); SpiritInfo spInfo = SpiritInfo.parse(spiritInfoXML); spiritInfos.Add(ID, spInfo); } roleWords.Clear(); XElement roleWordsXML = Tools.GetXmlElement(root, "roleWords"); foreach (XElement roleWordXML in Tools.GetXmlElements(roleWordsXML, "roleWord")) { int ID = Tools.GetXmlAttributeInt(roleWordXML, "ID"); string word = Tools.GetXmlAttribute(roleWordXML, "word"); roleWords.Add(ID, word); } roleAttackInfo.Clear(); XElement roleAttackInfosXML = Tools.GetXmlElement(root, "roleAttackInfos"); foreach (XElement roleAttackInfoXML in Tools.GetXmlElements(roleAttackInfosXML, "roleAttackInfo")) { int ID = Tools.GetXmlAttributeInt(roleAttackInfoXML, "ID"); List <BattleWord> blist = BattleWord.parse(Tools.GetXmlElement(roleAttackInfoXML, "battleWords")); roleAttackInfo.Add(ID, blist); } die.Clear(); XElement diesXML = Tools.GetXmlElement(root, "dies"); foreach (XElement dieXML in Tools.GetXmlElements(diesXML, "die")) { int ID = Tools.GetXmlAttributeInt(dieXML, "ID"); die.Add(ID); } }