Skip to content

Commit

Permalink
Merge pull request #171 from Erag0n001/Xenogerm-patch
Browse files Browse the repository at this point in the history
Added compatibility with XenoGerms
  • Loading branch information
Byte-Nova authored Oct 5, 2024
2 parents 8a69f89 + 57f5a4b commit 2deda34
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 21 deletions.
65 changes: 44 additions & 21 deletions Source/Client/Managers/DeepScribeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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<GeneDef> geneList = (List<GeneDef>)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()); }
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<GeneDef> geneList = (List<GeneDef>)fieldInfo.GetValue(geneSet);
geneList.Clear();
List<GeneDef> geneDefs = new List<GeneDef>();
foreach (string str in thingData.GenepackData.genepackDefs)
{
GeneDef gene = DefDatabase<GeneDef>.AllDefs.First(fetch => fetch.defName == str);
geneList.Add(gene);
geneDefs.Add(gene);
}
geneSet.GenerateName();
genepack.Initialize(geneDefs);
}
catch (Exception e) { Logger.Warning(e.ToString()); }
}
Expand Down Expand Up @@ -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<Genepack> genePacks = new List<Genepack>();
foreach (string genepacks in thingDataFile.XenoGermData.geneDefs)
{
Genepack genepack = new Genepack();
List<GeneDef> geneDefs = new List<GeneDef>();
geneDefs.Add(DefDatabase<GeneDef>.GetNamed(genepacks));
genepack.Initialize(geneDefs);
genePacks.Add(genepack);
}
germData.Initialize(genePacks, thingDataFile.XenoGermData.xenoTypeName, DefDatabase<XenotypeIconDef>.GetNamed(thingDataFile.XenoGermData.iconDef));
}
catch (Exception e) { Logger.Warning(e.ToString()); }
}
}

//Class that handles transformation of maps
Expand Down Expand Up @@ -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;
}
}
}
13 changes: 13 additions & 0 deletions Source/Shared/Files/Components/Thing/XenoGermData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace Shared
{
public class XenoGermData
{
public List<string> geneDefs = new List<string>();

public string xenoTypeName = "";

public string iconDef = "";
}
}
2 changes: 2 additions & 0 deletions Source/Shared/Files/ThingDataFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class ThingDataFile

public BookData BookData = new BookData();

public XenoGermData XenoGermData = new XenoGermData();

public PlantData PlantData = new PlantData();
}
}
1 change: 1 addition & 0 deletions Source/Shared/Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Files\ActionValuesFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Files\Components\Thing\XenoGermData.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Files\DifficultyValuesFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Files\SettlementFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Files\RoadValuesFile.cs" />
Expand Down

0 comments on commit 2deda34

Please sign in to comment.