I have this FactionDef which I would like to edit ingame. I have created a settings menu with HugsLib with a simple bool toggle, and if it's checked, the FactionDef's techLevel should be set to spacer, else industrial. The current defauls is industrial, and this is how I've tried to solve it:
This is my factiondef
And this is my HugsLib C# settings menu:
This is my first mod, so it's probably something obvious. But this sometimes work, and sometimes it doesn't. What have I done wrong?
Edit: nvm I think it's working, but my tech level isn't modifying my research speed?
This is my factiondef
Code Select
<Defs>
<FactionDef ParentName="PlayerFactionBase">
<defName>EarlySpacerColonists</defName>
<label>Early Spacer Colonists</label>
<description>A colony of recently-arrived spacer colonists.</description>
<isPlayer>true</isPlayer>
<techLevel>Industrial</techLevel>
<!-- And a bunch of other settings -->
</FactionDef>
</Defs>
And this is my HugsLib C# settings menu:
Code Select
private SettingHandle<bool> shouldHaveSpacerTechLevel;
public override void DefsLoaded()
{
if (ModIsActive)
{
shouldHaveSpacerTechLevel = Settings.GetHandle(
"shouldHaveSpacerTechLevel",
"shouldHaveSpacerTechLevel_title".Translate(),
"shouldHaveSpacerTechLevel_desc".Translate(),
false
);
ApplySettings();
}
}
public override void SettingsChanged()
{
ApplySettings();
base.SettingsChanged();
}
public void ApplySettings()
{
if (shouldHaveSpacerTechLevel)
{
DefDatabase<FactionDef>.GetNamed("EarlySpacerColonists").techLevel = TechLevel.Spacer;
Logger.Message("Set the default techlevel to Spacer");
}
else
{
DefDatabase<FactionDef>.GetNamed("EarlySpacerColonists").techLevel = TechLevel.Industrial;
Logger.Message("Set the default techlevel to Industrial");
}
}
This is my first mod, so it's probably something obvious. But this sometimes work, and sometimes it doesn't. What have I done wrong?
Edit: nvm I think it's working, but my tech level isn't modifying my research speed?