Example #1
0
        public static List <Pair <Def, string> > GetUnlockDefsAndDescs(this ResearchProjectDef research)
        {
            if (_unlocksCache.ContainsKey(research))
            {
                return(_unlocksCache[research]);
            }

            var unlocks = new List <Pair <Def, string> >();

            unlocks.AddRange(research.GetThingsUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, "Fluffy.ResearchTree.AllowsBuildingX".Translate(d.LabelCap))));
            unlocks.AddRange(research.GetTerrainUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, "Fluffy.ResearchTree.AllowsBuildingX".Translate(d.LabelCap))));
            unlocks.AddRange(research.GetRecipesUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, "Fluffy.ResearchTree.AllowsCraftingX".Translate(d.LabelCap))));
            unlocks.AddRange(research.GetPlantsUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, "Fluffy.ResearchTree.AllowsPlantingX".Translate(d.LabelCap))));

            // get unlocks for all descendant research, and remove duplicates.
            var descendantUnlocks = research.Descendants().SelectMany(c => c.GetUnlockDefsAndDescs().Select(u => u.First)).ToList();

            unlocks = unlocks.Where(u => !descendantUnlocks.Contains(u.First)).ToList();

            _unlocksCache.Add(research, unlocks);
            return(unlocks);
        }
Example #2
0
        public static List <Pair <Def, string> > GetDirectUnlocks(this ResearchProjectDef research, bool dedupe = false)
        {
            var unlocks = new List <Pair <Def, string> >();

            unlocks.AddRange(research.GetThingsUnlocked()
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsBuildingX(d.LabelCap))));

            unlocks.AddRange(research.GetTerrainUnlocked()
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsBuildingX(d.LabelCap))));

            unlocks.AddRange(research.GetDirectRecipesUnlocked()
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsCraftingX(d.LabelCap))));

            unlocks.AddRange(research.GetPlantsUnlocked()
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsPlantingX(d.LabelCap))));

            var descendants = research.Descendants();

            if (dedupe && descendants.Any())
            {
                var descendantUnlocks = descendants
                                        .SelectMany(c => c.GetUnlockDefsAndDescs(false).Select(u => u.First))
                                        .Distinct()
                                        .ToList();
                unlocks = unlocks.Where(u => !descendantUnlocks.Contains(u.First)).ToList();
            }

            return(unlocks);
        }
Example #3
0
        public static List <Pair <Def, string> > GetUnlockDefsAndDescs(this ResearchProjectDef research, bool dedupe = true)
        {
            if (_unlocksCache.ContainsKey(research))
            {
                return(_unlocksCache[research]);
            }

            var unlocks = new List <Pair <Def, string> >();

            unlocks.AddRange(research.GetThingsUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsBuildingX(d.LabelCap))));

            unlocks.AddRange(research.GetTerrainUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsBuildingX(d.LabelCap))));

            unlocks.AddRange(research.GetRecipesUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsCraftingX(d.LabelCap))));

            unlocks.AddRange(research.GetPlantsUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsPlantingX(d.LabelCap))));



            // get unlocks for all descendant research, and remove duplicates.
            var descendants = research.Descendants();

            if (dedupe && descendants.Any())
            {
                var descendantUnlocks = descendants
                                        .SelectMany(c => c.GetUnlockDefsAndDescs(false).Select(u => u.First))
                                        .Distinct()
                                        .ToList();
                unlocks = unlocks.Where(u => !descendantUnlocks.Contains(u.First)).ToList();
            }

            _unlocksCache.Add(research, unlocks);
            return(unlocks);
        }