diff --git a/Source/Client/Managers/DeepScribeManager.cs b/Source/Client/Managers/DeepScribeManager.cs index 3e75135d..1ba33b49 100644 --- a/Source/Client/Managers/DeepScribeManager.cs +++ b/Source/Client/Managers/DeepScribeManager.cs @@ -1004,6 +1004,7 @@ public static ThingDataFile ItemToString(Thing thing, int thingCount) if (DeepScribeHelper.CheckIfThingIsGenepack(toUse)) GetGenepackDetails(toUse, thingData); else if (DeepScribeHelper.CheckIfThingIsBook(toUse)) GetBookDetails(toUse, thingData); + else if (DeepScribeHelper.CheckIfThingIsXenoGerm(toUse)) GetXenoGermDetails(toUse, thingData); return thingData; } @@ -1025,6 +1026,7 @@ public static Thing StringToItem(ThingDataFile thingData) if (DeepScribeHelper.CheckIfThingIsGenepack(thing)) SetGenepackDetails(thing, thingData); else if (DeepScribeHelper.CheckIfThingIsBook(thing)) SetBookDetails(thing, thingData); + else if (DeepScribeHelper.CheckIfThingIsXenoGerm(thing)) SetXenoGermDetails(thing, thingData); return thing; } @@ -1093,15 +1095,7 @@ private static void GetGenepackDetails(Thing thing, ThingDataFile thingData) try { Genepack genepack = (Genepack)thing; - - Type type = genepack.GetType(); - FieldInfo fieldInfo = type.GetField("geneSet", BindingFlags.NonPublic | BindingFlags.Instance); - GeneSet geneSet = (GeneSet)fieldInfo.GetValue(genepack); - - type = geneSet.GetType(); - fieldInfo = type.GetField("genes", BindingFlags.NonPublic | BindingFlags.Instance); - List geneList = (List)fieldInfo.GetValue(geneSet); - foreach (GeneDef gene in geneList) thingData.GenepackData.genepackDefs.Add(gene.defName); + foreach (GeneDef gene in genepack.GeneSet.GenesListForReading) thingData.GenepackData.genepackDefs.Add(gene.defName); } catch (Exception e) { Logger.Warning(e.ToString()); } } @@ -1147,6 +1141,17 @@ private static void GetBookDetails(Thing thing, ThingDataFile thingData) catch (Exception e) { Logger.Warning(e.ToString()); } } + private static void GetXenoGermDetails(Thing thing, ThingDataFile thingDataFile) + { + try + { + Xenogerm germData = (Xenogerm)thing; + foreach (GeneDef gene in germData.GeneSet.GenesListForReading) thingDataFile.XenoGermData.geneDefs.Add(gene.defName); + thingDataFile.XenoGermData.xenoTypeName = germData.xenotypeName; + thingDataFile.XenoGermData.iconDef = germData.iconDef.defName; + } catch (Exception e ) { Logger.Warning(e.ToString()); } + } + //Setters private static Thing SetItem(ThingDataFile thingData) @@ -1218,22 +1223,13 @@ private static void SetGenepackDetails(Thing thing, ThingDataFile thingData) try { Genepack genepack = (Genepack)thing; - - Type type = genepack.GetType(); - FieldInfo fieldInfo = type.GetField("geneSet", BindingFlags.NonPublic | BindingFlags.Instance); - GeneSet geneSet = (GeneSet)fieldInfo.GetValue(genepack); - - type = geneSet.GetType(); - fieldInfo = type.GetField("genes", BindingFlags.NonPublic | BindingFlags.Instance); - - List geneList = (List)fieldInfo.GetValue(geneSet); - geneList.Clear(); + List geneDefs = new List(); foreach (string str in thingData.GenepackData.genepackDefs) { GeneDef gene = DefDatabase.AllDefs.First(fetch => fetch.defName == str); - geneList.Add(gene); + geneDefs.Add(gene); } - geneSet.GenerateName(); + genepack.Initialize(geneDefs); } catch (Exception e) { Logger.Warning(e.ToString()); } } @@ -1294,6 +1290,25 @@ private static void SetBookDetails(Thing thing, ThingDataFile thingData) } catch (Exception e) { Logger.Warning(e.ToString()); } } + + private static void SetXenoGermDetails(Thing thing, ThingDataFile thingDataFile) + { + try + { + Xenogerm germData = (Xenogerm)thing; + List genePacks = new List(); + foreach (string genepacks in thingDataFile.XenoGermData.geneDefs) + { + Genepack genepack = new Genepack(); + List geneDefs = new List(); + geneDefs.Add(DefDatabase.GetNamed(genepacks)); + genepack.Initialize(geneDefs); + genePacks.Add(genepack); + } + germData.Initialize(genePacks, thingDataFile.XenoGermData.xenoTypeName, DefDatabase.GetNamed(thingDataFile.XenoGermData.iconDef)); + } + catch (Exception e) { Logger.Warning(e.ToString()); } + } } //Class that handles transformation of maps @@ -1770,5 +1785,13 @@ public static bool CheckIfThingIsGenepack(Thing thing) if (thing.def.defName == ThingDefOf.Genepack.defName) return true; else return false; } + + public static bool CheckIfThingIsXenoGerm(Thing thing) + { + if(!ModsConfig.BiotechActive) return false; + + if (thing.def.defName == ThingDefOf.Xenogerm.defName) return true; + else return false; + } } } diff --git a/Source/Shared/Files/Components/Thing/XenoGermData.cs b/Source/Shared/Files/Components/Thing/XenoGermData.cs new file mode 100644 index 00000000..745747fb --- /dev/null +++ b/Source/Shared/Files/Components/Thing/XenoGermData.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Shared +{ + public class XenoGermData + { + public List geneDefs = new List(); + + public string xenoTypeName = ""; + + public string iconDef = ""; + } +} \ No newline at end of file diff --git a/Source/Shared/Files/ThingDataFile.cs b/Source/Shared/Files/ThingDataFile.cs index 75c569e3..3e696573 100644 --- a/Source/Shared/Files/ThingDataFile.cs +++ b/Source/Shared/Files/ThingDataFile.cs @@ -28,6 +28,8 @@ public class ThingDataFile public BookData BookData = new BookData(); + public XenoGermData XenoGermData = new XenoGermData(); + public PlantData PlantData = new PlantData(); } } \ No newline at end of file diff --git a/Source/Shared/Shared.projitems b/Source/Shared/Shared.projitems index 1bb146ae..6830908d 100644 --- a/Source/Shared/Shared.projitems +++ b/Source/Shared/Shared.projitems @@ -10,6 +10,7 @@ +