Add passives to cards via DB

develop
Nathan Steel 1 year ago
parent 5f89925a92
commit 3e512459cf

@ -251,6 +251,28 @@ function buildCardEffects(effects, effectSteps, effectTriggers){
} }
function getCardPassive(){
const cPromise = new Promise((resolve, reject) => {
database.dbGetPassive().then(data => {
let passives = [];
data.forEach((passive) => {
passives.push({
'cardId': passive.cardId,
'passiveId': passive.passiveId,
});
});
console.log(passives);
resolve(passives);
})
.catch(err => { throw err; })
});
return cPromise;
}
//getCardColourRequirement(); //getCardColourRequirement();
// Then effects which will have effects with parent triggers, and unit type checks // Then effects which will have effects with parent triggers, and unit type checks
@ -299,12 +321,13 @@ function requestDeck(itemData = null){
// Change SQL to accept for just the cards passed // Change SQL to accept for just the cards passed
// Get each cards data, colourReqs, and classes // Get each cards data, colourReqs, and classes
const [cards, cardClasses, cardColourRequirements, cardManaColours] = const [cards, cardClasses, cardColourRequirements, cardManaColours, cardPassives] =
await Promise.all([ await Promise.all([
getCards(), getCards(),
getCardClasses(), getCardClasses(),
getCardColourRequirement(), getCardColourRequirement(),
getCardManaColour(), getCardManaColour(),
getCardPassive(),
]); ]);
// ^^^^ Classes async? Can pass the cardsIds, then loop classes, if the class cardId // ^^^^ Classes async? Can pass the cardsIds, then loop classes, if the class cardId
@ -336,7 +359,7 @@ function requestDeck(itemData = null){
// 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, cardEffects), buildCards(cards, cardClasses, cardColourRequirements, cardManaColours, cardEffects, cardPassives),
]); ]);
//console.log(builtCards); //console.log(builtCards);
@ -395,6 +418,9 @@ function requestDeck(itemData = null){
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 = {}; let cardEffect = {};
// Passive
let flight = {};
let reach = {};
// 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
@ -465,6 +491,28 @@ function requestDeck(itemData = null){
if(cardData[itemCount].effect.length > 0){ if(cardData[itemCount].effect.length > 0){
cardEffect[itemCount] = cardData[itemCount].effect; cardEffect[itemCount] = cardData[itemCount].effect;
} }
// Add each passive
if(cardData[itemCount].passive.length > 0){
//console.log(cardData[itemCount].passive);
for(let i = 0; i < cardData[itemCount].passive.length; i++){
switch (cardData[itemCount].passive[i]){
// Flight
case 1:
flight[itemCount] = itemCount;
break;
// Reach
case 2:
reach[itemCount] = itemCount;
break;
}
}
}
itemCount++; // Increment item to not overwrite itemCount++; // Increment item to not overwrite
@ -489,6 +537,8 @@ function requestDeck(itemData = null){
itemData.cardSprite = cardSprite; itemData.cardSprite = cardSprite;
itemData.cardManaColour = cardManaColour; itemData.cardManaColour = cardManaColour;
itemData.cardEffect = cardEffect; itemData.cardEffect = cardEffect;
itemData.flight = flight;
itemData.reach = reach;
// item, itemCount, deckData, cardData, boardElement // item, itemCount, deckData, cardData, boardElement
//console.log(cardData); //console.log(cardData);
@ -514,7 +564,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, cardEffects){ function buildCards(cards, cardClasses, cardColourRequirements, cardManaColours, cardEffects, cardPassives){
console.log(cardColourRequirements); console.log(cardColourRequirements);
const dPromise = new Promise((resolve, reject) => { const dPromise = new Promise((resolve, reject) => {
@ -537,6 +587,7 @@ function buildCards(cards, cardClasses, cardColourRequirements, cardManaColours,
rarity: card.cardRarity, rarity: card.cardRarity,
effect: [], effect: [],
cardClass: [], cardClass: [],
passive: [],
}; };
// Give the card an easily accessible Id for compares // Give the card an easily accessible Id for compares
// and to add to the cardItem being built // and to add to the cardItem being built
@ -608,6 +659,17 @@ function buildCards(cards, cardClasses, cardColourRequirements, cardManaColours,
} }
// Add card mana colours (colour value when played in mana zone)
cardPassives.forEach((passive) => {
// Check the card exists (it should always, but don't want jank)
if(passive.cardId in builtCards){
// Add the colours to the class array (cards can have multiple)
builtCards[passive.cardId]['passive'].push(passive.passiveId);
}
});
resolve(builtCards); resolve(builtCards);
}); });

@ -205,6 +205,23 @@ function dbGetEffectTrigger(){
return ePromise; return ePromise;
} }
// Passive stuff
function dbGetPassive(){
const pPromise = new Promise((resolve, reject) => {
let sql = `SELECT
cardId
,passiveId
FROM card_passive
`;
con.query(sql, function (err, result, fields) {
if (err) { throw err; reject(new Error(err)); }
resolve(result);
});
});
return pPromise;
}
module.exports = { module.exports = {
connect, disconnect connect, disconnect
// Testing, and trailing // Testing, and trailing
@ -217,4 +234,5 @@ module.exports = {
, dbGetEffect , dbGetEffect
, dbGetEffectStep , dbGetEffectStep
, dbGetEffectTrigger , dbGetEffectTrigger
, dbGetPassive
}; };

@ -0,0 +1,3 @@
INSERT INTO `card_passive` (`id`, `cardId`, `passiveId`) VALUES (1, 1, 1);
INSERT INTO `card_passive` (`id`, `cardId`, `passiveId`) VALUES (2, 5, 2);

@ -1236,6 +1236,10 @@ function loadBoard(data) {
cardManaColour = data.cardManaColour; cardManaColour = data.cardManaColour;
cardEffect = data.cardEffect; cardEffect = data.cardEffect;
// Passives
flight = data.flight;
reach = data.reach;
// 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.
for(let i = 0; i < itemCount; i++){ for(let i = 0; i < itemCount; i++){

Loading…
Cancel
Save