RacesOfValheim/JotunnModStub/TrolsHammer/TrolsHammerConfig.cs
2026-08-13 19:13:24 +02:00

50 lines
2.5 KiB
C#

using BepInEx.Configuration;
namespace RacesOfValheim
{
/// <summary>
/// The two numbers behind Trol's Hammer, bound as BepInEx ConfigEntry so they can be dragged in
/// Configuration Manager rather than recompiled - the same shape as WarVultureConfig.
///
/// Note what the switch does NOT do: turning the hammer off never un-scales anything already
/// standing. A piece carries its own size on its ZDO, and that is read back on load whatever
/// the config says, so a house built at 1.2 stays a house and not a pile of clipping walls.
/// The switch only decides whether NEW placements are enlarged.
/// </summary>
public static class TrolsHammerConfig
{
public static ConfigEntry<bool> Enabled;
public static ConfigEntry<float> ScaleFactor;
public static void Bind(ConfigFile config)
{
// No apostrophe, and not a typo: BepInEx rejects ' in a section name outright, and this
// Bind runs from the plugin's Awake - so "Trol's Hammer" did not merely fail to appear
// in Configuration Manager, it threw and took the whole mod's startup with it.
const string section = "Trols Hammer";
Enabled = config.Bind(section, "Enabled", true,
new ConfigDescription("Whether pieces placed with Trol's Hammer come out enlarged. " +
"Switching this off leaves every piece already built at the size " +
"it was built at; only new placements are affected."));
ScaleFactor = config.Bind(section, "Scale factor", 1.2f,
new ConfigDescription("How much bigger than the vanilla piece. 1.2 is the +20% the " +
"hammer exists for. Cost and drop never change - this is size " +
"only.", new AcceptableValueRange<float>(1f, 3f)));
}
/// <summary>
/// The multiplier a new placement should use, or 1 when the hammer is switched off. Clamped
/// against a zero or negative value typed straight into the .cfg file, which the
/// Configuration Manager slider cannot produce but a text editor can - and a piece scaled to
/// zero is a piece that cannot be seen, hit or removed.
/// </summary>
public static float ActiveFactor()
{
if (Enabled == null || ScaleFactor == null) return 1f;
if (!Enabled.Value) return 1f;
return ScaleFactor.Value > 0.01f ? ScaleFactor.Value : 1f;
}
}
}