ThreeDDice Class

Hierarchy

  • ThreeDDice

Properties

DICE_ON_TABLE_LIMIT: number = 25

Limit of 3D dice to allow on table at any one time

DefaultConfig: IEngineConfig = ...

Default Config

API Connection

Available after calling connect

apiKey?: string

API Key

canvas?: HTMLCanvasElement

Canvas

Constructors

  • Construct and initialize the object

    Parameters

    • Optional canvas: HTMLCanvasElement

      Canvas element

    • Optional apiKey: string

      Required if connecting to the dddice API

    • Optional config: Partial<IEngineConfig>

      Optional configuration to change the look and feel of the renderer

    Returns ThreeDDice

Methods

  • Check if WebGL is available

    Returns boolean

  • Clear all dice from canvas

    Returns void

  • Connect to the live server and begin listening to room events.

    Note: Your user must be a participant in a room in order to listen to events, otherwise an error is thrown.

    Parameters

    • roomSlug: string

      Room slug to listen on

    • Optional roomPasscode: string

      Private passcode to access room

    • Optional userUuid: string

      Personal User UUID to listen to whispers

    Returns ThreeDDice

  • Connect to the live server and begin listening to room events.

    Note: Your user must be a participant in a room in order to listen to events, otherwise an error is thrown.

    Returns ThreeDDice

  • Return a loaded theme

    Parameters

    • themeId: string

    Returns ITheme

  • Return all loaded themes

    Returns ITheme[]

  • Initialize object if the default constructor had been called

    Parameters

    • Optional canvas: HTMLCanvasElement

      Canvas element

    • Optional apiKey: string

      Required if connecting to the dddice API

    • Optional config: Partial<IEngineConfig>

      Optional configuration to change the look and feel of the renderer

    • Optional appName: string

      Optional name to identify which application is connecting to dddice

    Returns ThreeDDice

  • Load a theme, including shaders, into the engine

    Parameters

    • theme: ITheme
    • overwriteTheme: boolean = false
    • fetchPreviews: boolean = true

    Returns ThreeDDice

  • Pause camera controls

    Returns void

  • Pick up dice

    This clears certain dice from the board and updates the API

    Returns

    void

    Throws

    APIError if connect not called previously

    Parameters

    • roll: IRoll | IRoll[]

      single roll or array of rolls

    • uuids: string[] = []

      Optional array of dice uuids

    Returns Promise<IApiResponse<"roll[]", IRoll[]>>

  • Load assets for a loaded theme

    This loads all meshes, textures, and sounds for a dice theme. Calling this multiple times will debounce the loading processing for 50ms

    Returns a list of items to be queued

    Parameters

    • id: string
    • processQueue: boolean = true

    Returns string[]

  • Reset camera frame

    After disabling camera controls, this can be used to reset the camera view to a top-down angle

    Returns void

  • Resize canvas

    Parameters

    • width: number

      Width of canvas in pixels

    • height: number

      Height of canvas in pixels

    Returns ThreeDDice

  • Resume camera controls

    Returns void

  • Screenshot the canvas

    Returns

    screenshot as a DataURI

    Parameters

    • mimeType: string

      image format mime type of the generated screenshot.

    Returns undefined | string

  • Change the hidden state of a roll

    Optionally pass the uuids of specific dice to only unhide those dice, otherwise all dice in the roll will be revealed.

    Returns

    void

    Throws

    APIError if connect not called previously

    Parameters

    • roll: IRoll

      IRoll Roll to unhide

    • uuids: string[] = []

      Optional array of dice uuids

    Returns Promise<IApiResponse<"roll", IRoll>>

Accessors

  • get controlsEnabled(): boolean
  • Get mouse/pointer controls enabled

    Returns boolean

  • set controlsEnabled(enabled: boolean): void
  • Set mouse/pointer controls enabled

    Parameters

    • enabled: boolean

    Returns void

  • get height(): number
  • Canvas Height

    Returns number

  • get isDiceThrowing(): boolean
  • Get if a roll is currently animating

    Returns boolean

  • get version(): string
  • Get the current version of dddice

    Returns string

  • get width(): number
  • Canvas width

    Returns number

Generated using TypeDoc