Last active
February 20, 2022 23:28
-
-
Save Sevaarcen/809a091a45ed2d02e96cf6dbeb87039f to your computer and use it in GitHub Desktop.
FoundryVTT macro to choose a random card and play it as a tile in the current scene.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CONSTANTS | |
const SRC_DECK_NAME = "Tarokka Deck"; | |
const DST_CARD_PILE_NAME = "Tarokka Reading"; | |
const CARD_WIDTH = 150; | |
const CARD_HEIGHT = 210; | |
// get reference to src/dst cards objects | |
const src_cards = game.cards.filter(cards => cards.data.name===SRC_DECK_NAME)[0]; | |
const dst_cards = game.cards.filter(cards => cards.data.name===DST_CARD_PILE_NAME)[0]; | |
// deal 1 random card and grab reference to the dealt card | |
await src_cards.deal([dst_cards], 1, {how: CONST.CARD_DRAW_MODES.RANDOM}); | |
let most_recent_drawn = dst_cards.cards.contents[dst_cards.cards.size - 1]; | |
console.log(most_recent_drawn); | |
// Create TileDocument object in current scene using the card's face image | |
let card_tile_data = {z: 100 + dst_cards.cards.size, width: CARD_WIDTH, height: CARD_HEIGHT, img: most_recent_drawn.face.img}; | |
canvas.scene.createEmbeddedDocuments("Tile", [card_tile_data]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment