API
OBS Utils comes with an API to allow custom overlays to be registered to it.
Accessing the API
Section titled “Accessing the API”The OBS Utils API can be accessed using:
game.modules.get("obs-utils").apiConsider any API properties not mentioned in this Guide “internal.” Not all use-cases are supported for external Components and will cause the module to break.
Self-Contained, single instance overlays
Section titled “Self-Contained, single instance overlays”You can create an overlay that will be rendered into the stream page exactly once. To do so, create a Svelte component of your desired overlay and then pass the Class Object you get from importing the Svelte Component to the API:
import YourOverlay from "../YourOverlay.svelte";
game.modules.get("obs-utils").api.registerUniqueOverlay(YourOverlay);The overlay will then be instanced on reload!
API Reference
Section titled “API Reference”The OBS Utils API provides the following methods and properties:
Properties
Section titled “Properties”overlayTypes: Map of overlay types registered with the APIoverlayTypeNames: Map of readable names for overlay typessingleInstanceOverlays: Set of Svelte components registered as single instance overlays
Methods
Section titled “Methods”registerOverlayType(key: string, readableName: string, type: OverlayType)
Section titled “registerOverlayType(key: string, readableName: string, type: OverlayType)”Registers a new overlay type with the API.
Parameters:
key(string): The key to identify the overlay typereadableName(string): A human-readable name for the overlay typetype(OverlayType): The overlay type object
registerUniqueOverlay(overlay: SvelteComponentConstructor)
Section titled “registerUniqueOverlay(overlay: SvelteComponentConstructor)”Registers a Svelte component as a unique overlay that will be rendered once.
Parameters:
overlay(SvelteComponentConstructor): The Svelte component to register
getSelectedActors()
Section titled “getSelectedActors()”Returns the currently selected actors for overlays.
Returns: Array of actor IDs
setSelectedActors(actorArray: string[])
Section titled “setSelectedActors(actorArray: string[])”Sets the selected actors for overlays.
Parameters:
actorArray(string[]): Array of actor IDs
setAVData(actorValueArray: ActorValues)
Section titled “setAVData(actorValueArray: ActorValues)”Sets actor values data.
Parameters:
actorValueArray(ActorValues): Actor values data
getOBSWebsocketClient()
Section titled “getOBSWebsocketClient()”Returns the OBS WebSocket client if the WebSocket API is allowed.
Returns: OBS WebSocket client or undefined
isOBS()
Section titled “isOBS()”Checks if the current context is OBS.
Returns: boolean
ObsUtilsApi
Section titled “ObsUtilsApi”The main API class that provides methods for registering overlay types and components.
export class ObsUtilsApi { // Properties overlayTypes: Map<string, OverlayType>; overlayTypeNames: Map<string, string>; singleInstanceOverlays: Set<SvelteComponentConstructor>;
// Methods registerOverlayType(key: string, readableName: string, type: OverlayType); registerUniqueOverlay(overlay: SvelteComponentConstructor); getSelectedActors(); setSelectedActors(actorArray: string[]); setAVData(actorValueArray: ActorValues); getOBSWebsocketClient(); isOBS();}OverlayType
Section titled “OverlayType”A class for defining custom overlay types.
export class OverlayType { // Properties overlayEditor: SvelteComponentConstructor; overlayComponents: Map<string, SvelteComponentConstructor>; overlayClass: SvelteComponentConstructor; overlayComponentNames: Map<string, string>; overlayComponentEditors: Map<string, SvelteComponentConstructor>; compactEditorButtons: Map<string, boolean>;
// Methods registerOverlayEditor(editor: SvelteComponentConstructor); registerComponent(key: string, readableName: string, type: SvelteComponentConstructor); registerComponentEditor(key: string, editor: SvelteComponentConstructor, compactButtons: boolean);}