Beispiel #1
0
        /// <summary>
        /// Add new XmlInfoData
        /// </summary>
        /// <param name="path">XmlData path</param>
        /// <param name="valueToSet">Value to set</param>
        /// <returns>Created XmlDataNode</returns>
        public XmlDataNode AddXmlInfoByPath(string path, string valueToSet = "", Dictionary <string, string> attributePairsToSet = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            List <string> NAME_LIST = path.Split('/').ToList();

            if (NAME_LIST.Count > 1)
            {
                XmlDataNode foundXmlDataNode = subNodes.Find((XmlDataNode xmlDataNode) =>
                {
                    return(xmlDataNode.name == NAME_LIST[0]);
                });
                if (foundXmlDataNode != null)
                {
                    return(foundXmlDataNode.AddXmlInfoByPath(String.Join("/", NAME_LIST.Skip(1)), valueToSet, attributePairsToSet));
                }
                else
                {
                    XmlDataNode createdXmlDataNode = new XmlDataNode(NAME_LIST[0]);
                    subNodes.Add(createdXmlDataNode);
                    return(createdXmlDataNode.AddXmlInfoByPath(String.Join("/", NAME_LIST.Skip(1)), valueToSet, attributePairsToSet));
                }
            }
            else
            {
                XmlDataNode createdXmlDataNode = new XmlDataNode(NAME_LIST[0], valueToSet, attributePairsToSet);
                subNodes.Add(createdXmlDataNode);
                MainWindow.mainWindow.UpdateDebugInfo();
                return(createdXmlDataNode);
            }
        }
        /// <summary>
        /// Make new localize books base by basic node in game data
        /// </summary>
        /// <returns>Created books info</returns>
        public static XmlDataNode MakeNewLocalizeBooksBase(string bookIdToSet = "", string nameToSet = "", string desc = "")
        {
            List <XmlDataNode> foundXmlDataNodes = DM.GameInfos.localizeInfos["Books"].rootDataNode.GetXmlDataNodesByPathWithXmlInfo("bookDescList/BookDesc",
                                                                                                                                     attributeToCheck: new Dictionary <string, string>()
            {
                { "BookID", "200001" }
            });

            if (foundXmlDataNodes.Count > 0)
            {
                XmlDataNode xmlDataNodeToAdd = foundXmlDataNodes[0].Copy();

                xmlDataNodeToAdd.attribute["BookID"] = bookIdToSet;
                xmlDataNodeToAdd.SetXmlInfoByPath("BookName", nameToSet);

                if (!string.IsNullOrEmpty(desc))
                {
                    xmlDataNodeToAdd.RemoveXmlInfosByPath("TextList/Desc");

                    foreach (string desPart in desc.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.None))
                    {
                        string DESC_TO_ADD = desPart.Replace("\r\n", " ").Replace("\r", "").Replace("\n", "");
                        xmlDataNodeToAdd.AddXmlInfoByPath("TextList/Desc", DESC_TO_ADD);
                    }
                }
                else
                {
                    xmlDataNodeToAdd.RemoveXmlInfosByPath("TextList/Desc");
                    xmlDataNodeToAdd.MakeEmptyNodeGivenPathIfNotExist("TextList/Desc");
                }

                return(xmlDataNodeToAdd);
            }
            else
            {
                return(null);
            }
        }