Table of Contents

Class TimbnPluginSettings

Namespace
Timbn.GraveyardKeeperTwo.Core.Framework
Assembly
Timbn.GraveyardKeeperTwo.Core.dll

Keeps a plugin's changes to the game in step with its config, so a setting changed in a config menu applies straight away instead of on the next start. A setting whose feature is broken, because a game update broke its patches (see TimbnFeatureAttribute), reads as off here whatever its value. Reach it through the plugin's Settings property.

public sealed class TimbnPluginSettings
Inheritance
TimbnPluginSettings
Inherited Members

Methods

Changed<T>(ConfigEntry<T>, Action<T>)

Runs your code whenever a setting's value changes, such as from a config manager or a reloaded config file. The handler is removed when the plugin unloads, and a throw is logged. Prefer Toggle or While when the setting switches a change on and off.

public IDisposable Changed<T>(ConfigEntry<T> entry, Action<T> handler)

Parameters

entry ConfigEntry<T>

The setting.

handler Action<T>

Gets the new value.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Type Parameters

T

Examples

Settings.Changed(PluginConfig.TimeSpeed, speed => Logger.LogInfo($"Meditation time speed is now {speed}"));

IsEnabled(ConfigEntry<bool>)

Whether a toggle is on and its feature is working, which is what Toggle(ConfigEntry<bool>, Action, Action?) and While(ConfigEntry<bool>, Func<IDisposable>) go by. Use it in place of the entry's Value in a patch or a handler that reads the toggle directly. The plugin's static IsEnabled is the master switch instead, the plugin's own Enabled toggle and Core's.

public bool IsEnabled(ConfigEntry<bool> entry)

Parameters

entry ConfigEntry<bool>

The toggle.

Returns

bool

True when the toggle is on and no game update has broken the feature's patches.

Toggle(ConfigEntry<bool>, Action, Action?)

Ties a toggle to the change it makes. While the toggle is on, apply runs on every save load and as soon as the toggle turns on during play. Revert runs as soon as the toggle turns off and when the plugin unloads. Both run straight away if a save is already loaded. At the main menu, revert only runs for a change that was applied.

public IDisposable Toggle(ConfigEntry<bool> entry, Action apply, Action? revert = null)

Parameters

entry ConfigEntry<bool>

The toggle.

apply Action

Makes the change. It can run more than once, so it must skip work already done.

revert Action

Undoes the change. It can run when nothing was applied, so it must cope with that. Leave it out for a fix that runs once per save and has nothing to undo.

Returns

IDisposable

A handle that stops following the toggle and reverts when disposed. You don't need to keep it.

Examples

Settings.Toggle(PluginConfig.StuckCarriers, stuckCarriers.Reset, stuckCarriers.Revert);
Settings.Toggle(PluginConfig.StuckResourceWorkers, Repair);

Toggle<T>(ConfigEntry<T>, Func<T, bool>, Action, Action?)

Ties a setting of any type to the change it makes, like Toggle(ConfigEntry<bool>, Action, Action?) with isOn deciding which values count as on. Any change to the value reverts first and then applies again if the new value is on, so apply can read the new value.

public IDisposable Toggle<T>(ConfigEntry<T> entry, Func<T, bool> isOn, Action apply, Action? revert = null)

Parameters

entry ConfigEntry<T>

The setting.

isOn Func<T, bool>

Whether a value of the setting turns the change on.

apply Action

Makes the change. It can run more than once, so it must skip work already done.

revert Action

Undoes the change. It can run when nothing was applied, so it must cope with that. Can be null.

Returns

IDisposable

A handle that stops following the setting and reverts when disposed. You don't need to keep it.

Type Parameters

T

Examples

Settings.Toggle(PluginConfig.TechPointCap, cap => cap > 999, _techPointCap.Apply, _techPointCap.Revert);

While(ConfigEntry<bool>, Func<IDisposable>)

Keeps a registration alive only while a toggle is on. Subscribe runs straight away if the toggle is on and again each time it turns on, and what it returns is disposed as soon as the toggle turns off. It suits any Core registration, such as a timer, an event handler, or a balance edit, so a tweak that is switched off costs nothing and its handlers need no check of the setting.

public IDisposable While(ConfigEntry<bool> entry, Func<IDisposable> subscribe)

Parameters

entry ConfigEntry<bool>

The toggle.

subscribe Func<IDisposable>

Makes the registration and returns its handle.

Returns

IDisposable

A handle that stops following the toggle and disposes the registration when disposed. You don't need to keep it.

Examples

Settings.While(PluginConfig.StuckCarriers, () => Events.EveryRealSeconds(0.5f, stuckCarriers.Tick));

While<T>(ConfigEntry<T>, Func<T, bool>, Func<IDisposable>)

Keeps a registration alive only while a setting of any type is on, like While(ConfigEntry<bool>, Func<IDisposable>) with isOn deciding which values count as on. Any change to the value disposes the registration and makes it again if the new value is on, so subscribe can read the new value.

public IDisposable While<T>(ConfigEntry<T> entry, Func<T, bool> isOn, Func<IDisposable> subscribe)

Parameters

entry ConfigEntry<T>

The setting.

isOn Func<T, bool>

Whether a value of the setting keeps the registration alive.

subscribe Func<IDisposable>

Makes the registration and returns its handle.

Returns

IDisposable

A handle that stops following the setting and disposes the registration when disposed. You don't need to keep it.

Type Parameters

T

Examples

Settings.While(PluginConfig.TechPointCap, cap => cap > 999, () => Balance.Edit<GameResSystemDef>("tech_red", Raise, Lower));