Portal

Portal

A library module for spawning creatures, teleporting tokens, and picking locations. Check the wiki for the scripting API.

Free
Version: V12
FVTT: V12
Any System
Download
Changelog

    Portal Class Documentation

    Overview

    The Portal class provides a flexible interface for creating and managing portals. It allows you to set various properties such as origin, size, color, and texture, and supports functionalities like adding creatures, spawning them, teleporting tokens, and displaying dialogs.

    Properties

    • template: Returns the current template of the portal.
    • tokens: Returns an array of tokens associated with the portal.
    • origin: Returns the origin coordinates of the portal.
    • radius: Returns the radius of the portal.
    • texture: Returns the texture of the portal.

    Methods

    addCreature

    Adds a creature to the portal.

    Syntax:

    addCreature(creature, { updateData = null, count = 1 } = {})

    Parameters:

    • creature: Can be a single creature, an array of creatures, a token, token document, actor, or a string identifier (uuid or name).
    • updateData: Optional. Update data for the creature.
    • count: Optional. Number of creatures to add (default is 1).

    Example:

    portal.addCreature("Aboleth", { count: 3 });

    Example updateData:

    Click to expand
    const updateData = {
        token: {
            name: "Aboleth Clone",
            texture: {
                src: "icons/svg/dice-target.svg",
            }
            elevation: 10,
        },
        actor: {
            system: {
                attributes: {
                    hp: {
                        value: 150,
                        max: 150
                    }
                }
            }
        },
        embedded: {
            Item: {
                "Fireball": {
                    name: "Improved Fireball",
                    data: {
                        damage: {
                            parts: [["8d6", "fire"]]
                        }
                    }
                }
            }
        }
    };

    origin

    Sets the origin of the portal.

    Syntax:

    origin(origin)

    Parameters:

    • origin: Coordinates or a token/document.

    Example:

    portal.origin({ x: 100, y: 200 });

    size

    Sets the radius of the portal.

    Syntax:

    size(radius)

    Parameters:

    • radius: The radius value.

    Example:

    portal.size(30);

    color

    Sets the color of the portal.

    Syntax:

    color(color)

    Parameters:

    • color: The color value.

    Example:

    portal.color("#ff0000");

    range

    Sets the range of the portal.

    Syntax:

    range(range)

    Parameters:

    • range: The range value.

    Example:

    portal.range(60);

    texture

    Sets the texture of the portal.

    Syntax:

    texture(texture)

    Parameters:

    • texture: The texture URL or path.

    Example:

    portal.texture("icons/svg/dice-target.svg");

    pick

    Picks a location for the portal template asynchronously.

    Syntax:

    async pick(options = {})

    Parameters:

    • options: Options for picking the template.

    Example:

    const position = await portal.pick();

    spawn

    Spawns the portal and its associated tokens.

    Syntax:

    async spawn(options = {})

    Parameters:

    • options: Options for spawning.

    Example:

    await portal.spawn();

    dialog

    Opens a dialog for user interaction to configure and/or spawn the portal.

    Syntax:

    async dialog(options = { spawn: true, multipleChoice: false, title: `${MODULE_ID}.DIALOG.Title` })

    Parameters:

    • options: Options for the dialog.
      • spawn: Whether to spawn the portal after the dialog (default is true).
      • multipleChoice: Whether multiple selections are allowed (default is false).
      • title: The title of the dialog.

    Example:

    await portal.dialog({ spawn: true, multipleChoice: false, title: "Portal Configuration" });

    teleport

    Teleports a token to the portal location.

    Syntax:

    async teleport(options = {})

    Parameters:

    • options: Options for teleporting.

    Example:

    await portal.teleport();

    Static Methods

    spawn

    Creates and spawns a new portal.

    Syntax:

    static async spawn(options = {})

    Parameters:

    • options: Options for spawning.

    Example:

    await Portal.spawn({ creature: "Aboleth", count: 3 });

    Examples

    Spawning a creature

    Basic Spawning

    new Portal()
        .addCreature("Aboleth", {count: 3})
        .spawn()

    or using the quick shorthand

    Portal.spawn("Aboleth")

    Advanced Spawning

    new Portal()
        .addCreature("Aboleth", {count: 3})
        .color("#ff0000")
        .texture("icons/svg/dice-target.svg")
        .origin(token)
        .range(60)
        .spawn()

    Getting the spawned creatures

    const portal = new Portal();
    //...setup the portal
    const creatures = await portal.spawn();

    Teleporting a token

    Basic Teleporting

    new Portal()
        .origin(token)
        .teleport()

    Advanced Teleporting

    new Portal()
        .color("#ff0000")
        .texture("icons/svg/dice-target.svg")
        .origin(token)
        .range(60)
        .teleport()

    Picking a location

    Basic Picking

    new Portal()
        .pick()

    Advanced Picking

    new Portal()
        .color("#ff0000")
        .texture("icons/svg/dice-target.svg")
        .origin(token)
        .range(60)
        .pick()

    Spawning with a Choice Dialog

    new Portal()
        .addCreature("Acolyte", {count: 3})
        .addCreature("Aboleth", {count: 3})
        .dialog();