public static Dictionary <string, DefInfo> CollectDefInfos() { var dict = new Dictionary <string, DefInfo>(); int TypeHash(Type type) => GenText.StableStringHash(type.FullName); dict["ThingComp"] = GetDefInfo(Sync.thingCompTypes, TypeHash); dict["Designator"] = GetDefInfo(Sync.designatorTypes, TypeHash); dict["WorldObjectComp"] = GetDefInfo(Sync.worldObjectCompTypes, TypeHash); dict["IStoreSettingsParent"] = GetDefInfo(Sync.storageParents, TypeHash); dict["IPlantToGrowSettable"] = GetDefInfo(Sync.plantToGrowSettables, TypeHash); foreach (var defType in GenTypes.AllLeafSubclasses(typeof(Def))) { if (defType.Assembly != typeof(Game).Assembly) { continue; } if (IgnoredVanillaDefTypes.Contains(defType)) { continue; } var defs = GenDefDatabase.GetAllDefsInDatabaseForDef(defType); dict.Add(defType.Name, GetDefInfo(defs, d => GenText.StableStringHash(d.defName))); } return(dict); }
private static void FixIndices() // this method fixes Tynan's bug with index assigning where modded defs derived from vanilla would get repeating indices // thus breaking some logic, i.e terrain wealth calculation was broken when adding mods with modded terrain def types { Dictionary <Type, HashSet <int> > idsByDefTypes = new Dictionary <Type, HashSet <int> >(); foreach (Type item in typeof(Def).AllSubclasses()) { if (item != typeof(BuildableDef)) { var defsList = GenDefDatabase.GetAllDefsInDatabaseForDef(item).ToList(); foreach (var def in defsList) { if (!idsByDefTypes.TryGetValue(item, out var list)) { idsByDefTypes[item] = list = new HashSet <int>(); } if (list.Contains(def.index)) { def.index = (ushort)(list.Max() + 1); } if (!list.Add(def.index)) { Log.Error("Failed to assign non duplicate index to " + def + " - " + def.index); } } } } }
private static void ChangeDefLabels() { // Go through every appropriate def that has a label var changeableDefTypes = GenDefDatabase.AllDefTypesWithDatabases().Where(t => ShouldChangeDefTypeLabel(t)).ToList(); for (int i = 0; i < changeableDefTypes.Count; i++) { var curDefs = GenDefDatabase.GetAllDefsInDatabaseForDef(changeableDefTypes[i]).ToList(); for (int j = 0; j < curDefs.Count; j++) { var curDef = curDefs[j]; if (!curDef.label.NullOrEmpty()) { // Update the def's label AdjustLabel(ref curDef.label); // If the def is a ThingDef... if (curDef is ThingDef tDef) { // If the ThingDef is a stuff item if (tDef.stuffProps is StuffProperties stuffProps) { // Update the stuff adjective if there is one if (!stuffProps.stuffAdjective.NullOrEmpty()) { AdjustLabel(ref stuffProps.stuffAdjective); } } } } } } }
public static void EntryAction() { Log.Message( GenDefDatabase.GetAllDefsInDatabaseForDef(typeof(TerrainDef)) .Select(def => $"{def.modContentPack?.Name} {def} {def.shortHash} {def.index}") .Join(delimiter: "\n") ); }
public virtual IEnumerable <T> Options() { if (typeof(T).IsEnum) { return(Enum.GetValues(typeof(T)).OfType <T>()); } if (typeof(Def).IsAssignableFrom(typeof(T))) { return(GenDefDatabase.GetAllDefsInDatabaseForDef(typeof(T)).Cast <T>()); } throw new NotImplementedException(); }
public static void DumpDefTypes() { foreach (var defType in GenTypes.AllLeafSubclasses(typeof(Def))) { if (defType.Assembly != typeof(Game).Assembly) { continue; } if (Multiplayer.IgnoredVanillaDefTypes.Contains(defType)) { continue; } Log.Warning($"== {defType.Name} =="); Log.Message( GenDefDatabase.GetAllDefsInDatabaseForDef(defType) .Select(def => $"{def.defName}") .Join(delimiter: "\n") ); } }