|
|
|
|
@ -329,13 +329,14 @@ function requestDeck(itemData = null){
|
|
|
|
|
await Promise.all([
|
|
|
|
|
buildCardEffects(effects, effectSteps, effectTriggers),
|
|
|
|
|
]);
|
|
|
|
|
// cardEffects[0][cardId] == [array of effect IDs]
|
|
|
|
|
// cardEffects[1][effectId] == {object of the effect data}
|
|
|
|
|
//console.log(cardEffects);
|
|
|
|
|
|
|
|
|
|
// Build the cardData (maybe do all the components here too)
|
|
|
|
|
const [builtCards] =
|
|
|
|
|
await Promise.all([
|
|
|
|
|
buildCards(cards, cardClasses, cardColourRequirements, cardManaColours),
|
|
|
|
|
// TODO: builtEffects
|
|
|
|
|
buildCards(cards, cardClasses, cardColourRequirements, cardManaColours, cardEffects),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
//console.log(builtCards);
|
|
|
|
|
@ -393,6 +394,7 @@ function requestDeck(itemData = null){
|
|
|
|
|
let cardAttack = {}; // Base, Current
|
|
|
|
|
let cardSprite = {}; // Maybe from DB?
|
|
|
|
|
let cardManaColour = {}; // The card colour value when played in mana zone
|
|
|
|
|
let cardEffect = {};
|
|
|
|
|
|
|
|
|
|
// TODO: Set the player. For now will do this in front-end as testing currently
|
|
|
|
|
|
|
|
|
|
@ -457,6 +459,13 @@ function requestDeck(itemData = null){
|
|
|
|
|
cardAttack[itemCount] = [atk, atk]; // Base, Current
|
|
|
|
|
player[itemCount] = forPlayer; // Jank TODO: actually set to correct player
|
|
|
|
|
|
|
|
|
|
// Add the cardEffect(s) to the cardEffect component
|
|
|
|
|
// only if there is an effect, starting to think about
|
|
|
|
|
// not wasting RAM/storage, y'know
|
|
|
|
|
if(cardData[itemCount].effect.length > 0){
|
|
|
|
|
cardEffect[itemCount] = cardData[itemCount].effect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
itemCount++; // Increment item to not overwrite
|
|
|
|
|
}
|
|
|
|
|
@ -479,6 +488,7 @@ function requestDeck(itemData = null){
|
|
|
|
|
itemData.cardAttack = cardAttack;
|
|
|
|
|
itemData.cardSprite = cardSprite;
|
|
|
|
|
itemData.cardManaColour = cardManaColour;
|
|
|
|
|
itemData.cardEffect = cardEffect;
|
|
|
|
|
|
|
|
|
|
// item, itemCount, deckData, cardData, boardElement
|
|
|
|
|
//console.log(cardData);
|
|
|
|
|
@ -504,7 +514,7 @@ function requestDeck(itemData = null){
|
|
|
|
|
// point to see. For now DB, and generating is ok, as still working on it
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function buildCards(cards, cardClasses, cardColourRequirements, cardManaColours){
|
|
|
|
|
function buildCards(cards, cardClasses, cardColourRequirements, cardManaColours, cardEffects){
|
|
|
|
|
|
|
|
|
|
console.log(cardColourRequirements);
|
|
|
|
|
const dPromise = new Promise((resolve, reject) => {
|
|
|
|
|
@ -581,6 +591,23 @@ function buildCards(cards, cardClasses, cardColourRequirements, cardManaColours)
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Add the card effects that have been pre-built
|
|
|
|
|
// Loop the cards (each with an array of effect IDs)
|
|
|
|
|
for (const [key] of Object.entries(cardEffects[0])) {
|
|
|
|
|
|
|
|
|
|
// If the cardId is not in builtCards, skip
|
|
|
|
|
// should always be, but eh
|
|
|
|
|
let cardId = cardEffects[0][key];
|
|
|
|
|
if(builtCards[cardId] === undefined){ continue; }
|
|
|
|
|
|
|
|
|
|
// Loop the effects in each of the card's effect arrays
|
|
|
|
|
for (const [key, value] of Object.entries(cardEffects[1])) {
|
|
|
|
|
// Add each effect that belongs to the card
|
|
|
|
|
builtCards[cardId].effect.push(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolve(builtCards);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|