using System; using System.Collections.Generic; using System.Linq; using Verse; using RimWorld; namespace Rimworld_Animations_Patch { public static class ApparelSettingsUtility { private static Dictionary cachedApparelTextures = new Dictionary(); public static ApparelTexture2DPack GetCachedApparelTextures(Graphic graphic, BodyTypeDef bodyType) { if (ApparelSettings.cropApparel == false) return null; if (graphic?.path == null) return null; if (cachedApparelTextures.TryGetValue(graphic.path, out ApparelTexture2DPack pack) == false) { pack = new ApparelTexture2DPack(); pack.PackTexturesForBodyType(graphic, bodyType); cachedApparelTextures.Add(graphic.path, pack); DebugMode.Message("Cropped textures have been cached for " + graphic.path); } return pack; } public static void ClearCachedApparelTextures() { cachedApparelTextures.Clear(); } public static bool IsApparelOfInterest(ThingDef thingDef) { if (thingDef.IsApparel == false) return false; return thingDef.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso) || thingDef.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs) || thingDef.apparel.bodyPartGroups.Contains(PatchBodyPartGroupDefOf.GenitalsBPG) || thingDef.apparel.bodyPartGroups.Contains(PatchBodyPartGroupDefOf.ChestBPG); } public static List GetApparelOfInterest() { List thingDefs = new List(); foreach (ThingDef thingDef in DefDatabase.AllDefs) { if (IsApparelOfInterest(thingDef)) { thingDefs.Add(thingDef); } } return thingDefs; } // Get data public static RimNudeData GetRimNudeData(ThingDef thingDef) { if (ApparelSettings.rimNudeData.NullOrEmpty()) ResetRimNudeData(); if (IsApparelOfInterest(thingDef) == false) return null; foreach (RimNudeData rimNudeData in ApparelSettings.rimNudeData) { if (rimNudeData.EquivalentTo(new RimNudeData(thingDef))) { return rimNudeData; } } var newRimNudeData = GetApparelDefault(thingDef); if (newRimNudeData == null) newRimNudeData = new RimNudeData(thingDef); ApparelSettings.rimNudeData.Add(newRimNudeData); return newRimNudeData; } public static RimNudeData GetRimNudeData(Apparel apparel) { return GetRimNudeData(apparel.def); } // Reset all data public static void ResetRimNudeData() { ApparelSettings.rimNudeData = new List(); foreach (ThingDef thingDef in GetApparelOfInterest()) { var newRimNudeData = GetApparelDefault(thingDef); if (newRimNudeData == null) newRimNudeData = new RimNudeData(thingDef); ApparelSettings.rimNudeData.Add(newRimNudeData); } } // Reset some data public static void ResetRimNudeData(List thingDefs) { if (ApparelSettings.rimNudeData.NullOrEmpty()) ResetRimNudeData(); foreach (ThingDef thingDef in thingDefs) { var newRimNudeData = GetApparelDefault(thingDef); if (newRimNudeData == null) newRimNudeData = new RimNudeData(thingDef); RimNudeData rimNudeData = ApparelSettings.rimNudeData.FirstOrDefault(x => x.EquivalentTo(new RimNudeData(thingDef))); rimNudeData.coversGroin = newRimNudeData.coversGroin; rimNudeData.coversBelly = newRimNudeData.coversBelly; rimNudeData.coversChest = newRimNudeData.coversChest; rimNudeData.sexWear = newRimNudeData.sexWear; } } public static void SetAllCoversGroin(List thingDefs, bool value) { foreach (ThingDef thingDef in thingDefs) { RimNudeData rimNudeApparel = ApparelSettings.rimNudeData.First(x => x.EquivalentTo(new RimNudeData(thingDef))); rimNudeApparel.coversGroin = value; } } public static void SetAllCoversBelly(List thingDefs, bool value) { foreach (ThingDef thingDef in thingDefs) { RimNudeData rimNudeApparel = ApparelSettings.rimNudeData.First(x => x.EquivalentTo(new RimNudeData(thingDef))); rimNudeApparel.coversBelly = value; } } public static void SetAllCoversChest(List thingDefs, bool value) { foreach (ThingDef thingDef in thingDefs) { RimNudeData rimNudeApparel = ApparelSettings.rimNudeData.First(x => x.EquivalentTo(new RimNudeData(thingDef))); rimNudeApparel.coversChest = value; } } public static void SetAllSexWear(List thingDefs, bool value) { foreach (ThingDef thingDef in thingDefs) { RimNudeData rimNudeApparel = ApparelSettings.rimNudeData.First(x => x.EquivalentTo(new RimNudeData(thingDef))); rimNudeApparel.sexWear = value; } } public static RimNudeData GetApparelDefault(ThingDef thingDef) { foreach(RimNudeData rimNudeData in apparelDefaults) { if (rimNudeData.thingDef == thingDef.defName) { return rimNudeData; } } return null; } public static List apparelDefaults = new List() { new RimNudeData("Apparel_BasicShirt", coversGroin: false, coversBelly: true, coversChest: true, sexWear: false), new RimNudeData("Apparel_CollarShirt", coversGroin: false, coversBelly: true, coversChest: true, sexWear: false), new RimNudeData("Apparel_FlakVest", coversGroin: false, coversBelly: false, coversChest: false, sexWear: false), new RimNudeData("Apparel_Duster", coversGroin: false, coversBelly: false, coversChest: true, sexWear: false), new RimNudeData("Apparel_Jacket", coversGroin: false, coversBelly: false, coversChest: true, sexWear: false), new RimNudeData("Apparel_TribalA", coversGroin: true, coversBelly: true, coversChest: true, sexWear: false), new RimNudeData("Apparel_BodyStrap", coversGroin: false, coversBelly: false, coversChest: false, sexWear: true), new RimNudeData("Apparel_PsyfocusRobe", coversGroin: false, coversBelly: false, coversChest: true, sexWear: false), new RimNudeData("Apparel_Cape", coversGroin: false, coversBelly: false, coversChest: false, sexWear: false), new RimNudeData("Apparel_RobeRoyal", coversGroin: false, coversBelly: false, coversChest: true, sexWear: false), new RimNudeData("Apparel_Corset", coversGroin: false, coversBelly: true, coversChest: true, sexWear: false), new RimNudeData("Apparel_Bandolier", coversGroin: false, coversBelly: false, coversChest: false, sexWear: false), new RimNudeData("Apparel_Sash", coversGroin: false, coversBelly: false, coversChest: false, sexWear: false), new RimNudeData("Apparel_HeavyShield", coversGroin: false, coversBelly: false, coversChest: false, sexWear: false), new RimNudeData("VAE_Apparel_Overalls", coversGroin: true, coversBelly: true, coversChest: false, sexWear: false), new RimNudeData("VAE_Apparel_LabCoat", coversGroin: false, coversBelly: false, coversChest: true, sexWear: false), new RimNudeData("VAE_Apparel_BuildersJacket", coversGroin: false, coversBelly: false, coversChest: true, sexWear: false), new RimNudeData("VAE_Apparel_Apron", coversGroin: true, coversBelly: true, coversChest: false, sexWear: false), new RimNudeData("VAE_Apparel_Tunic", coversGroin: false, coversBelly: true, coversChest: true, sexWear: false), new RimNudeData("VAE_Apparel_PeltCoat", coversGroin: false, coversBelly: false, coversChest: true, sexWear: false), new RimNudeData("VAE_Apparel_WoodenArmor", coversGroin: false, coversBelly: true, coversChest: false, sexWear: false), new RimNudeData("VAE_Apparel_AdvancedVest", coversGroin: false, coversBelly: false, coversChest: false, sexWear: false), new RimNudeData("VAE_Apparel_BulletproofVest", coversGroin: false, coversBelly: true, coversChest: false, sexWear: false), new RimNudeData("VWE_Apparel_Exoframe", coversGroin: false, coversBelly: false, coversChest: false, sexWear: false), new RimNudeData("VFEM_Apparel_Tabard", coversGroin: true, coversBelly: true, coversChest: true, sexWear: false), new RimNudeData("VFEV_Apparel_JarlCape", coversGroin: false, coversBelly: false, coversChest: true, sexWear: false), new RimNudeData("VFEV_Apparel_RoyalFurCoat", coversGroin: false, coversBelly: false, coversChest: true, sexWear: false), new RimNudeData("PrisonerChains", coversGroin: false, coversBelly: false, coversChest: false, sexWear: true), new RimNudeData("S16_ChainHarnessA", coversGroin: false, coversBelly: false, coversChest: false, sexWear: true), new RimNudeData("S16_NippleWristCuffs", coversGroin: false, coversBelly: false, coversChest: false, sexWear: true), new RimNudeData("S16_ServantGirlDress", coversGroin: true, coversBelly: true, coversChest: false, sexWear: true), new RimNudeData("S16_ZDress", coversGroin: false, coversBelly: true, coversChest: true, sexWear: true), new RimNudeData("S16_MaidA", coversGroin: false, coversBelly: true, coversChest: false, sexWear: true), new RimNudeData("S16_DiscoTop", coversGroin: false, coversBelly: false, coversChest: true, sexWear: true), new RimNudeData("S16_TransparentSkirt", coversGroin: false, coversBelly: false, coversChest: false, sexWear: true), new RimNudeData("S16_Vibrator", coversGroin: false, coversBelly: false, coversChest: false, sexWear: true), new RimNudeData("S16_VibratorDouble", coversGroin: false, coversBelly: false, coversChest: false, sexWear: true), new RimNudeData("S16_WiredVibrator", coversGroin: false, coversBelly: false, coversChest: false, sexWear: true), new RimNudeData("S16_DoubleWiredVibrator", coversGroin: false, coversBelly: false, coversChest: false, sexWear: true), new RimNudeData("S16_WiredAnalVibrator", coversGroin: false, coversBelly: false, coversChest: false, sexWear: true), }; } }