Skip to content
Joseph edited this page Jul 29, 2025 · 3 revisions

CCM provides a public-facing API in the global ccm namespace. This is loaded in prior to the init hook.

ccm.api

The following functions can all be accessed within the ccm.api namespace for use by systems, modules, and macros, e.g. ccm.api.grid

grid

/**
 * Creates a grid of placed cards
 * @param {object} config                       Mandatory configuration object
 * @param {Cards} config.from                   The Cards document to draw from
 * @param {Cards} config.to                     The Cards document to put the cards into
 * @param {number} config.rows                  Number of rows to layout
 * @param {number} config.columns               Number of columns to layout
 * @param {object} [options]                    Options modifying the layout
 * @param {number} [options.how=0]              How to draw, a value from CONST.CARD_DRAW_MODES
 * @param {object} [options.updateData={}]      Modifications to make to each Card as part of
 *                                              the draw operation, for example the displayed face
 * @param {number} [options.horizontalSpacing]  Spacing between cards horizontally
 *                                              Defaults to `canvas.grid.sizeX`
 * @param {number} [options.verticalSpacing]    Spacing between cards vertically
 *                                              Defaults to `canvas.grid.sizeY`
 * @param {number} [options.defaultWidth=2]     Default width of a card in grid squares
 * @param {number} [options.defaultHeight=3]    Default height of a card in grid squares
 * @param {number} [options.offsetX]            Adjust X offset from the top left of the scene
 * @param {number} [options.offsetY]            Adjust Y offset from the top left of the scene
 * @param {number} [options.sceneId]            Scene ID to play cards to. Defaults to canvas.scene
 * @returns {Promise<Card[]>}                   A promise that resolves to the drawn cards.
 */
async function grid(config, options = {})

triangle

/**
 * Creates a pyramid of placed cards
 * @param {object} config                       Mandatory configuration object
 * @param {Cards} config.from                   The Cards document to draw from
 * @param {Cards} config.to                     The Cards document to put the cards into
 * @param {number} config.base                  Number of cards per side
 * @param {object} [options]                    Options modifying the layout
 * @param {number} [options.how=0]              How to draw, a value from CONST.CARD_DRAW_MODES
 * @param {object} [options.updateData={}]      Modifications to make to each Card as part of
 *                                              the draw operation, for example the displayed face
 * @param {number} [options.horizontalSpacing]  Spacing between cards horizontally
 *                                              Defaults to `canvas.grid.sizeX`
 * @param {number} [options.verticalSpacing]    Spacing between cards vertically
 *                                              Defaults to `canvas.grid.sizeY`
 * @param {number} [options.defaultWidth=2]     Default width of a card in grid squares
 * @param {number} [options.defaultHeight=3]    Default height of a card in grid squares
 * @param {number} [options.offsetX]            Adjust X offset from the top left of the scene
 * @param {number} [options.offsetY]            Adjust Y offset from the top left of the scene
 * @param {"UP" | "DOWN" | "LEFT" | "RIGHT"} [options.direction] Direction to orient the pyramid
 * @param {number} [options.sceneId]            Scene ID to play cards to. Defaults to canvas.scene
 * @returns {Promise<Card[]>}                   A promise that resolves to the drawn cards.
 */
async function triangle(config, options = {})

recallCard

/**
 * Recall a drawn card from a deck.
 * @param {Cards} deck          The deck to recall a drawn card to.
 * @param {string} cardId       The id of the card to recall.
 * @returns {Promise<Card>}     A reference to the recalled card belonging to its original parent.
 */
async function recallCard(deck, cardId)

scry

/**
 * Scry on a number of cards in a deck, hand, or pile.
 * @param {Cards} deck                                            The deck, hand, or pile on which to spy.
 * @param {object} [options={}]                                   Options that modify the scrying.
 * @param {number} [options.amount=1]                             The number of cards to reveal.
 * @param {number} [options.how=CONST.CARD_DRAW_MODES.FIRST]      From where in the deck to draw the cards to scry on.
 * @returns {Promise<ScryDialog>
 */
async function scry(deck, {amount = 1, how = CONST.CARD_DRAW_MODES.FIRST} = {})

placeCard

/**
 * Places a card on the scene or updates its location
 * @param {Card | Cards} card      Card or Cards to place
 * @param {object} data            Data for the CanvasCard
 * @param {number} data.x          Center of the card's horizontal location
 * @param {number} data.y          Center of the card's vertical location
 * @param {number} [data.rotation] Rotation on the canvas (default: The card's rotation)
 * @param {number} [data.sort]     Sort value on the canvas (default: The card's sort)
 * @param {string} [data.sceneId]  ID of the scene to place (default: the current scene)
 * @returns {Card | Card}          The updated document
 */
async function placeCard(card, data = {})

removeCard

/**
 * Removes a card from the scene
 * @param {Card | Cards} card
 * @returns {Promise<Card | Cards>}      A promise that resolves to the updated card or cards document.
 */
async function removeCard(card)

cleanCardCollection

/**
 * Purges cards without relevant CanvasCard data from the current scene
 * @returns {Scene} The updated scene
 */
async function cleanCardCollection()

Clone this wiki locally