public XElement ProcessCustomizationFile(string nation)
        {
            var element = BigworldXmlPreprocessor.LoadFile(_paths.GetCustomizationFile(nation))
                          .Rename("customization");

            element.SetAttributeValue("nation", nation);

            var inscriptionsElement     = element.ExistedElement("inscriptions");
            var firstInscriptionElement = inscriptionsElement.Elements().First();

            firstInscriptionElement.Rename("inscription");


            firstInscriptionElement.LocalizeValue("userString", _localization);
            firstInscriptionElement.Element("inscriptions")
            .ProcessElements(e => e.LocalizeValue("userString", _localization)
                             .ElementToAttribute("id"));

            inscriptionsElement.ReplaceWith(firstInscriptionElement);

            element.Element("camouflageGroups")
            .ProcessElements(e => e.LocalizeValue("userString", _localization)
                             .NameToAttribute("camouflageGroup"));
            element.Element("camouflages")
            .ProcessElements(e => e.LocalizeValue("description", _localization)
                             .NameToAttribute("camouflage")
                             .ElementToAttribute("id"));

            return(element);
        }
        public XElement ProcessCrewDefinitionFile(string nation)
        {
            var file = BigworldXmlPreprocessor.LoadFile(_paths.GetCrewDefinitionFile(nation))
                       .TrimNameTail()
                       .NameToAttribute("crewDefinition", "nation")
                       .ProcessElements("ranks", r => r.LocalizeValue("userString", _localization));

            var ranks = file.ExistedElement("ranks");

            file.ProcessElements("roleRanks", r => r.NameToAttribute("ranks", "role")
                                 .TextToElementList("rank")
                                 .ProcessElements(e =>
            {
                var rank = e.Value.Trim();
                e.SetAttributeValue("key", rank);
                e.Value = ranks.ExistedElement(rank).ExistedElement("userString").Value;
            }));

            var men1 = file.XPathSelectElement("normalGroups/men1");

            file.Add(new XElement(men1.ExistedElement("firstNames"))
                     .ProcessElements(e => e.Rename("name")
                                      .LocalizeValue(_localization)));
            file.Add(new XElement(men1.ExistedElement("lastNames"))
                     .ProcessElements(e => e.Rename("name")
                                      .LocalizeValue(_localization)));
            file.Add(new XElement(men1.ExistedElement("icons"))
                     .Rename("portraits")
                     .ProcessElements(e => e.Rename("portrait")));

            file.RemoveElement("normalGroups");
            file.RemoveElement("premiumGroups");

            return(file);
        }
        private XElement ProcessAccessoryFile(string file, string rootName, string itemName)
        {
            return(BigworldXmlPreprocessor.LoadFile(file)
                   .Rename(rootName)
                   .ProcessElements(e =>
            {
                e.NameToAttribute(itemName)
                .LocalizeValue("userString", _localization)
                .LocalizeValue("description", _localization)
                .ProcessPriceElement()
                .Select("script", s => s.TextToAttribute("name"));

                e.Select("vehicleFilter",
                         f =>
                {
                    foreach (var element in f.XPathSelectElements("//tags"))
                    {
                        element.TextToElementList("tag");
                    }

                    foreach (var element in f.XPathSelectElements("//nations"))
                    {
                        element.TextToElementList("nation");
                    }
                });
            }));
        }
 public XElement ProcessCommonVehicleDataFile()
 {
     return(BigworldXmlPreprocessor.LoadFile(_paths.CommonVehicleDataFile)
            .TrimNameTail()
            .Select("balance", balance => balance.ProcessElements("byVehicleModule", e => e.Rename("tank").TextToAttribute("key"))
                    .Select("byComponentLevels", e => e.TextToElementList("weight")))
            .Select("materials", materials => materials.ProcessElements(e => e.NameToAttribute("material"))));
 }
 private XElement ProcessShellListFile(string nation)
 {
     return(BigworldXmlPreprocessor.LoadFile(_paths.GetShellListFile(nation))
            .TrimNameTail()
            .RemoveElement("icons")
            .ProcessElements(e => e.NameToAttribute("shell")
                             .ProcessPriceElement()
                             .LocalizeValue("userString", _localization)));
 }
 private XElement ProcessModuleListFile(string file, string elementName, Action <XElement> additionalProcessing = null)
 {
     return(BigworldXmlPreprocessor.LoadFile(file)
            .TrimNameTail()
            .ProcessElements("ids", e => e.NameToAttribute(elementName).TextToAttribute("id"))
            .ProcessElements("shared", e => e.NameToAttribute(elementName)
                             .ApplyProcessing(additionalProcessing)
                             .LocalizeValue("userString", _localization)));
 }
        public XElement ProcessCommonCrewDataFile()
        {
            const string shortDescTag    = "<shortDesc>";
            const string shortDescTagEnd = "</shortDesc>";

            return(BigworldXmlPreprocessor.LoadFile(_paths.CommonCrewDataFile)
                   .Rename("crews")
                   .ProcessElements("roles", r => r.NameToAttribute("role")
                                    .LocalizeValue("userString", _localization)
                                    .LocalizeValue("description", _localization))
                   .ProcessElements("skills", s =>
            {
                s.LocalizeValue("userString", _localization)
                .LocalizeValue("description", _localization);

                var descriptionElement = s.Element("description");
                Debug.Assert(descriptionElement != null, "descriptionElement != null");

                var description = descriptionElement.Value;
                var shortDescription = description;

                var startIndex = description.IndexOf(shortDescTag, StringComparison.Ordinal);
                var endIndex = description.IndexOf(shortDescTagEnd, StringComparison.Ordinal);
                if (startIndex >= 0 && endIndex - startIndex - shortDescTag.Length > 0)
                {
                    shortDescription = description.Substring(startIndex + shortDescTag.Length, endIndex - startIndex - shortDescTag.Length);
                    description = description.Substring(0, startIndex) + shortDescription + description.Substring(endIndex + shortDescTagEnd.Length);
                }

                descriptionElement.Value = description;
                descriptionElement.AddAfterSelf(new XElement("shortDesc", shortDescription));


                string role = null;
                var name = s.Name.ToString();
                var nameParts = name.Split('_');
                if (nameParts.Length == 2)
                {
                    role = nameParts[0];
                    name = nameParts[1];
                }

                s.Name = "skill";
                s.SetAttributeValue("key", name);
                if (role != null)
                {
                    s.SetAttributeValue("role", role);
                }
            }));
        }
        public XElement ProcessTechTreeLayoutFile(string nation)
        {
            try
            {
                var file = BigworldXmlPreprocessor.LoadFile(_paths.GetNationalTechTreeLayoutFile(nation))
                           .TrimNameTail()
                           .Select("grid", g => g.TextToAttribute("style"))
                           .ProcessElements("nodes", n => n.NameToAttribute("node")
                                            .ProcessElements("lines", l => l.NameToAttribute("line", "target")));

                file.Name = file.Name.LocalName.Substring(0, file.Name.LocalName.Length - "-tree".Length);
                file.NameToAttribute("layout", "nation");
                return(file);
            }
            catch (FileNotFoundException)
            {
                return(null);
            }
        }
        public XElement ProcessTankListFile(string nation)
        {
            return(BigworldXmlPreprocessor.LoadFile(_paths.GetTankListFile(nation))
                   .TrimNameTail()
                   .ProcessElements(e =>
            {
                e = e.NameToAttribute("tank")
                    .ProcessPriceElement()
                    .Select("tags", tags => tags.TextToElementList("tag"))
                    .LocalizeValue("userString", _localization)
                    .LocalizeValue("description", _localization)
                    .LocalizeValue("shortUserString", _localization);

                if (e.Element("shortUserString") == null)
                {
                    var userStringElement = e.ExistedElement("userString");
                    e.Add(new XElement(userStringElement)
                    {
                        Name = "shortUserString"
                    });
                }

                var tankTags = e.ExistedElement("tags").Elements().ToArray();

                var classTag = tankTags.First();
                var classKey = classTag.Value;
                var className = _localization.GetLocalizedClassName(classKey);
                var classElement = new XElement("class", className);
                classElement.SetAttributeValue("key", classKey);
                e.Add(classElement);

                var nationElement = new XElement("nation", _localization.GetLocalizedNationName(nation));
                nationElement.SetAttributeValue("key", nation);
                e.Add(nationElement);

                var secretTags = new XElement("secretTags");

                var isSecret = tankTags.Any(t => t.Value == "secret");

                if (isSecret)
                {
                    e.Add(new XElement("secret", true));

                    var key = e.Attribute("key").Value;
                    if (key.EndsWith("_training"))
                    {
                        secretTags.Add(new XElement("tag", "training"));
                    }

                    if (key.EndsWith("_bot"))
                    {
                        secretTags.Add(new XElement("tag", "bot"));
                    }

                    if (tankTags.Any(t => t.Value == "premiumIGR"))
                    {
                        secretTags.Add(new XElement("tag", "igr"));
                    }

                    if (tankTags.Any(t => t.Value == "fallout"))
                    {
                        secretTags.Add(new XElement("tag", "fallout"));
                    }

                    if (tankTags.Any(t => t.Value == "event_battles"))
                    {
                        secretTags.Add(new XElement("tag", "event_battles"));
                    }
                }

                e.Add(secretTags);
            }));
        }
        public XElement ProcessTankFile(string nation, string key)
        {
            var element = BigworldXmlPreprocessor.LoadFile(_paths.GetTankFile(nation, key));

            element.TrimNameTail()
            .NameToAttribute("tank")
            .RenameElement("crew", "crews")
            .RenameElement("camouflage", "camouflageInfo")
            .ProcessElements("crews",
                             e => e.NameToAttribute("crew", "role")
                             .TextToElement("secondaryRoles")
                             .Select("secondaryRoles",
                                     s =>
                                     s.TextToElementList("secondaryRole")))
            .Select("hull",
                    e =>
            {
                e.ProcessArmorList(this.CommonVehicleData)
                .Select("armor",
                        a => a.AppendCommonArmorGroup(this.CommonVehicleData, "surveyingDevice")
                        .AppendCommonArmorGroup(this.CommonVehicleData, "turretRotator"));

                BigworldXmlPreprocessor.ProcessHitTester(e);
            })
            .ProcessTankModuleListNode("chassis",
                                       "chassis",
                                       _localization,
                                       e =>
            {
                e.ProcessArmorList(this.CommonVehicleData)
                .Select("terrainResistance",
                        t => t.TextToElements("hard", "medium", "soft"));

                BigworldXmlPreprocessor.ProcessHitTester(e);
            })
            .RenameElement("turrets0", "turrets")
            .ProcessTankModuleListNode("turrets",
                                       "turret",
                                       _localization,
                                       e =>
            {
                e.ProcessArmorList(this.CommonVehicleData)
                .Select("armor", a => a.AppendCommonArmorGroup(this.CommonVehicleData, "surveyingDevice"))
                .ProcessTankModuleListNode("guns",
                                           "gun",
                                           _localization,
                                           g => BigworldXmlPreprocessor.ProcessGunNode(g, this.CommonVehicleData, false));


                BigworldXmlPreprocessor.ProcessHitTester(e);
            })
            .ProcessTankModuleListNode("engines",
                                       "engine",
                                       _localization,
                                       BigworldXmlPreprocessor.ProcessEngineNode)
            .ProcessTankModuleListNode("fuelTanks", "fuelTank", _localization)
            .ProcessTankModuleListNode("radios", "radio", _localization);

            var unlockNodes = element.XPathSelectElements("(chassis/chassis|turrets/turret|turrets/turret/guns/gun|engines/engine|radios/radio)/unlocks/*");

            foreach (var unlockNode in unlockNodes)
            {
                string searchRootPath;
                switch (unlockNode.Name.LocalName)
                {
                case "gun":
                    searchRootPath = "turrets/turret/guns/gun";
                    break;

                case "chassis":
                    searchRootPath = "chassis/chassis";
                    break;

                case "turret":
                    searchRootPath = "turrets/turret";
                    break;

                case "engine":
                    searchRootPath = "engines/engine";
                    break;

                case "radio":
                    searchRootPath = "radios/radio";
                    break;

                default:
                    continue;
                }

                var targetElements = element.XPathSelectElements(string.Format("{0}[@key='{1}']",
                                                                               searchRootPath,
                                                                               unlockNode.Attribute("key").Value));

                foreach (var targetElement in targetElements)
                {
                    var costElement = unlockNode.Element("cost");
                    Debug.Assert(costElement != null, "costElement != null");
                    targetElement.SetElementValue("experience", costElement.Value);
                }
            }

            return(element);
        }