Esempio n. 1
0
        private void Parse(string path)
        {
            VObject vObject = (VObject)VdfConvert.Deserialize(File.ReadAllText(path).Replace(@"\", @"\\")).Value;

            DepotId     = int.Parse(vObject["DepotID"].ToString());
            ContentRoot = vObject["ContentRoot"].ToString();
            foreach (VProperty child in vObject.Children())
            {
                switch (child.Key)
                {
                case "FileMapping":
                    VObject mapping = (VObject)child.Value;
                    FileMappings.Add(new FileMapping {
                        LocalPath = mapping["LocalPath"].ToString(),
                        DepotPath = mapping["DepotPath"].ToString(),
                        Recursive = int.Parse(mapping["recursive"].ToString())
                    });
                    break;

                case "FileExclusion":
                    FileExclusions.Add(new FileExclusion(child.Value.ToString()));
                    break;

                default:
                    continue;
                }
            }
        }
Esempio n. 2
0
        private void GenerateFeatureMappings([NotNull, ItemNotNull] IList <ProjectOutputGroup> projectOutputGroups, [NotNull, ItemNotNull] IList <Project> vsProjects, [NotNull] WixProject wixProject)
        {
            Debug.Assert(FileMappings != null);

            var componentNodes      = wixProject.ComponentNodes.ToDictionary(node => node.Id);
            var componentGroupNodes = wixProject.ComponentGroupNodes.ToDictionary(node => node.Id);
            var fileNodes           = wixProject.FileNodes.ToDictionary(node => node.Id);
            var fileMappingsLookup  = FileMappings.ToDictionary(fm => fm.Id);
            var featureMappings     = new List <FeatureMapping>();

            foreach (var featureNode in wixProject.FeatureNodes)
            {
                var installedFileNodes = featureNode.EnumerateInstalledFiles(componentGroupNodes, componentNodes, fileNodes)
                                         .ToList().AsReadOnly();

                var fileMappings = installedFileNodes
                                   .Select(file => fileMappingsLookup.GetValueOrDefault(file.Id))
                                   .Where(item => item != null)
                                   .ToList().AsReadOnly();

                var installedTargetNames = new HashSet <string>(fileMappings.Select(fm => fm.TargetName));

                var projects = vsProjects
                               .Where(p => installedTargetNames.Contains(p.PrimaryOutputFileName))
                               .ToList().AsReadOnly();

                var requiredOutputs = projectOutputGroups
                                      .Where(group => projects.Any(proj => group.Projects.Contains(proj)))
                                      .ToList().AsReadOnly();

                var missingOutputs = requiredOutputs
                                     .Where(o => !installedTargetNames.Contains(o.TargetName))
                                     .ToList().AsReadOnly();

                featureMappings.Add(new FeatureMapping(featureNode, fileMappings, projects, requiredOutputs, missingOutputs));
            }

            var featureMappingsLookup = featureMappings.ToDictionary(item => item.FeatureNode);

            foreach (var featureMapping in featureMappings)
            {
                var parentNode = featureMapping.FeatureNode.Parent;
                if (parentNode == null)
                {
                    continue;
                }

                featureMapping.Parent = featureMappingsLookup.GetValueOrDefault(parentNode);
            }

            foreach (var featureMapping in featureMappings)
            {
                featureMapping.Parent?.Children.Add(featureMapping);
            }

            FeatureMappings = featureMappings
                              .Where(feature => feature?.Parent == null)
                              .ToList().AsReadOnly();
        }
Esempio n. 3
0
 public Depot(int depotId)
 {
     DepotId = depotId;
     FileMappings.Add(new FileMapping());
     FileExclusions.Add(new FileExclusion());
 }
Esempio n. 4
0
        private void ProcessMod(string gameDataPath, long modId, FileMappings fileMappings, bool rebuildGameJson)
        {
            if (rebuildGameJson)
            {
                _converter.Convert(gameDataPath, modId);
            }
            var tempFolderForMod = Path.Combine(DataWriter.ProjectBaseFolder, "Temp", modId.ToString());

            var localizations = _jsonLoader.LoadLocalizations(tempFolderForMod).Concat(
                _jsonLoader.LoadLocalizations(Path.Combine(DataWriter.ProjectBaseFolder, "Temp", "0"))).DistinctBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);

            var countries = MapFiles(_jsonLoader.LoadCountries, fileMappings.Countries, tempFolderForMod, x => x.Filename);

            var countryHistories = MapFiles(_jsonLoader.LoadHistoryCountries, fileMappings.History.Countries, tempFolderForMod, x => x.Filename);
            var countryTags      = MapFiles(_jsonLoader.LoadCountryTags, fileMappings.CountryTags, tempFolderForMod, x => x.Key);
            var ideas            = MapFiles(_jsonLoader.LoadIdeas, fileMappings.Ideas, tempFolderForMod, x => x.Name);
            var policies         = MapFiles(_jsonLoader.LoadPolicies, fileMappings.Policies, tempFolderForMod, x => x.Name);
            var religions        = MapFiles(_jsonLoader.LoadReligions, fileMappings.Religions, tempFolderForMod, x => x.Name);
            var cultures         = MapFiles(_jsonLoader.LoadCultures, fileMappings.Cultures, tempFolderForMod, x => x.Name);

            var countryIdeas = ideas.Where(x => string.IsNullOrEmpty(x.Category)).ToList();
            var ideaGroups   = ideas.Where(x => !string.IsNullOrEmpty(x.Category)).ToList();

            // filter the country histories based on the country tags
            countryHistories = countryHistories.Where(x => countryTags.Any(ct => ct.Value.Split('/')[1].Trim() == x.Filename.Split('-')[1].Trim())).ToList();

            var religionsOutput  = CombineReligionData(religions);
            var countriesOutput  = CombineCountryData(countries, countryTags.ToDictionary(x => x.Key, x => x.Value), countryIdeas, countryHistories, religions, cultures);
            var ideaGroupsOutput = CombineIdeaGroups(ideaGroups, localizations);
            var policiesOutput   = policies.Select(x => new Models.Output.Policies.Policy
            {
                Name         = x.Name,
                Allow        = x.Allow,
                Potential    = x.Potential,
                Bonuses      = x.Bonuses,
                MonarchPower = x.MonarchPower
            }).ToList();

            var religionBonuses = religionsOutput.SelectMany(x => x.Religions.SelectMany(y =>
                                                                                         (y.Province ?? new Dictionary <string, string>()).Concat(y.SecondaryCountry ?? new Dictionary <string, string>()).Concat(y.Province ?? new Dictionary <string, string>()))
                                                             ).ToList();
            var ideaBonuses   = ideas.SelectMany(x => x.Ideas.SelectMany(y => y.Bonuses)).ToList();
            var policyBonuses = policies.SelectMany(x => x.Bonuses).ToList();
            var bonuses       = religionBonuses
                                .Concat(ideaBonuses)
                                .Concat(policyBonuses)
                                .Select(x => x.Key)
                                .Distinct().ToList();

            _dataWriter.Write("bonuses", new { bonuses = bonuses }, "Web\\Data\\" + modId.ToString());
            _dataWriter.Write("religionGroups", new { religionGroups = religionsOutput }, "Web\\Data\\" + modId.ToString());
            _dataWriter.Write("countries", new { countries = countriesOutput }, "Web\\Data\\" + modId.ToString());
            _dataWriter.Write("ideaGroups", new { ideaGroups = ideaGroupsOutput }, "Web\\Data\\" + modId.ToString());
            _dataWriter.Write("policies", new { policies = policiesOutput }, "Web\\Data\\" + modId.ToString());

            CreateCountryImages(countriesOutput, modId, true);
            CreateBonusImages(bonuses, modId);

            _dataWriter.Write("mods", new Parsing.ModList
            {
                Mods = _config.Mods.Concat(new Config.Mod[] { new Config.Mod {
                                                                  Id = 0, Name = "Base Game", FileMappings = _config.BaseFileMappings
                                                              } }).Select(x =>
                {
                    var sections = new List <ModSection>();
                    if (x.FileMappings.Sections.Countries)
                    {
                        sections.Add(new ModSection {
                            Name = "countries", DisplayName = "Countries"
                        });
                    }
                    if (x.FileMappings.Sections.Policies)
                    {
                        sections.Add(new ModSection {
                            Name = "policies", DisplayName = "Policies"
                        });
                    }
                    if (x.FileMappings.Sections.Ideas)
                    {
                        sections.Add(new ModSection {
                            Name = "ideaGroups", DisplayName = "Idea Groups"
                        });
                    }
                    if (x.FileMappings.Sections.Religions)
                    {
                        sections.Add(new ModSection {
                            Name = "religionGroups", DisplayName = "Religions"
                        });
                    }
                    //if (x.FileMappings.Sections.GreatProjects)
                    //{
                    //	sections.Add(new ModSection { Name = "greatProjects", DisplayName = "Great Projects" });
                    //}
                    return(new Parsing.Mod {
                        Id = x.Id, Name = x.Name, Sections = sections, Bonuses = "bonuses"
                    });
                }).ToList()
            }, "Web\\Data\\");
        }