From f83f003a924951179870aa3befb4a9b3cf33d0f1 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 25 Oct 2024 00:25:09 +0100 Subject: [PATCH] Add cardEffect component data --- cardGen.js | 33 ++++++++++++++++++++++++++++++--- public/board.js | 5 ++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/cardGen.js b/cardGen.js index 6dca172..eac3737 100644 --- a/cardGen.js +++ b/cardGen.js @@ -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 @@ -456,6 +458,13 @@ function requestDeck(itemData = null){ let atk = cardData[itemCount].atk; 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); }); diff --git a/public/board.js b/public/board.js index 782d30a..bbd9137 100644 --- a/public/board.js +++ b/public/board.js @@ -40,6 +40,7 @@ let deckData = {}; let cardAttack = {}; // TODO: add to the logic let cardColours = {}; let cardManaColour = {}; +let cardEffect = {}; let inEvent = null; // To disable drawing each time something changes @@ -1191,6 +1192,7 @@ function loadBoard(data) { cardAttack = data.cardAttack; // TODO: add to the logic cardColours = data.cardColours; cardManaColour = data.cardManaColour; + cardEffect = data.cardEffect; // TODO: JANK IN, CHANGE CODE TO USE NEW ARRAY!! // Temp jank, set colour to first colour req. @@ -1672,7 +1674,8 @@ function printECSData(items){ 'deckData: '+deckData[itemKey]+"\n"+ 'cardAttack: '+cardAttack[itemKey]+"\n"+ 'cardColours: '+cardColours[itemKey]+"\n"+ - 'cardManaColour: '+cardManaColour[itemKey] + 'cardManaColour: '+cardManaColour[itemKey]+"\n"+ + 'cardEffect: '+cardEffect[itemKey] ); } }