Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    A simple event framework used throughout Foundry Virtual Tabletop. When key actions or events occur, a "hook" is defined where user-defined callback functions can execute. This class manages the registration and execution of hooked callback functions.

    Index

    Accessors

    Methods

    Accessors

    • get events(): Record<string, HookedFunction[]>

      A mapping of hook events which have functions registered to them.

      Returns Record<string, HookedFunction[]>

    Methods

    • Call hook listeners in the order in which they were registered. Continue calling hooks until either all have been called or one returns false.

      Hook listeners which return false denote that the original event has been adequately handled and no further hooks should be called.

      Parameters

      • hook: string

        The hook being triggered

      • ...args: any[]

        Arguments passed to the hook callback functions

      Returns boolean

      Were all hooks called without execution being prevented?

    • Call all hook listeners in the order in which they were registered Hooks called this way can not be handled by returning false and will always trigger every hook callback.

      Parameters

      • hook: string

        The hook being triggered

      • ...args: any[]

        Arguments passed to the hook callback functions

      Returns void

    • Unregister a callback handler for a particular hook event

      Parameters

      • hook: string

        The unique name of the hooked event

      • fn: number | Function

        The function, or ID number for the function, that should be turned off

      Returns void

    • Register a callback handler which should be triggered when a hook is triggered.

      Parameters

      • hook: string

        The unique name of the hooked event

      • fn: Function

        The callback function which should be triggered when the hook event occurs

      • options: { once: boolean } = {}

        Options which customize hook registration

        • once: boolean

          Only trigger the hooked function once

      Returns number

      An ID number of the hooked function which can be used to turn off the hook later

    • Register a callback handler for an event which is only triggered once the first time the event occurs. An alias for Hooks.on with {once: true}

      Parameters

      • hook: string

        The unique name of the hooked event

      • fn: Function

        The callback function which should be triggered when the hook event occurs

      Returns number

      An ID number of the hooked function which can be used to turn off the hook later

    • Notify subscribers that an error has occurred within foundry.

      Parameters

      • location: string

        The method where the error was caught.

      • error: Error

        The error.

      • Optionaloptions: { data?: object; log?: string; msg?: string; notify?: string } = {}

        Additional options to configure behaviour.

        • Optionaldata?: object

          Additional data to pass to the hook subscribers.

        • Optionallog?: string

          The level at which to log the error to console (if at all).

        • Optionalmsg?: string

          A message which should prefix the resulting error or notification.

        • Optionalnotify?: string

          The level at which to spawn a notification in the UI (if at all).

      Returns void