All code submission.
mnguyen
Posts: 229 Joined: Thu Apr 29, 2010 4:13 pm
Post
by mnguyen » Sat Sep 18, 2010 4:30 am
Hey all!
I have a small patch that will have the system save the player decks such that there are human readable values for the ids in place. I found that there are times I want to go through my decks and possibly my collection outside the game to make edits/review what I have. Wagic currently converts all the decks and collection.dat into a single column list of just the MTG ids. My patch will add a comment above each group of cards so you know what they are.
Here it is!
Code: Select all
Index: projects/mtg/src/MTGDeck.cpp
===================================================================
--- projects/mtg/src/MTGDeck.cpp (revision 2282)
+++ projects/mtg/src/MTGDeck.cpp (working copy)
@@ -745,8 +745,13 @@
}
map<int,int>::iterator it;
for (it = cards.begin(); it!=cards.end(); it++){
- sprintf(writer,"%i\n", it->first);
- for (int j = 0; j<it->second; j++){
+ int cardId = it->first;
+ int numCopies = it->second;
+ MTGCard* currentCard = getCardById(cardId );
+ MTGSetInfo * setInfo = setlist.getInfo( currentCard->setId );
+ file<< "# " << currentCard->data->getName() << " (" << setInfo->id << ") *" << numCopies <<"\n";
+ sprintf(writer,"%i\n", cardId);
+ for (int j = 0; j < numCopies; j++){
file<<writer;
}
}
mnguyen
Posts: 229 Joined: Thu Apr 29, 2010 4:13 pm
Post
by mnguyen » Sat Sep 18, 2010 4:32 am
I should add an example of what I am talking about.
So instead of this:
Code: Select all
#NAME:Elfball
#DESC:Mono Green Elf deck
#DESC:
109755
122367
122367
129559
129559
129559
129559
129559
129560
129560
129560
129560
129560
129561
129561
129561
129561
129561
129562
129562
129562
129562
129562
130506
130506
130506
139401
139401
139401
139401
139487
139487
139487
139487
139676
139676
139676
139676
139683
139683
139683
139683
157950
157950
157950
158111
158111
158111
158113
158113
158113
158113
189878
189878
189878
189878
194424
194424
194424
194424
You get this:
Code: Select all
#NAME:Elfball
#DESC:Mono Green Elf deck
#DESC:
# Pendelhaven (TSB) *1
109755
# Gaea's Anthem (PLC) *2
122367
122367
# Forest (10E) *5
129559
129559
129559
129559
129559
# Forest (10E) *5
129560
129560
129560
129560
129560
# Forest (10E) *5
129561
129561
129561
129561
129561
# Forest (10E) *5
129562
129562
129562
129562
129562
# Overrun (10E) *3
130506
130506
130506
# Lys Alana Huntmaster (LRW) *4
139401
139401
139401
139401
# Leaf Gilder (LRW) *4
139487
139487
139487
139487
# Elvish Promenade (LRW) *4
139676
139676
139676
139676
# Imperious Perfect (LRW) *4
139683
139683
139683
139683
# Ambush Commander (EVG) *3
157950
157950
157950
# Wirewood Lodge (EVG) *3
158111
158111
158111
# Heedless One (EVG) *4
158113
158113
158113
158113
# Llanowar Elves (M10) *4
189878
189878
189878
189878
# Elvish Visionary (M10) *4
194424
194424
194424
194424
wololo
Site Admin
Posts: 3728 Joined: Wed Oct 15, 2008 12:42 am
Location: Japan
Post
by wololo » Sat Sep 18, 2010 8:55 am
Great, but why did you make those a comment instead of directly using them as the values?
The reason we save as ints so far is because it was "easier", but if you went through the hassle of retrieving the information by id, then go ahead, get rid of the IDs, and uncomment the "human readable" version
for example, instead of:
# Forest (10E) *5
129559
129559
129559
129559
129559
just save as
Forest (10E) *5
mnguyen
Posts: 229 Joined: Thu Apr 29, 2010 4:13 pm
Post
by mnguyen » Sat Sep 18, 2010 2:55 pm
i wasn't sure if this would impact the performance of loading the collection.dat file. You seem to think it's okay. So here's the amended patch:
Code: Select all
Index: projects/mtg/src/MTGDeck.cpp
===================================================================
--- projects/mtg/src/MTGDeck.cpp (revision 2290)
+++ projects/mtg/src/MTGDeck.cpp (working copy)
@@ -724,7 +724,6 @@
string tmp = filename;
tmp.append(".tmp"); //not thread safe
std::ofstream file(tmp.c_str());
- char writer[512];
if (file){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("saving");
@@ -746,10 +745,11 @@
}
map<int,int>::iterator it;
for (it = cards.begin(); it!=cards.end(); it++){
- sprintf(writer,"%i\n", it->first);
- for (int j = 0; j<it->second; j++){
- file<<writer;
- }
+ int cardId = it->first;
+ int numCopies = it->second;
+ MTGCard* currentCard = getCardById(cardId );
+ MTGSetInfo * setInfo = setlist.getInfo( currentCard->setId );
+ file<< currentCard->data->getName() << " (" << setInfo->id << ") *" << numCopies << "\n";
}
file.close();
std::remove(filename.c_str());
I put here in case for convenience for users:
http://www.forevernow.net/wagic/2010091 ... save.patch
wololo
Site Admin
Posts: 3728 Joined: Wed Oct 15, 2008 12:42 am
Location: Japan
Post
by wololo » Sat Sep 18, 2010 11:34 pm
You're right, I probably need to double check with the entire collection on a psp. I'll try that., we might need to create a special case for that file... (then again, this one would be even better as a binary if we care about speed)
mnguyen
Posts: 229 Joined: Thu Apr 29, 2010 4:13 pm
Post
by mnguyen » Sun Sep 19, 2010 3:12 am
maybe we do binary on the psp and whatever on the PC. If the majority of Wagic PSP players are on the phat, (me included) perhaps we should consider this?