コード例 #1
0
        public ObjectsDependantOnTechs CreateDependantGraph(IList <ParseTarget> parseTargetsWithoutTechs)
        {
            var result = new ObjectsDependantOnTechs();

            foreach (var target in parseTargetsWithoutTechs)
            {
                switch (target)
                {
                case ParseTarget.Buildings: {
                    var creator = new BuildingGraphCreator(localisationApiHelper, cwParserHelper);
                    result.Buildings = ProcessDependant(creator, target);
                    break;
                }

                case ParseTarget.ShipComponents: {
                    var shipComponentSetGraphCreator = new ShipComponentSetGraphCreator(localisationApiHelper, cwParserHelper);
                    var shipComponentGraphCreator    = new ShipComponentGraphCreator(localisationApiHelper, cwParserHelper);
                    var shipComponentSets            = CreateDependant(shipComponentSetGraphCreator, target);
                    var shipComponents = ProcessDependant(shipComponentGraphCreator, target);
                    result.SetShipComponents(shipComponents, shipComponentSets);
                    break;
                }

                case ParseTarget.Decisions: {
                    var creator = new DecisionGraphCreator(localisationApiHelper, cwParserHelper);
                    result.Decisions = ProcessDependant(creator, target);
                    break;
                }

                default: throw new Exception("unknown target: " + target);
                }
            }

            return(result);
        }
コード例 #2
0
        public static IEnumerable <Entity> Get(this ObjectsDependantOnTechs deps, ParseTarget parseTarget)
        {
            switch (parseTarget)
            {
            case ParseTarget.Technologies: throw new InvalidOperationException("No techs in dependants");

            case ParseTarget.Buildings: return(deps.Buildings.AllEntities);

            case ParseTarget.ShipComponents: return(deps.ShipComponentsSets.AllEntities);

            case ParseTarget.Decisions: return(deps.Decisions.AllEntities);

            default: throw new InvalidOperationException("Unknown type: " + parseTarget);
            }
        }
コード例 #3
0
        private VisData CreateDependantDataForModGroup(string modGroup, IDictionary <string, VisNode> prereqTechNodeLookup, ObjectsDependantOnTechs objectsDependantOnTechs,
                                                       IEnumerable <ParseTarget> parseTargets)
        {
            var result = new VisData()
            {
                ModGroup = modGroup,
            };

            foreach (var parseTarget in parseTargets.WithoutTechs())
            {
                switch (parseTarget)
                {
                case ParseTarget.Buildings: {
                    result.nodes.AddRange(objectsDependantOnTechs.Buildings.AllEntitiesForModGroup(modGroup)
                                          .Select(x => MarshalBuilding(x, prereqTechNodeLookup, outputDirectoryHelper.GetImagesPath(parseTarget.ImagesDirectory()))));
                    result.edges.AddRange(objectsDependantOnTechs.Buildings.AllLinksForModGroup(modGroup).Select(VisHelpers.MarshalLink));
                    break;
                }

                case ParseTarget.ShipComponents: {
                    result.nodes.AddRange(objectsDependantOnTechs.ShipComponentsSets.AllEntitiesForModGroup(modGroup)
                                          .Select(x => MarshallShipComponentSet(x, prereqTechNodeLookup, outputDirectoryHelper.GetImagesPath(parseTarget.ImagesDirectory()))));
                    ISet <Link> allLinksForModGroup = objectsDependantOnTechs.ShipComponentsSets.AllLinksForModGroup(modGroup);
                    result.edges.AddRange(allLinksForModGroup.Select(VisHelpers.MarshalLink));
                    break;
                }

                case ParseTarget.Decisions: {
                    result.nodes.AddRange(objectsDependantOnTechs.Decisions.AllEntitiesForModGroup(modGroup)
                                          .Select(x => MarshalDecision(x, prereqTechNodeLookup, outputDirectoryHelper.GetImagesPath(parseTarget.ImagesDirectory()))));
                    ISet <Link> allLinksForModGroup = objectsDependantOnTechs.Decisions.AllLinksForModGroup(modGroup);
                    result.edges.AddRange(allLinksForModGroup.Select(VisHelpers.MarshalLink));
                    break;
                }

                default:
                    throw new Exception(parseTarget.ToString());
                }
            }

            return(result);
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        public IDictionary <string, VisData> CreateGroupedVisDependantData(IDictionary <string, VisData> techData, ObjectsDependantOnTechs objectsDependantOnTechs,
                                                                           IEnumerable <ParseTarget> parseTargets)
        {
            Dictionary <string, VisNode> prereqTechNodeLookup =
                techData.Values.Select(x => x.nodes).SelectMany(x => x).Distinct(IEqualityComparerExtensions.Create <VisNode>(x => x.id)).ToDictionary(x => x.id);
            var result = new Dictionary <string, VisData>();

            objectsDependantOnTechs.ModGroups.ForEach(x => result[x] = CreateDependantDataForModGroup(x, prereqTechNodeLookup, objectsDependantOnTechs, parseTargets));
            return(result);
        }