Skip to content

Commit

Permalink
Allow single section shuffles to repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiehumphries committed Aug 6, 2024
1 parent 1dd2a52 commit 72595d4
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,10 @@ class Section extends Toggleable {

for (let i = 0; i < cardCount; i++) {
const oldCard = this.cards[i];
const preferExclude = !isShuffleAll ? oldCard : null;
const newCard =
i < required.length
? required[i]
: this.randomCard({ isShuffleAll, exclude, preferExclude });
: this.randomCard({ isShuffleAll, exclude });
newCards.push(newCard);
exclude.push(newCard);

Expand Down Expand Up @@ -358,22 +357,13 @@ class Section extends Toggleable {
}
}

randomCard({
isShuffleAll = false,
exclude = [],
preferExclude = null,
available = null,
} = {}) {
randomCard({ isShuffleAll = false, exclude = [], available = null } = {}) {
available ||= this.allCheckedCards;
available = available.filter((card) => !exclude.includes(card));

if (preferExclude !== null && available.length > 1) {
available = available.filter((card) => card !== preferExclude);
}

if (available.length === 0) {
available = this.getDefaultOptions();
return this.randomCard({ exclude, preferExclude, available });
return this.randomCard({ exclude, available });
}

const prioritisedAvailable = available.flatMap((card) =>
Expand Down

0 comments on commit 72595d4

Please sign in to comment.