예제 #1
0
        public bool                         IsValid()
        {
            if (!isValidChecked)
            {
                // Hopefully...
                isValid = true;

                var ModContentPack = Find_Extensions.ModByDefOfType <AdvancedResearchDef>(defName);
                modHelperDef = Find_Extensions.ModHelperDefForMod(ModContentPack);

                if (
                    (modHelperDef == null) ||
                    (modHelperDef.dummy)
                    )
                {
                    // Missing ModHelperDef (not dummyable)
                    isValid = false;
                    CCL_Log.TraceMod(
                        this,
                        Verbosity.FatalErrors,
                        "Requires ModHelperDef"
                        );
                }

#if DEBUG
                // Validate research
                if (researchDefs.NullOrEmpty())
                {
                    // Invalid project
                    isValid = false;
                    CCL_Log.TraceMod(
                        this,
                        Verbosity.FatalErrors,
                        "Missing researchDefs"
                        );
                }

                // Validate recipes
                if (IsRecipeToggle)
                {
                    // v0.12.7 - Obsoleted check to allow for automated machines
                    // Make sure thingDefs are of the appropriate type (has ITab_Bills)

                    /*
                     * foreach( var thingDef in thingDefs )
                     * {
                     *  if( thingDef.thingClass.GetInterface( "IBillGiver" ) == null )
                     *  {
                     *      // Invalid project
                     *      isValid = false;
                     *      CCL_Log.AppendTrace(
                     *          ref stringBuilder,
                     *          this,
                     *          Verbosity.FatalErrors,
                     *          "ThingDef '" + thingDef.defName + "' does not implement IBillGiver"
                     *      );
                     *  }
                     * }
                     */
                }

                // Validate plant sowTags
                if (IsPlantToggle)
                {
                    // Make sure things are of the appropriate class (Plant)
                    foreach (var thingDef in thingDefs)
                    {
                        if (
                            (thingDef.thingClass != typeof(Plant)) &&
                            (!thingDef.thingClass.IsSubclassOf(typeof(Plant)))
                            )
                        {
                            // Invalid plant
                            isValid = false;
                            CCL_Log.TraceMod(
                                this,
                                Verbosity.FatalErrors,
                                "ThingDef '" + thingDef.defName + "' ThingClass is not Plant based"
                                );
                        }
                    }

                    // Make sure sowTags are valid (!null or empty)
                    for (int i = 0; i < sowTags.Count; i++)
                    {
                        var sowTag = sowTags[i];
                        if (sowTag.NullOrEmpty())
                        {
                            isValid = false;
                            CCL_Log.TraceMod(
                                this,
                                Verbosity.FatalErrors,
                                "sowTag at index'" + i + "' is null or empty"
                                );
                        }
                    }
                }

                // Validate buildings
                if (IsBuildingToggle)
                {
                    // Make sure thingDefs are of the appropriate type (has proper designationCategory)
                    foreach (var thingDef in thingDefs)
                    {
                        if ((thingDef.designationCategory.NullOrEmpty()) ||
                            (thingDef.designationCategory.ToLower() == "none"))
                        {
                            bool mhdUnlock = false;
                            foreach (var mhd in DefDatabase <ModHelperDef> .AllDefs)
                            {
                                if (mhd.ThingDefAvailability != null)
                                {
                                    foreach (var tda in mhd.ThingDefAvailability)
                                    {
                                        if (
                                            (tda.targetDefs.Contains(thingDef.defName)) &&
                                            (!tda.designationCategory.NullOrEmpty()) &&
                                            (tda.designationCategory.ToLower() != "none")
                                            )
                                        {
                                            mhdUnlock = true;
                                            break;
                                        }
                                    }
                                }
                                if (mhdUnlock == true)
                                {
                                    break;
                                }
                            }
                            if (!mhdUnlock)
                            {
                                // Invalid project
                                isValid = false;
                                CCL_Log.TraceMod(
                                    this,
                                    Verbosity.FatalErrors,
                                    "ThingDef '" + thingDef.defName + "' :: designationCategory is null or empty"
                                    );
                            }
                        }
                    }
                }

                // Validate help
                if (researchDefs.Count > 1)
                {
                    if (ResearchConsolidator == null)
                    {
                        // Error processing data
                        isValid = false;
                        CCL_Log.TraceMod(
                            this,
                            Verbosity.FatalErrors,
                            string.Format("No valid help consolidator for AdvancedResearchDef {0}", defName)
                            );
                    }
                    if ((HasHelp) &&
                        (ResearchConsolidator == this))
                    {
                        if (label.NullOrEmpty())
                        {
                            // Error processing data
                            isValid = false;
                            CCL_Log.TraceMod(
                                this,
                                Verbosity.FatalErrors,
                                "Help Consolidator requires missing label"
                                );
                        }
                        if (description.NullOrEmpty())
                        {
                            // Error processing data
                            isValid = false;
                            CCL_Log.TraceMod(
                                this,
                                Verbosity.FatalErrors,
                                "Help Consolidator requires missing description"
                                );
                        }
                    }
                }
#endif
            }
            return(isValid);
        }