UserOptions
UserOptions
Kind: global class
new UserOptions()
Handle events relating to changes in user options for your mod.
User options are defined in the options
object in your octos.json file, and are configurable by users in the Octos app:
userOptions.on(eventName, callback)
Add an event listener.
Kind: instance method of UserOptions
Param | Type | Description |
---|---|---|
eventName | 'change' | 'load' | 'changeload' |
Events with type change are fired whenever a user changes an option. load events are fired when the wallpaper first loads in. changeload fires for either of the previous events. |
callback | function |
Callback receives an object containing the ID of the affected option (as specified in octos.json ) along with its value in the form {id, value} . |
Example
// This example shows how to add a simple checkbox for dark mode in your mod and listen for changes by the user.
// In your octos.json:
{
...
"options": {
"dark-mode": {
"type": "checkbox",
"value": true,
"label": "Enable dark mode?"
}
}
...
}
// In your script.js:
// Listen for changes in user options for your mod
userOptions.on('change', ({id, value}) => {
if (id == 'dark-mode') {
if (value) {
myElement.classList.add('dark-mode')
}
else {
myElement.classList.remove('dark-mode')
}
}
... // handle changes for other options
})
userOptions.once(eventName, callback)
Add a one-time event listener that removes itself after firing.
Kind: instance method of UserOptions
Param | Type |
---|---|
eventName | 'change' | 'load' | 'changeload' |
callback | function |
userOptions.off(eventName, callback)
Remove an event listener.
Kind: instance method of UserOptions
Param | Type |
---|---|
eventName | 'change' | 'load' | 'changeload' |
callback | function |
userOptions.requestOptions() ⇒ Promise.<object>
Request all user options along with their properties and values and await a response.
Kind: instance method of UserOptions
Returns: Promise.<object>
- Resolves to an object containing options
from octos.json
along with user-set values.
Example
userOptions.requestOptions().then((options) => {
// what the options object looks like:
// {
// "dark-mode": {
// "type": "checkbox",
// "value": (user-set),
// "label": "Enable dark mode?"
// }
// ... any other options
// }
if (options['dark-mode'].value) {
myElement.classList.add('dark-mode')
}
});
userOptions.setOption(id, value)
Set the value of a user option. Note that this will not trigger user events such as 'change'
.
Kind: instance method of UserOptions
Param | Type | Description |
---|---|---|
id | string |
The id of the option to set, as specified in options of octos.json . |
value | any |
The value to set. |
Example
userOptions.setOption('dark-mode', true);