mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Tarot Command
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = class TarotCard {
|
||||
constructor(data) {
|
||||
this.rank = data.rank;
|
||||
this.suit = data.suit;
|
||||
this.name = data.name;
|
||||
this.meanings = data.meanings;
|
||||
this.keywords = data.keywords;
|
||||
this.fortunes = data.fortune_telling;
|
||||
}
|
||||
|
||||
get imagePath() {
|
||||
return path.join(__dirname, '..', '..', 'assets', 'images', 'tarot', this.suit, `${this.rank}.jpg`);
|
||||
}
|
||||
|
||||
randomLightMeaning() {
|
||||
return this.meanings.light[Math.floor(Math.random() * this.meanings.light.length)];
|
||||
}
|
||||
|
||||
randomShadowMeaning() {
|
||||
return this.meanings.shadow[Math.floor(Math.random() * this.meanings.shadow.length)];
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
const TarotCard = require('./TarotCard');
|
||||
const cards = require('../../assets/json/tarot');
|
||||
const { shuffle } = require('../../util/Util');
|
||||
|
||||
module.exports = class TarotDeck {
|
||||
constructor() {
|
||||
this.deck = [];
|
||||
this.makeCards();
|
||||
}
|
||||
|
||||
makeCards() {
|
||||
const newDeck = [];
|
||||
for (const card of cards) {
|
||||
newDeck.push(new TarotCard(card));
|
||||
}
|
||||
this.deck = shuffle(newDeck);
|
||||
return this.deck;
|
||||
}
|
||||
|
||||
draw(amount = 1) {
|
||||
const cards = [];
|
||||
for (let i = 0; i < amount; i++) {
|
||||
const card = this.deck[0];
|
||||
this.deck.shift();
|
||||
cards.push(card);
|
||||
}
|
||||
return amount === 1 ? cards[0] : cards;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.makeCards();
|
||||
return this;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user