Commit 3cea5c89 authored by Chen Bill's avatar Chen Bill

move deck sort functions to DataManager

parent b02c18a8
......@@ -243,72 +243,4 @@ bool ClientCard::client_card_sort(ClientCard* c1, ClientCard* c2) {
return c1->sequence < c2->sequence;
}
}
bool ClientCard::deck_sort_lv(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
int type1 = (p1->second.type & 0x48020c0) ? (p1->second.type & 0x48020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x48020c0) ? (p2->second.type & 0x48020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
if(p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
if(p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if(p1->second.defense != p2->second.defense)
return p1->second.defense > p2->second.defense;
return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_atk(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
if(p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if(p1->second.defense != p2->second.defense)
return p1->second.defense > p2->second.defense;
if(p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
int type1 = (p1->second.type & 0x48020c0) ? (p1->second.type & 0x48020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x48020c0) ? (p2->second.type & 0x48020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_def(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
if(p1->second.defense != p2->second.defense)
return p1->second.defense > p2->second.defense;
if(p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if(p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
int type1 = (p1->second.type & 0x48020c0) ? (p1->second.type & 0x48020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x48020c0) ? (p2->second.type & 0x48020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_name(code_pointer p1, code_pointer p2) {
const wchar_t* name1 = dataManager.GetName(p1->first);
const wchar_t* name2 = dataManager.GetName(p2->first);
int res = wcscmp(name1, name2);
if(res != 0)
return res < 0;
return p1->first < p2->first;
}
}
......@@ -2,7 +2,6 @@
#define CLIENT_CARD_H
#include "config.h"
#include "data_manager.h"
#include <vector>
#include <set>
#include <map>
......@@ -81,10 +80,6 @@ public:
void ClearTarget();
void ClearData();
static bool client_card_sort(ClientCard* c1, ClientCard* c2);
static bool deck_sort_lv(code_pointer l1, code_pointer l2);
static bool deck_sort_atk(code_pointer l1, code_pointer l2);
static bool deck_sort_def(code_pointer l1, code_pointer l2);
static bool deck_sort_name(code_pointer l1, code_pointer l2);
};
}
......
......@@ -444,5 +444,73 @@ unsigned char* DataManager::DefaultScriptReader(const char* script_name, int* sl
*slen = (int)len;
return scriptBuffer;
}
bool DataManager::deck_sort_lv(code_pointer p1, code_pointer p2) {
if ((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if ((p1->second.type & 0x7) == 1) {
int type1 = (p1->second.type & 0x48020c0) ? (p1->second.type & 0x48020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x48020c0) ? (p2->second.type & 0x48020c1) : (p2->second.type & 0x31);
if (type1 != type2)
return type1 < type2;
if (p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
if (p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if (p1->second.defense != p2->second.defense)
return p1->second.defense > p2->second.defense;
return p1->first < p2->first;
}
if ((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool DataManager::deck_sort_atk(code_pointer p1, code_pointer p2) {
if ((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if ((p1->second.type & 0x7) == 1) {
if (p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if (p1->second.defense != p2->second.defense)
return p1->second.defense > p2->second.defense;
if (p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
int type1 = (p1->second.type & 0x48020c0) ? (p1->second.type & 0x48020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x48020c0) ? (p2->second.type & 0x48020c1) : (p2->second.type & 0x31);
if (type1 != type2)
return type1 < type2;
return p1->first < p2->first;
}
if ((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool DataManager::deck_sort_def(code_pointer p1, code_pointer p2) {
if ((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if ((p1->second.type & 0x7) == 1) {
if (p1->second.defense != p2->second.defense)
return p1->second.defense > p2->second.defense;
if (p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if (p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
int type1 = (p1->second.type & 0x48020c0) ? (p1->second.type & 0x48020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x48020c0) ? (p2->second.type & 0x48020c1) : (p2->second.type & 0x31);
if (type1 != type2)
return type1 < type2;
return p1->first < p2->first;
}
if ((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool DataManager::deck_sort_name(code_pointer p1, code_pointer p2) {
const wchar_t* name1 = dataManager.GetName(p1->first);
const wchar_t* name2 = dataManager.GetName(p2->first);
int res = wcscmp(name1, name2);
if (res != 0)
return res < 0;
return p1->first < p2->first;
}
}
......@@ -91,6 +91,11 @@ public:
static irr::io::IFileSystem* FileSystem;
static bool deck_sort_lv(code_pointer l1, code_pointer l2);
static bool deck_sort_atk(code_pointer l1, code_pointer l2);
static bool deck_sort_def(code_pointer l1, code_pointer l2);
static bool deck_sort_name(code_pointer l1, code_pointer l2);
private:
std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings;
......
......@@ -150,9 +150,9 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_SORT_DECK: {
std::sort(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), ClientCard::deck_sort_lv);
std::sort(deckManager.current_deck.extra.begin(), deckManager.current_deck.extra.end(), ClientCard::deck_sort_lv);
std::sort(deckManager.current_deck.side.begin(), deckManager.current_deck.side.end(), ClientCard::deck_sort_lv);
std::sort(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), DataManager::deck_sort_lv);
std::sort(deckManager.current_deck.extra.begin(), deckManager.current_deck.extra.end(), DataManager::deck_sort_lv);
std::sort(deckManager.current_deck.side.begin(), deckManager.current_deck.side.end(), DataManager::deck_sort_lv);
break;
}
case BUTTON_SHUFFLE_DECK: {
......@@ -1572,16 +1572,16 @@ void DeckBuilder::SortList() {
}
switch(mainGame->cbSortType->getSelected()) {
case 0:
std::sort(left, results.end(), ClientCard::deck_sort_lv);
std::sort(left, results.end(), DataManager::deck_sort_lv);
break;
case 1:
std::sort(left, results.end(), ClientCard::deck_sort_atk);
std::sort(left, results.end(), DataManager::deck_sort_atk);
break;
case 2:
std::sort(left, results.end(), ClientCard::deck_sort_def);
std::sort(left, results.end(), DataManager::deck_sort_def);
break;
case 3:
std::sort(left, results.end(), ClientCard::deck_sort_name);
std::sort(left, results.end(), DataManager::deck_sort_name);
break;
}
}
......
......@@ -4,7 +4,7 @@
#include "config.h"
#include <unordered_map>
#include <vector>
#include "client_card.h"
#include "data_manager.h"
#include "../ocgcore/mtrandom.h"
namespace ygo {
......
#include "game.h"
#include "client_card.h"
#include "materials.h"
#include "image_manager.h"
#include "deck_manager.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment