private void AddLinks(ModEntityData <T> data, ModEntityData <Tech> techs)
        {
            foreach (var entity in data.Entities)
            {
                // it is possible that the pre-reqs for a something do not exist
                // in this we do not add them to the populated list, but leave them in the ids list
                var prereqs = new List <Tech>();
                foreach (var prerequisiteId in entity.PrerequisiteIds)
                {
                    if (techs.ContainsEntityInTree(prerequisiteId))
                    {
                        var prereq = techs[prerequisiteId];
                        prereqs.Add(prereq);
                        data.Links.Add(new Link()
                        {
                            From = prereq, To = entity
                        });
                    }
                    else
                    {
                        Log.Logger.Warning("Could not find prerequisite {prerequisite} for {entityType} {entityId} in {filePath}",
                                           prerequisiteId, entity.GetType().Name, entity.Id, entity.FilePath);
                    }
                }

                entity.Prerequisites = prereqs;
            }
        }
示例#2
0
        public ModEntityData <Tech> CreateTechnologyGraph()
        {
            ModEntityData <Tech> techs = null;

            foreach (var modDirectoryHelper in StellarisDirectoryHelper.CreateCombinedList(stellarisDirectoryHelper, modDirectoryHelpers))
            {
                techs = ProcessDirectoryHelper(techs, modDirectoryHelper, null);
            }

            // post process because while most things work on the principle of:
            // later mod override core
            // later mod override core
            // core
            // some have the core first, then additional features that depend on it (Zenith, I am looking at you)
            // so need to post process

            techs?.ApplyToChain((modTechs, modLinks) => {
                foreach (var(key, tech) in modTechs)
                {
                    if (tech.Prerequisites.Count == tech.PrerequisiteIds.Count())
                    {
                        continue;
                    }

                    Log.Logger.Debug("Tech {id} had missing pre-requisite, trying to find it in the complete listing", key);
                    var populatedPreReqs = tech.Prerequisites.Select(preReq => preReq.Id).ToHashSet();
                    foreach (var missingPreReq in tech.PrerequisiteIds.Where(x => !populatedPreReqs.Contains(x)))
                    {
                        if (techs.ContainsEntityInTree(missingPreReq))
                        {
                            Tech attemptToFindPreq = techs[missingPreReq];
                            tech.Prerequisites.Add(attemptToFindPreq);
                            modLinks.Add(new Link()
                            {
                                From = attemptToFindPreq, To = tech
                            });
                            Log.Logger.Debug("Found prereq {key} in file {file}", attemptToFindPreq.Id, attemptToFindPreq.FilePath);
                        }
                        else
                        {
                            Log.Logger.Debug("Still unable to find {prereqId} for Tech {id}", missingPreReq, key);
                        }
                    }
                }
            });

            return(techs);
        }