v12 support

This commit is contained in:
2024-06-07 11:26:46 +02:00
parent a3b6908a17
commit 15e249e41e
74 changed files with 410 additions and 241 deletions

View File

@@ -8,7 +8,7 @@ const IDX2CARDFAMILY = ['c', 'd', 'h', 's'];
export class SoSCardDeck {
/* -------------------------------------------- */
initCardDeck(actor, savedDeck = undefined ) {
async initCardDeck(actor, savedDeck = undefined ) {
this.data = {};
@@ -18,27 +18,28 @@ export class SoSCardDeck {
this.data.cardEdge = [];
if ( savedDeck.deck && savedDeck.deck.length > 0 ) {
this.data.deck = duplicate(savedDeck.deck);
this.data.deck = foundry.utils.duplicate(savedDeck.deck);
}
if ( savedDeck.discard && savedDeck.discard.length > 0 ) {
this.data.discard = duplicate(savedDeck.discard);
this.data.discard = foundry.utils.duplicate(savedDeck.discard);
}
if ( savedDeck.cardEdge && savedDeck.cardEdge.length > 0 ) {
this.data.cardEdge = duplicate(savedDeck.cardEdge);
this.data.cardEdge = foundry.utils.duplicate(savedDeck.cardEdge);
}
this.data.actor = actor;
if ( this.data.deck.length == 0 && this.data.discard.length == 0) {
this.shuffleDeck();
await this.shuffleDeck();
}
}
/* -------------------------------------------- */
shuffleDeck() {
async shuffleDeck() {
this.cleanCardList();
// Randomize deck
while (this.data.deck.length != NB_POKER_CARD) {
let idx = new Roll("1d54").roll( {async:false} ).total;
let roll = await new Roll("1d54").roll();
let idx = roll.total;
if (!this.data.cardState[idx - 1]) {
if (idx == 53) { // Red Joker
this.data.deck.push( { cardName: 'jr' } );
@@ -57,8 +58,8 @@ export class SoSCardDeck {
}
/* -------------------------------------------- */
resetDeck() {
let newdeck = duplicate(this.data.deck).concat( duplicate (this.data.discard) )
async resetDeck() {
let newdeck = foundry.utils.duplicate(this.data.deck).concat( foundry.utils.duplicate (this.data.discard) )
this.data.discard = [] // Reinit discard pile
this.data.deck = []
let decklen = newdeck.length
@@ -68,7 +69,8 @@ export class SoSCardDeck {
}
// Randomize deck
while (this.data.deck.length != decklen) {
let idx = new Roll("1d"+decklen).roll({async : false}).total
let roll = await new Roll("1d"+decklen).roll()
let idx = roll.total
//console.log("Deck stuff", this.data.deck.length, decklen, idx)
if (!cardState[idx-1]) {
this.data.deck.push( newdeck[idx-1] )
@@ -104,7 +106,7 @@ export class SoSCardDeck {
/* -------------------------------------------- */
getDeckSize() {
return this.data.deck.length;
return this.data.deck.length;
}
/* -------------------------------------------- */