Gene Templates - SmArtKar/AthenaFramework GitHub Wiki
To simplify creation of procedurally generated genes for C# users (and to avoid patching the generator in every single mod) Athena adds easy to use gene templates.
First, you need a generator handler which will be responsible for creating the genes themselves. GenerateDefs
should simply return created objects. In order to simplify gene creation, CreateDef
can be used to create a gene from a template def.
public abstract class GeneGenerationHandler
{
public abstract IEnumerable<GeneDef> GenerateDefs(AthenaGeneTemplateDef template);
public virtual GeneDef CreateDef(AthenaGeneTemplateDef template, Def def, int displayOrder, string iconPath)
{
GeneDef geneDef = new GeneDef
{
defName = template.defName + "_" + def.defName,
geneClass = template.geneClass,
label = template.label.Formatted(def.label),
iconPath = iconPath,
description = template.description.Formatted(def.label),
labelShortAdj = template.labelShortAdj.Formatted(def.label),
selectionWeight = template.selectionWeight,
biostatCpx = template.biostatCpx,
biostatMet = template.biostatMet,
biostatArc = template.biostatArc,
displayCategory = template.displayCategory,
displayOrderInCategory = displayOrder + template.displayOrderOffset,
minAgeActive = template.minAgeActive,
modContentPack = template.modContentPack
};
if (!template.exclusionTagPrefix.NullOrEmpty())
{
geneDef.exclusionTags = new List<string> { template.exclusionTagPrefix + "_" + def.defName };
}
return geneDef;
}
}
Afterwards, simply create a template def and specify your handler in it
public class AthenaGeneTemplateDef : Def
{
public Type geneClass = typeof(Gene);
public Type geneHandler;
public int biostatCpx;
public int biostatMet;
public int biostatArc;
public float minAgeActive;
public GeneCategoryDef displayCategory;
public int displayOrderOffset;
public float selectionWeight = 1f;
[MustTranslate]
public string labelShortAdj;
[NoTranslate]
public string iconPath;
[NoTranslate]
public string exclusionTagPrefix;
}