Пример #1
0
        private ModEntityData <T> ProcessDependant <T>(EntityCreator <T> creator, ParseTarget parseTarget) where T : Entity
        {
            ModEntityData <T> entities = CreateDependant(creator, parseTarget);

            entities?.ApplyToChain((ents, links) => {
                var invalidEntities = ents.Where(x => !x.Value.Prerequisites.Any()).Select(x => x.Value).ToList();
                foreach (var invalidEntity in invalidEntities)
                {
                    Log.Logger.Warning("Removing {entityId} from {file} dependant entities as we were unable to locate its specified pre-requisite techs", invalidEntity.Id,
                                       invalidEntity.FilePath);
                    ents.Remove(invalidEntity.Id);
                    var invalidLinks = links.Where(x => x.To.Id == invalidEntity.Id).ToList();
                    links.RemoveAll(invalidLinks);
                }
            });

            if (entities != null)
            {
                foreach (var entity in entities.AllEntities)
                {
                    foreach (var prerequisite in entity.Prerequisites)
                    {
                        if (prerequisite.ExtraDesc != null)
                        {
                            entity.ExtraDesc = prerequisite.ExtraDesc;
                        }
                    }
                }

                Log.Logger.Debug("Processed {entityCount} {parseTarget} with {linkCount} links", entities.EntityCount, parseTarget, entities.LinkCount);
            }
            else
            {
                Log.Logger.Warning("{parseTarget} had no items in any of the sources");
            }

            return(entities);
        }
        public void Parse(IEnumerable <ParseTarget> parseTargets)
        {
            var techTreeGraphCreator      = new TechTreeGraphCreator(Localisation, CWParser, StellarisDirectoryHelper, ModDirectoryHelpers);
            ModEntityData <Tech> techData = techTreeGraphCreator.CreateTechnologyGraph();

            Log.Logger.Debug("Processed {entityCount} techs with {linkCount} Links", techData.EntityCount, techData.LinkCount);
            // process technolgoies first
            var techImageOutputDir = OutputDirectoryHelper.GetImagesPath(ParseTarget.Technologies.ImagesDirectory());

            if (CopyImages)
            {
                CopyMainImages(techData.AllEntities, ParseTarget.Technologies.ImagesDirectory(),
                               techImageOutputDir);

                // because the image copying only get the most recent version of the entity, make sure that the image flag is set on all
                // relevant for the vanilla graph display
                var currentTechs = techData.AllEntitiesByKey;
                techData.ApplyToChain((techs, links) =>
                {
                    foreach (var tech in techs.Values)
                    {
                        tech.IconFound = currentTechs[tech.Id].IconFound;
                    }
                });

                var techAreas = Enum.GetValues(typeof(TechArea)).Cast <TechArea>();
                var areaDir   = Path.Combine(techImageOutputDir, "areas");

                // tech areas
                Directory.CreateDirectory(areaDir);
                foreach (var techArea in techAreas)
                {
                    var inputPath = Path.Combine(StellarisDirectoryHelper.Icons, "resources", techArea.ToString().ToLowerInvariant() + "_research.dds");
                    // icon to be displayed on the 3 root nodes
                    ImageOutput.TransformAndOutputImage(
                        inputPath,
                        Path.Combine(techImageOutputDir, techArea + "-root.png"));

                    // area icon
                    ImageOutput.TransformAndOutputImage(
                        inputPath,
                        Path.Combine(areaDir, techArea.ToString().ToLowerInvariant() + ".png"));
                }

                // tech categories
                CopyCategoryImages(techImageOutputDir);
            }

            // process dependant objects
            ObjectsDependantOnTechs dependants = null;
            var parseTargetsWithoutTechs       = parseTargets.WithoutTechs().ToList();

            if (parseTargetsWithoutTechs.Any())
            {
                var dependantsGraphCreator = new DependantsGraphCreator(Localisation, CWParser, StellarisDirectoryHelper, ModDirectoryHelpers, techData);
                dependants = dependantsGraphCreator.CreateDependantGraph(parseTargetsWithoutTechs);

                if (CopyImages)
                {
                    foreach (var parseTarget in parseTargetsWithoutTechs)
                    {
                        var imageOutputDir = OutputDirectoryHelper.GetImagesPath(parseTarget.ImagesDirectory());
                        var entityData     = dependants.Get(parseTarget);
                        CopyMainImages(entityData, parseTarget.ImagesDirectory(), imageOutputDir);
                    }
                    dependants.FixImages();
                }
            }

            var visDataMarshaler = new VisDataMarshaler(localisation, OutputDirectoryHelper);
            IDictionary <string, VisData> techVisResults = visDataMarshaler.CreateTechVisData(techData, techImageOutputDir);
            ModEntityData <Tech>          coreGameTech   = techData.FindCoreGameData();

            if (coreGameTech != null)
            {
                IDictionary <string, VisData> techVisData = visDataMarshaler.CreateTechVisData(coreGameTech, techImageOutputDir);
                techVisResults["Stellaris-No-Mods"] = techVisData[StellarisDirectoryHelper.StellarisCoreRootDirectory];
            }
            else
            {
                Log.Logger.Warning("Could not find core game tech files to generate vanilla tree");
            }

            VisData rootNotes = visDataMarshaler.CreateRootNotes(techData, techImageOutputDir);

            techVisResults["Tech-Root-Nodes"] = rootNotes;
            WriteVisData(techVisResults, true);

            if (dependants != null)
            {
                var dependantVisResults = visDataMarshaler.CreateGroupedVisDependantData(techVisResults, dependants, parseTargetsWithoutTechs);
                var coreDependantsOnly  = dependants.CopyOnlyCore();

                // also do a no-mods lookup
                var stellarisNoModsTechVisResult            = techVisResults["Stellaris-No-Mods"];
                IDictionary <string, VisData> visLookupData =
                    stellarisNoModsTechVisResult != null ? new Dictionary <string, VisData>()
                {
                    { "Stellaris-No-Mods", stellarisNoModsTechVisResult }
                } : techVisResults;
                var coreDependantData = visDataMarshaler.CreateGroupedVisDependantData(visLookupData, coreDependantsOnly, parseTargetsWithoutTechs);

                if (coreDependantData.ContainsKey(StellarisDirectoryHelper.StellarisCoreRootDirectory))
                {
                    dependantVisResults["Stellaris-No-Mods"] = coreDependantData[StellarisDirectoryHelper.StellarisCoreRootDirectory];
                }
                else
                {
                    Log.Logger.Warning("Could not find core game dependant files to generate vanilla tree");
                }

                WriteVisData(dependantVisResults, false);
            }
        }