Exemplo n.º 1
0
        public bool                         Inject(ModHelperDef def)
        {
            if (def.TraderKinds.NullOrEmpty())
            {
                return(true);
            }

            for (var index = 0; index < def.TraderKinds.Count; index++)
            {
                var injectionSet = def.TraderKinds[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                var traderKindDef = DefDatabase <TraderKindDef> .GetNamed(injectionSet.targetDef);

                foreach (var stockGenerator in injectionSet.stockGenerators)
                {
                    traderKindDef.stockGenerators.Add(stockGenerator);
                    stockGenerator.PostLoad();
                    stockGenerator.ResolveReferences(traderKindDef);
                    CCL_Log.TraceMod(
                        def,
                        Verbosity.Injections,
                        string.Format("Injecting {0} into {1}", stockGenerator.GetType().Name, traderKindDef.label),
                        "TraderKinds");
                }
            }

            dictInjected.Add(def, true);
            return(true);
        }
Exemplo n.º 2
0
        public bool                         Injected(ModHelperDef def)
        {
            if (def.Facilities.NullOrEmpty())
            {
                return(true);
            }

            foreach (var facilitySet in def.Facilities)
            {
                bool processThis = true;
                if (!facilitySet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(facilitySet.requiredMod) != null;
                }
                if (processThis)
                {
                    var facilityDef = DefDatabase <ThingDef> .GetNamed(facilitySet.facility);

                    foreach (var target in facilitySet.targetDefs)
                    {
                        var targetDef = DefDatabase <ThingDef> .GetNamed(target);

                        var targetComp = targetDef.GetCompProperties <CompProperties_AffectedByFacilities>();
                        if (!targetComp.linkableFacilities.Contains(facilityDef))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        public bool                         IsValid(ModHelperDef def, ref string errors)
        {
            if (def.tickerSwitcher.NullOrEmpty())
            {
                return(true);
            }

            bool isValid = true;

            foreach (var switcherSet in def.tickerSwitcher)
            {
                bool processThis = true;
                if (!switcherSet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(switcherSet.requiredMod) != null;
                }
                if (processThis)
                {
                    foreach (var targetName in switcherSet.targetDefs)
                    {
                        var targetDef = DefDatabase <ThingDef> .GetNamed(targetName, false);

                        if (targetDef == null)
                        {
                            errors += string.Format("Unable to resolve targetDef '{0}' in TickerSwitcher", targetName);
                            isValid = false;
                        }
                    }
                }
            }

            return(isValid);
        }
Exemplo n.º 4
0
        public bool                         Inject(ModHelperDef def)
        {
            if (def.tickerSwitcher.NullOrEmpty())
            {
                return(true);
            }

            foreach (var switcherSet in def.tickerSwitcher)
            {
                bool processThis = true;
                if (!switcherSet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(switcherSet.requiredMod) != null;
                }
                if (processThis)
                {
                    foreach (var targetName in switcherSet.targetDefs)
                    {
                        var targetDef = DefDatabase <ThingDef> .GetNamed(targetName, false);

                        targetDef.tickerType = switcherSet.tickerType;
                    }
                }
            }

            return(true);
        }
        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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public bool                         Inject(ModHelperDef def)
        {
            if (def.ThingDefAvailability.NullOrEmpty())
            {
                return(true);
            }

            for (int index = 0; index < def.ThingDefAvailability.Count; ++index)
            {
                var availabilitySet = def.ThingDefAvailability[index];

                bool processThis = true;
                if (!availabilitySet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(availabilitySet.requiredMod) != null;
                }
                if (processThis)
                {
                    bool setMenuHidden  = !availabilitySet.menuHidden.NullOrEmpty();
                    bool setDesignation = !availabilitySet.designationCategory.NullOrEmpty();
                    bool setResearch    = availabilitySet.researchPrerequisites != null;

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

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

                    var targetDefs = DefDatabase <ThingDef> .AllDefs.Where(thingDef => availabilitySet.targetDefs.Contains(thingDef.defName)).ToList();

                    foreach (var target in targetDefs)
                    {
                        if (setMenuHidden)
                        {
                            target.menuHidden = menuHidden;
                        }
                        if (setDesignation)
                        {
                            target.ChangeDesignationCategory(availabilitySet.designationCategory);
                        }
                        if (setResearch)
                        {
                            target.researchPrerequisites = research;
                        }
                    }
                }
            }

            dictInjected.Add(def.defName, true);
            return(true);
        }
Exemplo n.º 8
0
        public bool                         Inject(ModHelperDef def)
        {
            if (def.Facilities.NullOrEmpty())
            {
                return(true);
            }

            foreach (var facilitySet in def.Facilities)
            {
                bool processThis = true;
                if (!facilitySet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(facilitySet.requiredMod) != null;
                }
                if (processThis)
                {
                    var facilityDef = DefDatabase <ThingDef> .GetNamed(facilitySet.facility);

                    foreach (var target in facilitySet.targetDefs)
                    {
                        var targetDef = DefDatabase <ThingDef> .GetNamed(target);

                        LinkFacility(targetDef, facilityDef);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 9
0
        public bool                         IsValid(ModHelperDef def, ref string errors)
        {
            if (def.TraderKinds.NullOrEmpty())
            {
                return(true);
            }

            bool isValid = true;

            for (int index = 0; index < def.TraderKinds.Count; ++index)
            {
                var  traderKindSet = def.TraderKinds[index];
                bool processThis   = true;
                if (!traderKindSet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(traderKindSet.requiredMod) != null;
                }
                if (processThis)
                {
                    if (traderKindSet.targetDef.NullOrEmpty())
                    {
                        errors += string.Format("\n\ttargetDef in TraderKinds {0} is null", index);
                        isValid = false;
                    }
                    else
                    {
                        var target        = traderKindSet.targetDef;
                        var traderKindDef = DefDatabase <TraderKindDef> .GetNamed(target, false);

                        if (traderKindDef == null)
                        {
                            errors += string.Format("Unable to resolve targetDef '{0}' in TraderKinds", target);
                            isValid = false;
                        }
                    }
                    for (int index2 = 0; index2 < traderKindSet.stockGenerators.Count; ++index2)
                    {
                        if (traderKindSet.stockGenerators[index2] == null)
                        {
                            errors += string.Format("\n\tstockGenerator {0} in TraderKinds {1} is null", index2, index);
                            isValid = false;
                        }
                    }
                }
            }

            return(isValid);
        }
Exemplo n.º 10
0
        public bool                         IsValid(ModHelperDef def, ref string errors)
        {
            if (def.TraderKinds.NullOrEmpty())
            {
                return(true);
            }

            bool isValid = true;

            for (int index = 0; index < def.TraderKinds.Count; ++index)
            {
                var injectionSet = def.TraderKinds[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                for (int index2 = 0; index2 < injectionSet.stockGenerators.Count; ++index2)
                {
                    if (injectionSet.stockGenerators[index2] == null)
                    {
                        errors += string.Format("\n\tstockGenerator {0} in TraderKinds {1} is null", index2, index);
                        isValid = false;
                    }
                }
                if (injectionSet.targetDef.NullOrEmpty())
                {
                    errors += "targetDef is null";
                    isValid = false;
                }
                else
                {
                    var traderKindDef = DefDatabase <TraderKindDef> .GetNamed(injectionSet.targetDef, false);

                    if (traderKindDef == null)
                    {
                        errors += string.Format("Unable to resolve targetDef '{0}' in TraderKinds", injectionSet.targetDef);
                        isValid = false;
                    }
                }
            }

            return(isValid);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        public bool                         Inject(ModHelperDef def)
        {
            if (def.ThingComps.NullOrEmpty())
            {
                return(true);
            }

            foreach (var compSet in def.ThingComps)
            {
                bool processThis = true;
                if (!compSet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(compSet.requiredMod) != null;
                }
                if (processThis)
                {
                    foreach (var targetName in compSet.targetDefs)
                    {
                        // 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
                        var targetDef = DefDatabase <ThingDef> .GetNamed(targetName);

                        if (targetDef.HasComp(compSet.compProps.compClass))
                        {
                            CCL_Log.TraceMod(
                                def,
                                Verbosity.Warnings,
                                string.Format("Trying to inject ThingComp '{0}' into '{1}' when it already exists (another mod may have already injected).", compSet.compProps.compClass.ToString(), targetName),
                                "ThingComp Injector");
                        }
                        else
                        {
                            targetDef.comps.Add(compSet.compProps);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        public bool                         Injected(ModHelperDef def)
        {
            if (def.ThingComps.NullOrEmpty())
            {
                return(true);
            }

            foreach (var compSet in def.ThingComps)
            {
                bool processThis = true;
                if (!compSet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(compSet.requiredMod) != null;
                }
                if (processThis)
                {
                    foreach (var targetName in compSet.targetDefs)
                    {
                        var targetDef = DefDatabase <ThingDef> .GetNamed(targetName, false);

                        if (
                            (compSet.compProps.compClass != null) &&
                            (!targetDef.comps.Exists(s => (s.compClass == compSet.compProps.compClass)))
                            )
                        {
                            return(false);
                        }
                        else if (targetDef.GetCompProperty(compSet.compProps.GetType()) == null)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 17
0
        public bool                         Inject(ModHelperDef def)
        {
            if (def.TraderKinds.NullOrEmpty())
            {
                return(true);
            }

            foreach (var traderKindSet in def.TraderKinds)
            {
                bool processThis = true;
                if (!traderKindSet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(traderKindSet.requiredMod) != null;
                }
                if (processThis)
                {
                    var targetDef = traderKindSet.targetDef;
                    foreach (var stockGenerator in traderKindSet.stockGenerators)
                    {
                        var traderKindDef = DefDatabase <TraderKindDef> .GetNamed(targetDef, false);

                        traderKindDef.stockGenerators.Add(stockGenerator);
                        stockGenerator.PostLoad();
                        stockGenerator.ResolveReferences(traderKindDef);
                        CCL_Log.TraceMod(
                            def,
                            Verbosity.Injections,
                            string.Format("Injecting {0} into {1}", stockGenerator.GetType().Name, traderKindDef.label),
                            "TraderKinds");
                    }
                }
            }

            dictInjected.Add(def, true);
            return(true);
        }
Exemplo n.º 18
0
        public bool                         IsValid(ModHelperDef def, ref string errors)
        {
            if (def.ThingDefAvailability.NullOrEmpty())
            {
                return(true);
            }

            bool isValid = true;

            for (int index = 0; index < def.ThingDefAvailability.Count; ++index)
            {
                var  availabilitySet = def.ThingDefAvailability[index];
                bool processThis     = true;
                if (!availabilitySet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(availabilitySet.requiredMod) != null;
                }
                if (processThis)
                {
                    if (!availabilitySet.menuHidden.NullOrEmpty())
                    {
                        var menuHidden = availabilitySet.menuHidden.ToLower();
                        if (
                            (menuHidden != "true") &&
                            (menuHidden != "false")
                            )
                        {
                            isValid = false;
                            errors += string.Format("\n\tmenuHidden '{0}' is invalid in ThingDefAvailability", availabilitySet.menuHidden);
                        }
                        if (!availabilitySet.designationCategory.NullOrEmpty())
                        {
                            if (availabilitySet.designationCategory != "None")
                            {
                                var category = DefDatabase <DesignationCategoryDef> .GetNamed(availabilitySet.designationCategory, true);

                                if (category == null)
                                {
                                    isValid = false;
                                    errors += string.Format("\n\tDesignationCategory '{0}' is invalid in ThingDefAvailability", availabilitySet.designationCategory);
                                }
                            }
                        }
                        if (availabilitySet.researchPrerequisites != null)
                        {
                            if (availabilitySet.researchPrerequisites.Count > 0)
                            {
                                for (int index2 = 0; index2 < availabilitySet.researchPrerequisites.Count; ++index2)
                                {
                                    var projectDef = DefDatabase <ResearchProjectDef> .GetNamed(availabilitySet.researchPrerequisites[index2], true);

                                    if (projectDef == null)
                                    {
                                        isValid = false;
                                        errors += string.Format("\n\tresearchPrerequisite '{0}' is invalid in ThingDefAvailability", availabilitySet.researchPrerequisites[index2]);
                                    }
                                }
                            }
                        }
                        if (availabilitySet.targetDefs.NullOrEmpty())
                        {
                            errors += "\n\tNull or no targetDefs in ThingDefAvailability";
                            isValid = false;
                        }
                        else
                        {
                            for (int index2 = 0; index2 < availabilitySet.targetDefs.Count; ++index2)
                            {
                                var targetDef = DefDatabase <ThingDef> .GetNamed(availabilitySet.targetDefs[index2], true);

                                if (targetDef == null)
                                {
                                    isValid = false;
                                    errors += string.Format("\n\ttargetDef '{0}' is invalid in ThingDefAvailability", availabilitySet.targetDefs[index2]);
                                }
                            }
                        }
                    }
                }
            }

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

            bool isValid = true;

            for (int index = 0; index < def.ThingDefAvailability.Count; ++index)
            {
                var qualifierValid = true;
                var injectionSet   = def.ThingDefAvailability[index];
                if (
                    (!injectionSet.requiredMod.NullOrEmpty()) &&
                    (Find_Extensions.ModByName(injectionSet.requiredMod) == null)
                    )
                {
                    continue;
                }
                if (!injectionSet.menuHidden.NullOrEmpty())
                {
                    var menuHidden = injectionSet.menuHidden.ToLower();
                    if (
                        (menuHidden != "true") &&
                        (menuHidden != "false")
                        )
                    {
                        isValid = false;
                        errors += string.Format("\n\tmenuHidden '{0}' is invalid in ThingDefAvailability", injectionSet.menuHidden);
                    }
                }
                if (!injectionSet.designationCategory.NullOrEmpty())
                {
                    if (injectionSet.designationCategory != "None")
                    {
                        var category = DefDatabase <DesignationCategoryDef> .GetNamed(injectionSet.designationCategory, true);

                        if (category == null)
                        {
                            isValid = false;
                            errors += string.Format("\n\tDesignationCategory '{0}' is invalid in ThingDefAvailability", injectionSet.designationCategory);
                        }
                    }
                }
                if (injectionSet.researchPrerequisites != null)
                {
                    if (injectionSet.researchPrerequisites.Count > 0)
                    {
                        for (int index2 = 0; index2 < injectionSet.researchPrerequisites.Count; ++index2)
                        {
                            var projectDef = DefDatabase <ResearchProjectDef> .GetNamed(injectionSet.researchPrerequisites[index2], true);

                            if (projectDef == null)
                            {
                                isValid = false;
                                errors += string.Format("\n\tresearchPrerequisite '{0}' is invalid in ThingDefAvailability", injectionSet.researchPrerequisites[index2]);
                            }
                        }
                    }
                }
                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 targetDef = DefDatabase <ThingDef> .GetNamed(injectionSet.targetDefs[index2], true);

                            if (targetDef == null)
                            {
                                isValid = false;
                                errors += string.Format("\n\ttargetDef '{0}' is invalid in ThingDefAvailability", injectionSet.targetDefs[index2]);
                            }
                        }
                    }
                }
                if (injectionSet.qualifier != null)
                {
                    if (!injectionSet.qualifier.IsSubclassOf(typeof(DefInjectionQualifier)))
                    {
                        errors += string.Format("Unable to resolve qualifier '{0}'", injectionSet.qualifier);
                        isValid = false;
                    }
                }
            }

            return(isValid);
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
        public bool                         IsValid(ModHelperDef def, ref string errors)
        {
            if (def.ThingComps.NullOrEmpty())
            {
                return(true);
            }

            bool isValid = true;

            foreach (var compSet in def.ThingComps)
            {
                bool processThis = true;
                if (!compSet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(compSet.requiredMod) != null;
                }
                if (processThis)
                {
                    if (compSet.targetDefs.NullOrEmpty())
                    {
                        errors += "\n\tNull or no targetDefs in ThingComps";
                        isValid = false;
                    }
                    if (compSet.compProps == null)
                    {
                        errors += "\n\tNull compProps in ThingComps";
                        isValid = false;
                    }
                    for (int index = 0; index < compSet.targetDefs.Count; ++index)
                    {
                        if (compSet.targetDefs[index].NullOrEmpty())
                        {
                            errors += string.Format("targetDef in ThingComps is null or empty at index {0}", index.ToString());
                            isValid = false;
                        }
                        else
                        {
                            var target    = compSet.targetDefs[index];
                            var targetDef = DefDatabase <ThingDef> .GetNamed(target, false);

                            if (targetDef == null)
                            {
                                errors += string.Format("Unable to resolve targetDef '{0}' in ThingComps", target);
                                isValid = false;
                            }
                            else
                            {
                                if (compSet.compProps.compClass != null)
                                {
                                    if (targetDef.HasComp(compSet.compProps.compClass))
                                    {
                                        errors += string.Format("targetDef '{0}' in ThingComps already has comp '{1}'", target, compSet.compProps.compClass);
                                        isValid = false;
                                    }
                                }
                                else if (compSet.compProps.GetType() != typeof(CompProperties))
                                {
                                    if (targetDef.GetCompProperty(compSet.compProps.GetType()) != null)
                                    {
                                        errors += string.Format("targetDef '{0}' in ThingComps already has comp '{1}'", target, compSet.compProps);
                                        isValid = false;
                                    }
                                }
                                else
                                {
                                    errors += string.Format("Can not inject CompProperties without a compClass into '{0}'", target);
                                    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);
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
0
        public bool                         IsValid(ModHelperDef def, ref string errors)
        {
            if (def.tickerSwitcher.NullOrEmpty())
            {
                return(true);
            }

            bool isValid = true;

            for (var index = 0; index < def.tickerSwitcher.Count; index++)
            {
                var qualifierValid = true;
                var injectionSet   = def.tickerSwitcher[index];
                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 (qualifierValid)
                {
                    if (!injectionSet.targetDefs.NullOrEmpty())
                    {
                        foreach (var targetName in injectionSet.targetDefs)
                        {
                            var targetDef = DefDatabase <ThingDef> .GetNamed(targetName, false);

                            if (targetDef == null)
                            {
                                errors += string.Format("Unable to resolve targetDef '{0}' in TickerSwitcher", targetName);
                                isValid = false;
                            }
                        }
                    }
                    if (injectionSet.qualifier != null)
                    {
                        if (!injectionSet.qualifier.IsSubclassOf(typeof(DefInjectionQualifier)))
                        {
                            errors += string.Format("Unable to resolve qualifier '{0}'", injectionSet.qualifier);
                            isValid = false;
                        }
                    }
                }
            }

            return(isValid);
        }
Exemplo n.º 26
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  facilitySet = def.Facilities[index];
                bool processThis = true;
                if (!facilitySet.requiredMod.NullOrEmpty())
                {
                    processThis = Find_Extensions.ModByName(facilitySet.requiredMod) != null;
                }
                if (processThis)
                {
                    if (facilitySet.facility.NullOrEmpty())
                    {
                        errors += string.Format("\n\tfacility in Facilities {0} is null", index);
                        isValid = false;
                    }
                    else
                    {
                        var facilityDef = DefDatabase <ThingDef> .GetNamed(facilitySet.facility, false);

                        if (facilityDef == null)
                        {
                            errors += string.Format("Unable to resolve facility '{0}' in Facilities", facilitySet.facility);
                            isValid = false;
                        }
                        else if (facilityDef.GetCompProperties <CompProperties_Facility>() == null)
                        {
                            // Check comps
                            errors += string.Format("'{0}' is missing CompFacility for facility injection", facilitySet.facility);
                            isValid = false;
                        }
                    }
                    for (int index2 = 0; index2 < facilitySet.targetDefs.Count; ++index2)
                    {
                        var target    = facilitySet.targetDefs[index2];
                        var targetDef = DefDatabase <ThingDef> .GetNamed(target, false);

                        if (targetDef == null)
                        {
                            errors += string.Format("Unable to resolve targetDef '{0}' in Facilities", target);
                            isValid = false;
                        }
                        else if (targetDef.GetCompProperties <CompProperties_AffectedByFacilities>() == null)
                        {
                            errors += string.Format("'{0}' is missing CompAffectedByFacilities for facility injection", target);
                            isValid = false;
                        }
                    }
                }
            }

            return(isValid);
        }