Add cardEffect component data

develop
Nathan Steel 1 year ago
parent 116f7af480
commit f83f003a92

@ -329,13 +329,14 @@ function requestDeck(itemData = null){
await Promise.all([ await Promise.all([
buildCardEffects(effects, effectSteps, effectTriggers), buildCardEffects(effects, effectSteps, effectTriggers),
]); ]);
// cardEffects[0][cardId] == [array of effect IDs]
// cardEffects[1][effectId] == {object of the effect data}
//console.log(cardEffects); //console.log(cardEffects);
// Build the cardData (maybe do all the components here too) // Build the cardData (maybe do all the components here too)
const [builtCards] = const [builtCards] =
await Promise.all([ await Promise.all([
buildCards(cards, cardClasses, cardColourRequirements, cardManaColours), buildCards(cards, cardClasses, cardColourRequirements, cardManaColours, cardEffects),
// TODO: builtEffects
]); ]);
//console.log(builtCards); //console.log(builtCards);
@ -393,6 +394,7 @@ function requestDeck(itemData = null){
let cardAttack = {}; // Base, Current let cardAttack = {}; // Base, Current
let cardSprite = {}; // Maybe from DB? let cardSprite = {}; // Maybe from DB?
let cardManaColour = {}; // The card colour value when played in mana zone 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 // 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; let atk = cardData[itemCount].atk;
cardAttack[itemCount] = [atk, atk]; // Base, Current cardAttack[itemCount] = [atk, atk]; // Base, Current
player[itemCount] = forPlayer; // Jank TODO: actually set to correct player 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 itemCount++; // Increment item to not overwrite
@ -479,6 +488,7 @@ function requestDeck(itemData = null){
itemData.cardAttack = cardAttack; itemData.cardAttack = cardAttack;
itemData.cardSprite = cardSprite; itemData.cardSprite = cardSprite;
itemData.cardManaColour = cardManaColour; itemData.cardManaColour = cardManaColour;
itemData.cardEffect = cardEffect;
// item, itemCount, deckData, cardData, boardElement // item, itemCount, deckData, cardData, boardElement
//console.log(cardData); //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 // 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); console.log(cardColourRequirements);
const dPromise = new Promise((resolve, reject) => { 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); resolve(builtCards);
}); });

@ -40,6 +40,7 @@ let deckData = {};
let cardAttack = {}; // TODO: add to the logic let cardAttack = {}; // TODO: add to the logic
let cardColours = {}; let cardColours = {};
let cardManaColour = {}; let cardManaColour = {};
let cardEffect = {};
let inEvent = null; let inEvent = null;
// To disable drawing each time something changes // To disable drawing each time something changes
@ -1191,6 +1192,7 @@ function loadBoard(data) {
cardAttack = data.cardAttack; // TODO: add to the logic cardAttack = data.cardAttack; // TODO: add to the logic
cardColours = data.cardColours; cardColours = data.cardColours;
cardManaColour = data.cardManaColour; cardManaColour = data.cardManaColour;
cardEffect = data.cardEffect;
// TODO: JANK IN, CHANGE CODE TO USE NEW ARRAY!! // TODO: JANK IN, CHANGE CODE TO USE NEW ARRAY!!
// Temp jank, set colour to first colour req. // Temp jank, set colour to first colour req.
@ -1672,7 +1674,8 @@ function printECSData(items){
'deckData: '+deckData[itemKey]+"\n"+ 'deckData: '+deckData[itemKey]+"\n"+
'cardAttack: '+cardAttack[itemKey]+"\n"+ 'cardAttack: '+cardAttack[itemKey]+"\n"+
'cardColours: '+cardColours[itemKey]+"\n"+ 'cardColours: '+cardColours[itemKey]+"\n"+
'cardManaColour: '+cardManaColour[itemKey] 'cardManaColour: '+cardManaColour[itemKey]+"\n"+
'cardEffect: '+cardEffect[itemKey]
); );
} }
} }

Loading…
Cancel
Save