IModWorldSettings
The root of a mod's world settings. No tab level; categories sit directly here.
public interface IModWorldSettingsThe root of a mod's world settings. There is no tab level; categories sit directly here. Handed to IGearsModApi.OnWorldSettingsLoaded; also IGearsMod.WorldSettings.
Methods
GetCategory(String)
IWorldModSettingsCategory GetCategory(string categoryName);Returns the IWorldModSettingsCategory named categoryName, or null.
CreateCategory(String, String)
IWorldModSettingsCategory CreateCategory(string categoryName, string displayName);Creates a category with the given name and display key. Throws ArgumentException on a duplicate name.
GetOrCreateCategory(String, String)
IWorldModSettingsCategory GetOrCreateCategory(string categoryName, string displayName);Returns the existing category, or creates it.
AddCategory(IWorldModSettingsCategory)
bool AddCategory(IWorldModSettingsCategory category);Adds an existing category object. Returns false if the name is taken.
RemoveCategory(String)
bool RemoveCategory(string categoryName);Removes the category with that name. Returns whether one was removed.
RemoveCategory(IWorldModSettingsCategory)
bool RemoveCategory(IWorldModSettingsCategory category);Removes that category. Returns whether it was removed.
GetAllCategories()
List<IWorldModSettingsCategory> GetAllCategories();Returns every category as a List<IWorldModSettingsCategory>.
GetAllWorldSettings()
List<IWorldModSetting> GetAllWorldSettings();Returns every setting in every category, categories included, as a List<IWorldModSetting>.
BindSettingsClass(Type)
void BindSettingsClass(Type settingsType);Binds a settings class. A type is bound once; later calls for it do nothing.
Scans settingsType for tagged static members carrying a "Category.Setting" path. Fields and properties tagged SettingAttribute are assigned the named setting first, then methods tagged SettingOnSelectedChangedAttribute or SettingOnEnabledAttribute are subscribed.
A world setting raises no OnValueChanged, because its applied value arrives with the world rather than changing under the player. A method tagged SettingOnValueChangedAttribute is therefore bound invoke-only: it is never raised, and runs only when SyncSettingsToClass calls it — which means it must be written with includeInSync: true, or it can never run at all. SettingOnAppliedAttribute has no such fallback and is logged and skipped.
Call this from IGearsModApi.InitMod. ModSettings.xml is read before that callback, so every setting exists by then, and it runs exactly once - whereas OnWorldSettingsLoaded fires again on every world load and rejoin. Binding is a one-time wiring job; use SyncSettingsToClass in the callback for the part that repeats.
This binds and nothing else. No listener is called, whether or not it asked for IncludeInSync. Calling this again with a type already bound does nothing at all, so binding from OnWorldSettingsLoaded instead is safe - just harder to follow.
Throws ArgumentNullException for null.
SyncSettingsToClass(Type)
void SyncSettingsToClass(Type settingsType);Calls the opted-in value listeners on an already-bound class with the values their settings hold now.
Calls every method on settingsType tagged SettingOnValueChangedAttribute or SettingOnSelectedChangedAttribute with includeInSync: true, handing each the value its setting holds at that moment, exactly as if the event had fired. Nothing is bound or subscribed, so this is safe to call as often as you like.
This is how a mod picks up a new world's values, and it is the only thing that calls a listener with a value no event delivered. BindSettingsClass deliberately calls nothing, so pairing the two runs each listener exactly once per world load. Gears applies a world's values before it fires OnWorldSettingsLoaded, so calling this from that callback hands every listener the current world's values, on the first load and on every load after it.
A listener without IncludeInSync is skipped — it runs only when its event fires. Throws ArgumentNullException for null, and logs a type that has never been bound rather than doing anything.
When OnWorldSettingsLoaded returns, Gears warns about every bound class that has an includeInSync listener and was not passed to this method during that callback. The check runs on every world load, so a load that skips the sync is reported even when an earlier one did it. A class with no includeInSync listener is never reported.
SaveSettings()
void SaveSettings();Writes the player-level saved settings file. World values themselves are written to the save folder by the world settings screen and on world start, not by this call.