@ -140,6 +140,27 @@ function getCardColourRequirement(){
} ) ;
} ) ;
return dPromise ;
return dPromise ;
}
}
function getCardManaColour ( ) {
const cPromise = new Promise ( ( resolve , reject ) => {
database . dbGetCardManaColour ( ) . then ( data => {
let manaColours = [ ] ;
data . forEach ( ( cardManaColour ) => {
manaColours . push ( {
'cardId' : cardManaColour . cardId ,
'colourId' : cardManaColour . colourId ,
} ) ;
} ) ;
resolve ( manaColours ) ;
} )
. 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
// colour checks, all sorts. So will be more difficult. Basic (flight, etc)
// colour checks, all sorts. So will be more difficult. Basic (flight, etc)
@ -187,11 +208,12 @@ 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 ] =
const [ cards , cardClasses , cardColourRequirements , cardManaColours ] =
await Promise . all ( [
await Promise . all ( [
getCards ( ) ,
getCards ( ) ,
getCardClasses ( ) ,
getCardClasses ( ) ,
getCardColourRequirement ( ) ,
getCardColourRequirement ( ) ,
getCardManaColour ( ) ,
] ) ;
] ) ;
// ^^^^ 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
// matches the cardId in cards[] then push the class to cards[x].classes
// matches the cardId in cards[] then push the class to cards[x].classes
@ -204,7 +226,7 @@ function requestDeck(itemData = null){
const [ builtCards ] =
const [ builtCards ] =
await Promise . all ( [
await Promise . all ( [
buildCards ( cards , cardClasses , cardColourRequirements ),
buildCards ( cards , cardClasses , cardColourRequirements , cardManaColours ),
// TODO: builtEffects
// TODO: builtEffects
] ) ;
] ) ;
@ -262,6 +284,7 @@ function requestDeck(itemData = null){
let cardColours = { } ; // Array of req.
let cardColours = { } ; // Array of req.
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
// 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
@ -320,6 +343,7 @@ function requestDeck(itemData = null){
cardStatus [ itemCount ] = null ;
cardStatus [ itemCount ] = null ;
cardFace [ itemCount ] = 0 ; // Face down by default (in deck)
cardFace [ itemCount ] = 0 ; // Face down by default (in deck)
cardColours [ itemCount ] = cardData [ itemCount ] . colourRequirements ; // TODO;
cardColours [ itemCount ] = cardData [ itemCount ] . colourRequirements ; // TODO;
cardManaColour [ itemCount ] = cardData [ itemCount ] . cardManaColour ;
// From cardData set the base attack, and current (same when deckbuild)
// From cardData set the base attack, and current (same when deckbuild)
let atk = cardData [ itemCount ] . atk ;
let atk = cardData [ itemCount ] . atk ;
cardAttack [ itemCount ] = [ atk , atk ] ; // Base, Current
cardAttack [ itemCount ] = [ atk , atk ] ; // Base, Current
@ -346,6 +370,7 @@ function requestDeck(itemData = null){
itemData . cardColours = cardColours ;
itemData . cardColours = cardColours ;
itemData . cardAttack = cardAttack ;
itemData . cardAttack = cardAttack ;
itemData . cardSprite = cardSprite ;
itemData . cardSprite = cardSprite ;
itemData . cardManaColour = cardManaColour ;
// item, itemCount, deckData, cardData, boardElement
// item, itemCount, deckData, cardData, boardElement
//console.log(cardData);
//console.log(cardData);
@ -371,7 +396,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 ){
function buildCards ( cards , cardClasses , cardColourRequirements , cardManaColours ){
console . log ( cardColourRequirements ) ;
console . log ( cardColourRequirements ) ;
const dPromise = new Promise ( ( resolve , reject ) => {
const dPromise = new Promise ( ( resolve , reject ) => {
@ -388,6 +413,7 @@ function buildCards(cards, cardClasses, cardColourRequirements){
colour : [ ] ,
colour : [ ] ,
cost : card . cardCost ,
cost : card . cardCost ,
colourRequirements : [ ] ,
colourRequirements : [ ] ,
cardManaColour : [ ] , // Should probably be an object
type : card . cardType ,
type : card . cardType ,
atk : card . cardAttack ,
atk : card . cardAttack ,
rarity : card . cardRarity ,
rarity : card . cardRarity ,
@ -436,6 +462,17 @@ function buildCards(cards, cardClasses, cardColourRequirements){
} ) ;
} ) ;
// Add card mana colours (colour value when played in mana zone)
cardManaColours . forEach ( ( manaCol ) => {
// Check the card exists (it should always, but don't want jank)
if ( manaCol . cardId in builtCards ) {
// Add the colours to the class array (cards can have multiple)
builtCards [ manaCol . cardId ] . cardManaColour . push ( manaCol . colourId ) ;
}
} ) ;
resolve ( builtCards ) ;
resolve ( builtCards ) ;
} ) ;
} ) ;