Jeck - Added full filtering system to deck editor and shop. I've spent 24hours on pure debugging, but there are likely a couple bugs I've missed. So please, if you find something, make an issue of it! :P Also split OptionItem classes into separate files, and added support for mixed-set boosters (which I think are way, way cool).
This commit is contained in:
@@ -2,180 +2,67 @@
|
||||
#include "../include/DeckDataWrapper.h"
|
||||
#include "../include/MTGDeck.h"
|
||||
#include "../include/PriceList.h"
|
||||
#include "../include/WDataSrc.h"
|
||||
|
||||
DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){
|
||||
parent = deck;
|
||||
for (int i = 0; i <= Constants::MTG_NB_COLORS; i++){
|
||||
colors[i] = 0;
|
||||
}
|
||||
parent = deck;
|
||||
for(int c=0;c<Constants::MTG_NB_COLORS;c++)
|
||||
counts[c] = 0;
|
||||
Add(deck);
|
||||
|
||||
currentColor = -1;
|
||||
}
|
||||
|
||||
int DeckDataWrapper::Add(MTGDeck * deck){
|
||||
map<int,int>::iterator it;
|
||||
for (it = deck->cards.begin(); it!=deck->cards.end(); it++){
|
||||
MTGCard * card = deck->getCardById(it->first);
|
||||
Add(card,it->second);
|
||||
}
|
||||
return 1;
|
||||
if(loadMatches(deck))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
int DeckDataWrapper::Remove(MTGCard * c, int quantity,bool erase){
|
||||
if(WSrcDeck::Remove(c,quantity,erase)){
|
||||
for(int i=0;i<Constants::MTG_NB_COLORS;i++){
|
||||
if(c->data->hasColor(i))
|
||||
counts[i]-=quantity;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int DeckDataWrapper::Add(MTGCard * c, int quantity){
|
||||
if(WSrcDeck::Add(c,quantity)){
|
||||
for(int i=0;i<Constants::MTG_NB_COLORS;i++){
|
||||
if(c->data && c->data->hasColor(i))
|
||||
counts[i]+=quantity;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int DeckDataWrapper::getCount(int color){
|
||||
if(color < 0 || color >=Constants::MTG_NB_COLORS)
|
||||
return Size(true);
|
||||
return counts[color];
|
||||
}
|
||||
void DeckDataWrapper::updateCounts(){
|
||||
map<int,int>::iterator it;
|
||||
for(int c=0;c<Constants::MTG_NB_COLORS;c++)
|
||||
counts[c] = 0;
|
||||
|
||||
void DeckDataWrapper::save(){
|
||||
parent->removeAll();
|
||||
map<MTGCard *,int,Cmp1>::iterator it;
|
||||
for ( it=cards.begin() ; it != cards.end(); it++ ){
|
||||
MTGCard * current = (*it).first;
|
||||
for (int i = 0; i < (*it).second; i++){
|
||||
parent->add(current);
|
||||
for(int i=0;i<Size(true);i++){
|
||||
for(int c=0;c<Constants::MTG_NB_COLORS;c++){
|
||||
MTGCard * card = getCard(c,true);
|
||||
if(card->data->hasColor(c)){
|
||||
it = copies.find(card->getMTGId());
|
||||
if(it != copies.end())
|
||||
counts[c]+=it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void DeckDataWrapper::save(){
|
||||
Rebuild(parent);
|
||||
parent->save();
|
||||
}
|
||||
|
||||
|
||||
DeckDataWrapper::~DeckDataWrapper(){
|
||||
SAFE_DELETE(parent);
|
||||
}
|
||||
|
||||
void DeckDataWrapper::updateCounts(MTGCard * card, int increment){
|
||||
if (!card){
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS+1; i++){
|
||||
colors[i] = 0;
|
||||
}
|
||||
map<MTGCard *,int,Cmp1>::iterator it;
|
||||
for ( it=cards.begin() ; it != cards.end(); it++ ){
|
||||
MTGCard * current = (*it).first;
|
||||
colors[Constants::MTG_NB_COLORS] += (*it).second;
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++){
|
||||
if (current->data->hasColor(i)) colors[i]+=(*it).second;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
colors[Constants::MTG_NB_COLORS] += increment;
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++){
|
||||
if (card->data->hasColor(i)) colors[i]+=increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int DeckDataWrapper::Add(MTGCard * card, int quantity){
|
||||
if(cards.find(card) == cards.end()){
|
||||
cards[card] = quantity;
|
||||
}else{
|
||||
cards[card]+= quantity;
|
||||
}
|
||||
updateCounts(card,quantity);
|
||||
return cards[card];
|
||||
}
|
||||
|
||||
int DeckDataWrapper::Remove(MTGCard * card){
|
||||
if(cards.find(card) == cards.end() || cards[card] <= 0) return 0;
|
||||
cards[card]--;
|
||||
updateCounts(card,-1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DeckDataWrapper::count(MTGCard * card){
|
||||
if(cards.find(card) == cards.end()){
|
||||
cards[card] = 0;
|
||||
}
|
||||
return cards[card];
|
||||
}
|
||||
|
||||
int DeckDataWrapper::countByName(MTGCard * card){
|
||||
string name = card->data->name;
|
||||
int total = 0;
|
||||
map<MTGCard *,int,Cmp1>::iterator it,it_origin;
|
||||
it = cards.find(card);
|
||||
if(it == cards.end()){
|
||||
cards[card] = 0;
|
||||
it = cards.find(card);
|
||||
}
|
||||
it_origin = it;
|
||||
|
||||
while(it !=cards.end()){
|
||||
MTGCard * _card = (*it).first;
|
||||
if (name.compare(_card->data->name) !=0){
|
||||
it = cards.end();
|
||||
}else{
|
||||
total+= (*it).second;
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
it = cards.find(card);
|
||||
if (it == cards.begin()) return total;
|
||||
it--;
|
||||
while(1){
|
||||
MTGCard * _card = (*it).first;
|
||||
if (name.compare(_card->data->name) !=0){
|
||||
break;
|
||||
}else{
|
||||
total+= (*it).second;
|
||||
if (it == cards.begin()) break;
|
||||
it--;
|
||||
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
MTGCard * DeckDataWrapper::getNext(MTGCard * previous, int color){
|
||||
map<MTGCard *,int,Cmp1>::iterator it;
|
||||
|
||||
it = cards.find(previous);
|
||||
|
||||
while(1){
|
||||
if (it == cards.end()){
|
||||
it = cards.begin();
|
||||
}else{
|
||||
it++;
|
||||
}
|
||||
if (it == cards.end()) return NULL;
|
||||
MTGCard * card = (*it).first;
|
||||
if (card == previous) return NULL;
|
||||
if ((*it).second >0 && (color ==-1 || card->data->hasColor(color))){
|
||||
return card;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MTGCard * DeckDataWrapper::getPrevious(MTGCard * next, int color){
|
||||
map<MTGCard *,int,Cmp1>::iterator it;
|
||||
it = cards.find(next);
|
||||
|
||||
while(1){
|
||||
if (it == cards.begin()){
|
||||
it = cards.end();
|
||||
}else{
|
||||
it--;
|
||||
}
|
||||
if (it == cards.end()) return NULL;
|
||||
MTGCard * card = (*it).first;
|
||||
if (card == next) return NULL;
|
||||
if ((*it).second >0 && (color ==-1 || card->data->hasColor(color))){
|
||||
return card;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int DeckDataWrapper::getCount(int color){
|
||||
if (color == -1) return colors[Constants::MTG_NB_COLORS];
|
||||
return colors[color];
|
||||
}
|
||||
|
||||
int DeckDataWrapper::totalPrice(){
|
||||
int total = 0;
|
||||
PriceList * pricelist = NEW PriceList(RESPATH"/settings/prices.dat",this->parent->database);
|
||||
map<MTGCard *,int,Cmp1>::iterator it;
|
||||
for ( it=cards.begin() ; it != cards.end(); it++ ){
|
||||
MTGCard * current = (*it).first;
|
||||
int nb = (*it).second;
|
||||
if (nb) total += pricelist->getPrice(current->getMTGId());
|
||||
}
|
||||
delete pricelist;
|
||||
return total;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user