public static T GetOrCreate <T>(this ChassisDef target, Func <T> factory) where T : ICustom { var result = target.GetComponent <T>(); if ((result is ExtendedDetails.ExtendedDetails ed) && ed.Def != target.Description) { ed.Def = target.Description; } return(result ?? target.AddComponent(factory.Invoke())); }
private static void AutoFixLocationNaming(ChassisDef chassisDef) { if (chassisDef.Is <ChassisLocationNaming>()) { return; } var template = AutoFixerFeature.settings.MechLocationNamingTemplates .Where(x => x.Tags.Any(chassisDef.ChassisTags.Contains)) .Select(x => x.Template) .FirstOrDefault(); if (template != null) { var copy = template.ReflectionCopy(); chassisDef.AddComponent(copy); } }