41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { ref } from 'vue';
|
|
|
|
export const useTarotStore = defineStore('tarot', () => {
|
|
// State
|
|
const freeDrawsRemaining = ref(1);
|
|
const paidDrawsRemaining = ref(0);
|
|
|
|
// Actions
|
|
function useFreeDraw() {
|
|
if (freeDrawsRemaining.value > 0) {
|
|
freeDrawsRemaining.value--;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Modified usePaidDraw to handle the correct number of cards and reset the state
|
|
function usePaidDraw(count: number) {
|
|
if (paidDrawsRemaining.value >= count) {
|
|
// Since the draws are 'used', we set the remaining to 0.
|
|
// This assumes a user pays for a set number of cards in one go.
|
|
paidDrawsRemaining.value = 0;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function addPaidDraws(count: number) {
|
|
paidDrawsRemaining.value += count;
|
|
}
|
|
|
|
return {
|
|
freeDrawsRemaining,
|
|
paidDrawsRemaining,
|
|
useFreeDraw,
|
|
usePaidDraw,
|
|
addPaidDraws,
|
|
};
|
|
});
|