Skip to content

Commit

Permalink
Added more fallback options for card sizes, when none is set. (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiocali authored Apr 5, 2022
1 parent e2bede3 commit f1dbbaf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
6 changes: 5 additions & 1 deletion languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"CardTiles.Settings.PassCardToBoardStack.Hint" : "If set, dealing a card onto the canvas passes it to a chosen stack.",
"CardTiles.Settings.BoardStack.Name" : "Default Board Stack",
"CardTiles.Settings.BoardStack.Hint" : "Cards that are played on the board are moved to this stack. If none is set, it will create one by default.",
"CardTiles.Settings.BoardStack.DefaultBoardStackOption" : "None"
"CardTiles.Settings.BoardStack.DefaultBoardStackOption" : "None",
"CardTiles.Settings.DefaultWidth.Name" : "Default Card Width",
"CardTiles.Settings.DefaultWidth.Hint" : "If both the card and its deck do not provide an explicit width value, this value will be used instead.",
"CardTiles.Settings.DefaultHeight.Name" : "Default Card Height",
"CardTiles.Settings.DefaultHeight.Hint" : "If both the card and its deck do not provide an explicit height value, this value will be used instead."
}
6 changes: 5 additions & 1 deletion languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"CardTiles.Settings.PassCardToBoardStack.Hint" : "Se abilitato, una carta giocata sulla scena viene automaticamente passata alla pila designata.",
"CardTiles.Settings.BoardStack.Name" : "Pila della Scena",
"CardTiles.Settings.BoardStack.Hint" : "Le carte giocate sulla scena vengono passate a questa pila. Se nessuna pila è stata scelta, ne viene generata una standard.",
"CardTiles.Settings.BoardStack.DefaultBoardStackOption" : "Nessuna"
"CardTiles.Settings.BoardStack.DefaultBoardStackOption" : "Nessuna",
"CardTiles.Settings.DefaultWidth.Name" : "Larghezza Carte (Default)",
"CardTiles.Settings.DefaultWidth.Hint" : "Se né la carta né la sua pila specificano un valore di larghezza, verrà utilizzato questo valore.",
"CardTiles.Settings.DefaultHeight.Name" : "Altezza Carte (Default)",
"CardTiles.Settings.DefaultHeight.Hint" : "Se né la carta né la sua pila specificano un valore di altezza, verrà utilizzato questo valore."
}
13 changes: 11 additions & 2 deletions scripts/card-tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async function onCanvasDrop(event) {

async function createCardTile(cardEventData) {
const card = cardEventData.card;
const cardCollection = cardEventData.cardCollection;

const monkFlags = {
"active" : true,
Expand All @@ -62,8 +63,8 @@ async function createCardTile(cardEventData) {
};

const scaling = game.settings.get(CardTilesConstants.MODULE_NAME, CardTilesConstants.Settings.SCALING_NAME) || 1.0;
const width = (card.data.width || 100) * scaling;
const height = (card.data.height || 100) * scaling;
const width = (card.data.width || getDefaultWidth(cardCollection)) * scaling;
const height = (card.data.height || getDefaultHeight(cardCollection)) * scaling;

const cardTileData = {
x : cardEventData.x - width / 2,
Expand Down Expand Up @@ -102,6 +103,14 @@ function buildFacesFiles(card) {
return allFaces.map( face => { return { "id" : randomID(16), "name" : face.img } } );
}

function getDefaultWidth(cardCollection) {
return cardCollection.data.width || game.settings.get(CardTilesConstants.MODULE_NAME, CardTilesConstants.Settings.DEFAULT_WIDTH_NAME) || 100;
}

function getDefaultHeight(cardCollection) {
return cardCollection.data.heigh || game.settings.get(CardTilesConstants.MODULE_NAME, CardTilesConstants.Settings.DEFAULT_HEIGHT_NAME) || 100;
}

async function moveCardToBoardStack(cardEventData) {
const cardCollection = cardEventData.cardCollection;
const destination = await getBoardStack();
Expand Down
4 changes: 3 additions & 1 deletion scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ export const MODULE_NAME = "card-tiles"
export const Settings = {
SCALING_NAME : "scaling",
BOARD_STACK_NAME : "board-stack",
PASS_CARDS_TO_BOARD_STACK : "pass-to-board-stack"
PASS_CARDS_TO_BOARD_STACK : "pass-to-board-stack",
DEFAULT_WIDTH_NAME : "default-card-width",
DEFAULT_HEIGHT_NAME : "default-card-height"
}
21 changes: 21 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ async function registerSettings() {
await registerScaling();
await registerPassToBoardStack();
await registerBoardStackSelector();
await registerDefaultCardSizes();
}

async function registerScaling() {
Expand Down Expand Up @@ -52,4 +53,24 @@ function buildCardStackSelector() {
};

return Array.from(game.cards).reduce(selectorReducer, selector);
}

async function registerDefaultCardSizes() {
await game.settings.register(CardTilesConstants.MODULE_NAME, CardTilesConstants.Settings.DEFAULT_HEIGHT_NAME, {
name: game.i18n.localize("CardTiles.Settings.DefaultHeight.Name"),
hint: game.i18n.localize("CardTiles.Settings.DefaultHeight.Hint"),
scope: "world",
config: true,
type: Number,
default: 100
});

await game.settings.register(CardTilesConstants.MODULE_NAME, CardTilesConstants.Settings.DEFAULT_WIDTH_NAME, {
name: game.i18n.localize("CardTiles.Settings.DefaultWidth.Name"),
hint: game.i18n.localize("CardTiles.Settings.DefaultWidth.Hint"),
scope: "world",
config: true,
type: Number,
default: 100
});
}

0 comments on commit f1dbbaf

Please sign in to comment.