Created
February 20, 2022 22:29
-
-
Save Sevaarcen/d9fd5c5c9356a28e708192d447a77872 to your computer and use it in GitHub Desktop.
Macro for FoundryVTT Allowing you to choose a specific card to pass to an in-play deck AND create corresponding 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 SOURCE/DESTINATION "CARDS" OBJECTS | |
const src_cards = game.cards.filter(cardstack => cardstack.data.name===SRC_DECK_NAME)[0]; | |
const dst_cards = game.cards.filter(cardstack => cardstack.data.name===DST_CARD_PILE_NAME)[0]; | |
// For all available cards, create a dropdown menu option w/ suit, value, and card name | |
// use ternary operator to remove any fields w/o values to make pretty | |
let available_cards_html = src_cards.availableCards.map(card => `<option value="${card.data._id}">${card.data.suit}${(card.data.value ? " " + card.data.value : "")}${(card.data.name ? ": " + card.data.name : "")}</option>`) | |
// Create and show Dialog view w/ card choices | |
new Dialog({ | |
title: "Cards to Tile", | |
content: ` | |
<form> | |
<div> | |
<select id="picked_card"> | |
${available_cards_html} | |
</select> | |
</div> | |
</form> | |
`, | |
buttons: { | |
cancel: { | |
label: "Cancel" | |
}, | |
confirm: { | |
label: "Confirm", | |
callback: () => { | |
// Grab chosen card's ID, and use that ID to pass card from src to dst cards collection | |
// and then create tile from card's face image | |
let chosen_id = document.getElementById("picked_card").value; | |
let chosen_card = src_cards.cards.filter(c => c.data._id === chosen_id)[0]; | |
src_cards.pass(dst_cards, [chosen_card.data._id]); | |
const tile_data = {z: 100 + dst_cards.cards.size, width: CARD_WIDTH, height: CARD_HEIGHT, img: chosen_card.face.img}; | |
canvas.scene.createEmbeddedDocuments("Tile", [tile_data]); | |
} | |
} | |
}, | |
default: "cancel" | |
}).render(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment