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([
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);
});

@ -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]
);
}
}

Loading…
Cancel
Save