#
Custom Keybinds and Settings
PolyModLoader has a few built in functions to make it easier for mod makers to add their own settings and keybinds to the base game.
NOTE: all these calls are positional, meaning the way it looks depends on the order they are called.
#
Custom Settings
Adding your own settings is fairly easy: First, add your own category
pml.registerSettingCategory("<category name>");
Then, you can register settings in one simple function:
pml.registerSetting("<name>", "<unique id>", SettingType.<type>, <default value>, optionalArgs);
- Please note you will have to import
SettingTypefromPolyModLoader.js.
#
Types of settings:
BOOL: A simple true/false (on/off) ex: anti aliasing toggleSLIDER: A slider between 0 and 1, do math accordingly for the values you want. ex: sound stuffCUSTOM: a setting with as many options as you want. ex: language setting, render scale ForCUSTOM, you are going to need some optional options. Those come in this format:
[ // This is what you would put in optionalArgs if using SettingType.CUSTOM
{
title: "<title here>", // what actually shows on the UI
value: "<value here (stringified)>" // the value that getSetting returns when this option is selected
},
// add more options at will by duplicating the object above
]
#
Accessing your (and the game's) settings
Getting a setting's value, yours or the game's, is a simple as:
pml.getSetting("<unique id>")
getSetting returns the string representation of your setting, so make sure to parse it properly if using booleans or sliders.
Here are the game's setting IDs
| Setting ID | Type |
|---------|---------|
| ImperialUnitsEnabled | Boolean |
| ResetHintEnabled | Boolean |
| GhostCarEnabled | Boolean |
| DefaultCameraMode | Boolean (true is cockpit) |
| CockpitCameraToggle | Boolean (true is toggle) |
| Checkpoints | Custom (string, top/bottom/off) |
| Timer | Same asCheckpoints |
| Speedometer | Same asCheckpoints |
| Language | Custom (string, language codes like en-US) |
| CarShadowQuality | Custom (int, 0/1024/2048/4096) |
| TrackShadowEnabled | Boolean |
| CloudsEnabled | Boolean |
| ParticlesEnabled | Boolean |
| SkidmarksEnabled | Boolean |
| RenderScale | Custom (float, 0.25/0.5/1/1.5/2) |
| Antialiasing | Boolean |
| SoundEffectVolume | Slider |
| MusicVolume | Slider |
| CheckpointVolume | Slider |
#
Custom Keybinds
Custom keybinds are even easier than the custom settings.
Create a category:
pml.registerBindCategory("<category name>");
Adding a keybind:
pml.registerKeybind("<name>", "<unique id>", "<keyboard event (ex: keydown, keyup, etc.)>", "<defaultBind (ex: KeyW, ArrowRight...)>", "<second bind (optional)>", callBackFunc = (event) => {});
The callback doesn't care what state the game is in, you will always receive it. It is your job to determine if the user is in the right context and call event.preventDefault() if needed.