public bool                         Injected(ModHelperDef def)
        {
            if (def.ITabs.NullOrEmpty())
            {
                return(true);
            }

            for (var index = 0; index < def.ITabs.Count; index++)
            {
                var injectionSet = def.ITabs[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                var thingDefs = DefInjectionQualifier.FilteredThingDefs(injectionSet.qualifier, ref injectionSet.qualifierInt, injectionSet.targetDefs);
                if (!thingDefs.NullOrEmpty())
                {
                    foreach (var thingDef in thingDefs)
                    {
                        if (
                            (thingDef.inspectorTabs.NullOrEmpty()) ||
                            (!thingDef.inspectorTabs.Contains(injectionSet.newITab))
                            )
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Пример #2
0
        public bool                         Injected(ModHelperDef def)
        {
            if (def.Facilities.NullOrEmpty())
            {
                return(true);
            }

            for (var index = 0; index < def.Facilities.Count; index++)
            {
                var injectionSet = def.Facilities[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                var facilityDef = DefDatabase <ThingDef> .GetNamed(injectionSet.facility);

                var thingDefs = DefInjectionQualifier.FilteredThingDefs(injectionSet.qualifier, ref injectionSet.qualifierInt, injectionSet.targetDefs);
                if (!thingDefs.NullOrEmpty())
                {
                    foreach (var thingDef in thingDefs)
                    {
                        var targetComp = thingDef.GetCompProperties <CompProperties_AffectedByFacilities>();
                        if (!targetComp.linkableFacilities.Contains(facilityDef))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Пример #3
0
 public static List <ThingDef> FilteredThingDefs(Type qualifier, ref DefInjectionQualifier qualifierInt, List <string> targetDefs)
 {
     if (!targetDefs.NullOrEmpty())
     {
         return(DefDatabase <ThingDef> .AllDefs.Where(def => targetDefs.Contains(def.defName)).ToList());
     }
     if (qualifierInt == null)
     {
         qualifierInt = (DefInjectionQualifier)Activator.CreateInstance(qualifier);
         if (qualifierInt == null)
         {
             return(null);
         }
     }
     return(DefDatabase <ThingDef> .AllDefs.Where(qualifierInt.Test).ToList());
 }
Пример #4
0
        public bool                         Inject(ModHelperDef def)
        {
            if (def.ThingComps.NullOrEmpty())
            {
                return(true);
            }

            for (var index = 0; index < def.ThingComps.Count; index++)
            {
                var injectionSet = def.ThingComps[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                var thingDefs = DefInjectionQualifier.FilteredThingDefs(injectionSet.qualifier, ref injectionSet.qualifierInt, injectionSet.targetDefs);
                if (!thingDefs.NullOrEmpty())
                {
#if DEBUG
                    var stringBuilder = new StringBuilder();
                    stringBuilder.Append("ThingComps :: Qualifier returned: ");
#endif
                    foreach (var thingDef in thingDefs)
                    {
#if DEBUG
                        stringBuilder.Append(thingDef.defName + ", ");
#endif
                        // TODO:  Make a full copy using the comp in this def as a template
                        // Currently adds the comp in this def so all target use the same def
                        if (!thingDef.HasComp(injectionSet.compProps.compClass))
                        {
                            thingDef.comps.Add(injectionSet.compProps);
                        }
                    }
#if DEBUG
                    CCL_Log.Message(stringBuilder.ToString(), def.ModName);
#endif
                }
            }

            return(true);
        }
        public bool                         Inject(ModHelperDef def)
        {
            if (def.ITabs.NullOrEmpty())
            {
                return(true);
            }

            for (var index = 0; index < def.ITabs.Count; index++)
            {
                var injectionSet = def.ITabs[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                var thingDefs = DefInjectionQualifier.FilteredThingDefs(injectionSet.qualifier, ref injectionSet.qualifierInt, injectionSet.targetDefs);
                if (!thingDefs.NullOrEmpty())
                {
#if DEBUG
                    var stringBuilder = new StringBuilder();
                    stringBuilder.Append("ITabs :: Qualifier returned: ");
#endif
                    foreach (var thingDef in thingDefs)
                    {
#if DEBUG
                        stringBuilder.Append(thingDef.defName + ", ");
#endif
                        if (!InjectITab(injectionSet.newITab, injectionSet.replaceITab, thingDef))
                        {
                            return(false);
                        }
                    }
#if DEBUG
                    CCL_Log.Message(stringBuilder.ToString(), def.ModName);
#endif
                }
            }

            return(true);
        }
Пример #6
0
        public bool                         Inject(ModHelperDef def)
        {
            if (def.Facilities.NullOrEmpty())
            {
                return(true);
            }

            for (var index = 0; index < def.Facilities.Count; index++)
            {
                var injectionSet = def.Facilities[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                var facilityDef = DefDatabase <ThingDef> .GetNamed(injectionSet.facility);

                var thingDefs = DefInjectionQualifier.FilteredThingDefs(injectionSet.qualifier, ref injectionSet.qualifierInt, injectionSet.targetDefs);
                if (!thingDefs.NullOrEmpty())
                {
#if DEBUG
                    var stringBuilder = new StringBuilder();
                    stringBuilder.Append("Facilities :: Qualifier returned: ");
#endif
                    foreach (var thingDef in thingDefs)
                    {
#if DEBUG
                        stringBuilder.Append(thingDef.defName + ", ");
#endif
                        LinkFacility(thingDef, facilityDef);
                    }
#if DEBUG
                    CCL_Log.Message(stringBuilder.ToString(), def.ModName);
#endif
                }
            }

            return(true);
        }
Пример #7
0
        public bool                         Injected(ModHelperDef def)
        {
            if (def.ThingComps.NullOrEmpty())
            {
                return(true);
            }

            for (var index = 0; index < def.ThingComps.Count; index++)
            {
                var injectionSet = def.ThingComps[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                var thingDefs = DefInjectionQualifier.FilteredThingDefs(injectionSet.qualifier, ref injectionSet.qualifierInt, injectionSet.targetDefs);
                if (!thingDefs.NullOrEmpty())
                {
                    foreach (var thingDef in thingDefs)
                    {
                        if (
                            (injectionSet.compProps.compClass != null) &&
                            (!thingDef.comps.Exists(s => (s.compClass == injectionSet.compProps.compClass)))
                            )
                        {
                            return(false);
                        }
                        else if (thingDef.GetCompProperty(injectionSet.compProps.GetType()) == null)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
        public bool                         IsValid(ModHelperDef def, ref string errors)
        {
            if (def.ITabs.NullOrEmpty())
            {
                return(true);
            }

            bool isValid = true;

            for (var iTabIndex = 0; iTabIndex < def.ITabs.Count; iTabIndex++)
            {
                var qualifierValid = true;
                var injectionSet   = def.ITabs[iTabIndex];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                var replaceTabIsValid = true;
                if (
                    (injectionSet.newITab == null) ||
                    (!injectionSet.newITab.IsSubclassOf(typeof(ITab)))
                    )
                {
                    errors += string.Format("Unable to resolve ITab '{0}'", injectionSet.newITab);
                    isValid = false;
                }
                if (
                    (injectionSet.replaceITab != null) &&
                    (!injectionSet.replaceITab.IsSubclassOf(typeof(ITab)))
                    )
                {
                    errors           += string.Format("Unable to resolve ITab '{0}'", injectionSet.replaceITab);
                    isValid           = false;
                    replaceTabIsValid = false;
                }
                if (
                    (injectionSet.targetDefs.NullOrEmpty()) &&
                    (injectionSet.qualifier == null)
                    )
                {
                    errors        += "targetDefs and qualifier are both null, one or the other must be supplied";
                    isValid        = false;
                    qualifierValid = false;
                }
                if (
                    (!injectionSet.targetDefs.NullOrEmpty()) &&
                    (injectionSet.qualifier != null)
                    )
                {
                    errors        += "targetDefs and qualifier are both supplied, only one or the other must be supplied";
                    isValid        = false;
                    qualifierValid = false;
                }
                if (qualifierValid)
                {
                    if (!injectionSet.targetDefs.NullOrEmpty())
                    {
                        for (var index = 0; index < injectionSet.targetDefs.Count; index++)
                        {
                            if (injectionSet.targetDefs[index].NullOrEmpty())
                            {
                                errors += string.Format("targetDef in ITabs is null or empty at index {0}", index.ToString());
                                isValid = false;
                            }
                            else
                            {
                                var thingDef = DefDatabase <ThingDef> .GetNamed(injectionSet.targetDefs[index], false);

                                if (thingDef == null)
                                {
                                    errors += string.Format("Unable to resolve targetDef '{0}'", injectionSet.targetDefs[index]);
                                    isValid = false;
                                }
                                else if (
                                    (injectionSet.replaceITab != null) &&
                                    (replaceTabIsValid)
                                    )
                                {
                                    if (!CanReplaceOn(thingDef, injectionSet.replaceITab))
                                    {
                                        errors += string.Format("targetDef '{0}' does not contain ITab '{1}' to replace", injectionSet.targetDefs[index], injectionSet.replaceITab);
                                        isValid = false;
                                    }
                                }
                            }
                        }
                    }
                    if (injectionSet.qualifier != null)
                    {
                        if (!injectionSet.qualifier.IsSubclassOf(typeof(DefInjectionQualifier)))
                        {
                            errors += string.Format("Unable to resolve qualifier '{0}'", injectionSet.qualifier);
                            isValid = false;
                        }
                        else if (
                            (injectionSet.replaceITab != null) &&
                            (replaceTabIsValid)
                            )
                        {
                            var thingDefs = DefInjectionQualifier.FilteredThingDefs(injectionSet.qualifier, ref injectionSet.qualifierInt, null);
                            if (!thingDefs.NullOrEmpty())
                            {
                                foreach (var thingDef in thingDefs)
                                {
                                    if (!CanReplaceOn(thingDef, injectionSet.replaceITab))
                                    {
                                        errors += string.Format("qualified ThingDef '{0}' does not contain ITab '{1}' to replace", thingDef.defName, injectionSet.replaceITab);
                                        isValid = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(isValid);
        }
Пример #9
0
        public bool                         IsValid(ModHelperDef def, ref string errors)
        {
            if (def.ThingComps.NullOrEmpty())
            {
                return(true);
            }

            bool isValid = true;

            for (var index = 0; index < def.ThingComps.Count; index++)
            {
                var injectionSet   = def.ThingComps[index];
                var qualifierValid = true;
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                if (
                    (injectionSet.targetDefs.NullOrEmpty()) &&
                    (injectionSet.qualifier == null)
                    )
                {
                    errors        += "targetDefs and qualifier are both null, one or the other must be supplied";
                    isValid        = false;
                    qualifierValid = false;
                }
                if (
                    (!injectionSet.targetDefs.NullOrEmpty()) &&
                    (injectionSet.qualifier != null)
                    )
                {
                    errors        += "targetDefs and qualifier are both supplied, only one or the other must be supplied";
                    isValid        = false;
                    qualifierValid = false;
                }
                if (injectionSet.compProps == null)
                {
                    errors += "\n\tNull compProps in ThingComps";
                    isValid = false;
                }
                if (qualifierValid)
                {
                    if (!injectionSet.targetDefs.NullOrEmpty())
                    {
                        for (int index2 = 0; index2 < injectionSet.targetDefs.Count; ++index2)
                        {
                            if (injectionSet.targetDefs[index2].NullOrEmpty())
                            {
                                errors += string.Format("targetDef in ThingComps is null or empty at index {0}", index2.ToString());
                                isValid = false;
                            }
                            else
                            {
                                var thingDef = DefDatabase <ThingDef> .GetNamed(injectionSet.targetDefs[index2], false);

                                if (thingDef == null)
                                {
                                    errors += string.Format("Unable to resolve targetDef '{0}' in ThingComps", thingDef.defName);
                                    isValid = false;
                                }
                                else
                                {
                                    if (!CanInjectInto(thingDef, injectionSet.compProps.compClass, injectionSet.compProps.GetType()))
                                    {
                                        errors += string.Format("Cannot inject ThingComps '{0}' into targetDef '{1}' - ThingComp with compClass or CompProperties may already exist, ", injectionSet.compProps, thingDef.defName);
                                        isValid = false;
                                    }
                                }
                            }
                        }
                    }
                    if (injectionSet.qualifier != null)
                    {
                        if (!injectionSet.qualifier.IsSubclassOf(typeof(DefInjectionQualifier)))
                        {
                            errors += string.Format("Unable to resolve qualifier '{0}'", injectionSet.qualifier);
                            isValid = false;
                        }
                        else
                        {
                            var thingDefs = DefInjectionQualifier.FilteredThingDefs(injectionSet.qualifier, ref injectionSet.qualifierInt, null);
                            if (!thingDefs.NullOrEmpty())
                            {
                                foreach (var thingDef in thingDefs)
                                {
                                    if (!CanInjectInto(thingDef, injectionSet.compProps.compClass, injectionSet.compProps.GetType()))
                                    {
                                        errors += string.Format("Cannot inject ThingComps '{0}' into targetDef '{1}' - ThingComp with compClass or CompProperties may already exist, ", injectionSet.compProps, thingDef.defName);
                                        isValid = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(isValid);
        }
Пример #10
0
        public bool                         IsValid(ModHelperDef def, ref string errors)
        {
            if (def.Facilities.NullOrEmpty())
            {
                return(true);
            }

            bool isValid = true;

            for (int index = 0; index < def.Facilities.Count; ++index)
            {
                var qualifierValid = true;
                var injectionSet   = def.Facilities[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                if (injectionSet.facility.NullOrEmpty())
                {
                    errors += string.Format("\n\tfacility in Facilities {0} is null", index);
                    isValid = false;
                }
                else
                {
                    var facilityDef = DefDatabase <ThingDef> .GetNamed(injectionSet.facility, false);

                    if (facilityDef == null)
                    {
                        errors += string.Format("Unable to resolve facility '{0}' in Facilities", injectionSet.facility);
                        isValid = false;
                    }
                    else if (facilityDef.GetCompProperties <CompProperties_Facility>() == null)
                    {
                        // Check comps
                        errors += string.Format("'{0}' is missing CompFacility for facility injection", injectionSet.facility);
                        isValid = false;
                    }
                }
                if (
                    (injectionSet.targetDefs.NullOrEmpty()) &&
                    (injectionSet.qualifier == null)
                    )
                {
                    errors        += "targetDefs and qualifier are both null, one or the other must be supplied";
                    isValid        = false;
                    qualifierValid = false;
                }
                if (
                    (!injectionSet.targetDefs.NullOrEmpty()) &&
                    (injectionSet.qualifier != null)
                    )
                {
                    errors        += "targetDefs and qualifier are both supplied, only one or the other must be supplied";
                    isValid        = false;
                    qualifierValid = false;
                }
                if (qualifierValid)
                {
                    if (!injectionSet.targetDefs.NullOrEmpty())
                    {
                        for (int index2 = 0; index2 < injectionSet.targetDefs.Count; ++index2)
                        {
                            var thingDef = DefDatabase <ThingDef> .GetNamed(injectionSet.targetDefs[index2], false);

                            if (thingDef == null)
                            {
                                errors += string.Format("Unable to resolve targetDef '{0}' in Facilities", injectionSet.targetDefs[index2]);
                                isValid = false;
                            }
                            else if (!CanInjectInto(thingDef))
                            {
                                errors += string.Format("'{0}' is missing CompAffectedByFacilities for facility injection", injectionSet.targetDefs[index2]);
                                isValid = false;
                            }
                        }
                    }
                    if (injectionSet.qualifier != null)
                    {
                        if (!injectionSet.qualifier.IsSubclassOf(typeof(DefInjectionQualifier)))
                        {
                            errors += string.Format("Unable to resolve qualifier '{0}'", injectionSet.qualifier);
                            isValid = false;
                        }
                        else
                        {
                            var thingDefs = DefInjectionQualifier.FilteredThingDefs(injectionSet.qualifier, ref injectionSet.qualifierInt, null);
                            if (!thingDefs.NullOrEmpty())
                            {
                                foreach (var thingDef in thingDefs)
                                {
                                    if (!CanInjectInto(thingDef))
                                    {
                                        errors += string.Format("'{0}' is missing CompAffectedByFacilities for facility injection", thingDef.defName);
                                        isValid = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(isValid);
        }
        public bool                         Inject(ModHelperDef def)
        {
            if (def.ThingDefAvailability.NullOrEmpty())
            {
                return(true);
            }

            for (int index = 0; index < def.ThingDefAvailability.Count; ++index)
            {
                var injectionSet = def.ThingDefAvailability[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                var thingDefs = DefInjectionQualifier.FilteredThingDefs(injectionSet.qualifier, ref injectionSet.qualifierInt, injectionSet.targetDefs);
                if (!thingDefs.NullOrEmpty())
                {
#if DEBUG
                    var stringBuilder = new StringBuilder();
                    stringBuilder.Append("ThingDefAvailability :: Qualifier returned: ");
#endif
                    bool setMenuHidden  = !injectionSet.menuHidden.NullOrEmpty();
                    bool setDesignation = !injectionSet.designationCategory.NullOrEmpty();
                    bool setResearch    = injectionSet.researchPrerequisites != null;

                    bool menuHidden = false;
                    List <ResearchProjectDef> research = null;

                    if (setMenuHidden)
                    {
                        menuHidden = injectionSet.menuHidden.ToLower() == "true" ? true : false;
                    }
                    if (
                        (setResearch) &&
                        (injectionSet.researchPrerequisites.Count > 0)
                        )
                    {
                        research = DefDatabase <ResearchProjectDef> .AllDefs.Where(projectDef => injectionSet.researchPrerequisites.Contains(projectDef.defName)).ToList();
                    }

                    foreach (var thingDef in thingDefs)
                    {
#if DEBUG
                        stringBuilder.Append(thingDef.defName + ", ");
#endif
                        if (setMenuHidden)
                        {
                            thingDef.menuHidden = menuHidden;
                        }
                        if (setDesignation)
                        {
                            thingDef.ChangeDesignationCategory(injectionSet.designationCategory);
                        }
                        if (setResearch)
                        {
                            thingDef.researchPrerequisites = research;
                        }
                    }
#if DEBUG
                    CCL_Log.Message(stringBuilder.ToString(), def.ModName);
#endif
                }
            }

            dictInjected.Add(def.defName, true);
            return(true);
        }