예제 #1
0
        public IEnumerable <Skill> GetSkillList(FilterOptions filter, string strName = "", bool blnFetchFromBackup = false)
        {
            //TODO less retarded way please
            // Load the Skills information.
            // Populate the Skills list.
            using (XmlNodeList xmlSkillList = XmlManager.Load("skills.xml").SelectNodes("/chummer/skills/skill[not(exotic) and (" + _objCharacter.Options.BookXPath() + ')' + SkillFilter(filter, strName) + "]"))
            {
                // First pass, build up a list of all of the Skills so we can sort them in alphabetical order for the current language.
                Dictionary <string, Skill> dicSkills     = new Dictionary <string, Skill>(xmlSkillList?.Count ?? 0);
                List <ListItem>            lstSkillOrder = new List <ListItem>();
                if (xmlSkillList != null)
                {
                    foreach (XmlNode xmlSkill in xmlSkillList)
                    {
                        string strSkillName = xmlSkill["name"]?.InnerText ?? string.Empty;
                        lstSkillOrder.Add(new ListItem(strSkillName, xmlSkill["translate"]?.InnerText ?? strSkillName));
                        //TODO: read from backup
                        if (blnFetchFromBackup && _dicSkillBackups.Count > 0 && xmlSkill.TryGetField("id", Guid.TryParse, out Guid guiSkillId))
                        {
                            if (_dicSkillBackups.TryGetValue(guiSkillId, out Skill objSkill) && objSkill != null)
                            {
                                dicSkills.Add(objSkill.Name, objSkill);
                                _dicSkillBackups.Remove(guiSkillId);
                            }
                            else
                            {
                                dicSkills.Add(strSkillName, Skill.FromData(xmlSkill, _objCharacter));
                            }
                        }
                        else
                        {
                            Skill objSkill = Skill.FromData(xmlSkill, _objCharacter);
                            dicSkills.Add(strSkillName, objSkill);
                        }
                    }
                }

                lstSkillOrder.Sort(CompareListItems.CompareNames);

                // Second pass, retrieve the Skills in the order they're presented in the list.
                foreach (ListItem objItem in lstSkillOrder)
                {
                    yield return(dicSkills[objItem.Value.ToString()]);
                }
            }
        }
예제 #2
0
        public static IList <Skill> GetSkillList(Character c, FilterOptions filter, string strName = "")
        {
            //TODO less retarded way please
            List <Skill> b = new List <Skill>();
            // Load the Skills information.
            XmlDocument objXmlDocument = XmlManager.Load("skills.xml");

            // Populate the Skills list.
            XmlNodeList objXmlSkillList = objXmlDocument.SelectNodes("/chummer/skills/skill[not(exotic) and (" + c.Options.BookXPath() + ")" + SkillFilter(filter, strName) + "]");

            // First pass, build up a list of all of the Skills so we can sort them in alphabetical order for the current language.
            Dictionary <string, Skill> dicSkills     = new Dictionary <string, Skill>(objXmlSkillList.Count);
            List <ListItem>            lstSkillOrder = new List <ListItem>();

            foreach (XmlNode objXmlSkill in objXmlSkillList)
            {
                string strSkillName = objXmlSkill["name"]?.InnerText ?? string.Empty;
                lstSkillOrder.Add(new ListItem(strSkillName, objXmlSkill["translate"]?.InnerText ?? strSkillName));
                //TODO: read from backup
                if (s_LstSkillBackups.Count > 0)
                {
                    Skill objSkill =
                        s_LstSkillBackups.FirstOrDefault(s => s.SkillId == Guid.Parse(objXmlSkill["id"].InnerText));
                    if (objSkill != null)
                    {
                        dicSkills.Add(objSkill.Name, objSkill);
                        s_LstSkillBackups.Remove(objSkill);
                    }
                }
                else
                {
                    Skill objSkill = Skill.FromData(objXmlSkill, c);
                    dicSkills.Add(strSkillName, objSkill);
                }
            }
            SortListItem objSort = new SortListItem();

            lstSkillOrder.Sort(objSort.Compare);

            // Second pass, retrieve the Skills in the order they're presented in the list.
            foreach (ListItem objItem in lstSkillOrder)
            {
                b.Add(dicSkills[objItem.Value]);
            }
            return(b);
        }