Commit b57b331b authored by Chen Bill's avatar Chen Bill Committed by GitHub

move struct CardDataC, deck sort functions to data_manager.h (#2647)

* move struct CardDataC to data_manager.h

* update struct CardDataC

* move deck sort functions to DataManager

* update DeckBuilder::filter_effect
parent 578afd6b
#include "client_card.h"
#include "client_field.h"
#include "data_manager.h"
#include "game.h"
namespace ygo {
......@@ -244,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,35 +2,12 @@
#define CLIENT_CARD_H
#include "config.h"
#include "../ocgcore/card_data.h"
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
namespace ygo {
using CardData = card_data;
struct CardDataC : card_data {
unsigned int ot{};
unsigned int category{};
bool is_setcodes(std::vector <uint32_t> values) const {
for (auto& value : values) {
if (is_setcode(value))
return true;
}
return false;
}
};
struct CardString {
std::wstring name;
std::wstring text;
std::wstring desc[16];
};
typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer;
typedef std::unordered_map<unsigned int, CardString>::const_iterator string_pointer;
class ClientCard {
public:
irr::core::matrix4 mTransform;
......@@ -103,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);
};
}
......
......@@ -7,7 +7,7 @@ namespace ygo {
const wchar_t* DataManager::unknown_string = L"???";
unsigned char DataManager::scriptBuffer[0x100000] = {};
IFileSystem* DataManager::FileSystem = nullptr;
irr::io::IFileSystem* DataManager::FileSystem = nullptr;
DataManager dataManager;
DataManager::DataManager() : _datas(32768), _strings(32768) {
......@@ -119,7 +119,7 @@ bool DataManager::LoadStrings(const char* file) {
fclose(fp);
return true;
}
bool DataManager::LoadStrings(IReadFile* reader) {
bool DataManager::LoadStrings(irr::io::IReadFile* reader) {
char ch{};
std::string linebuf;
while (reader->read(&ch, 1)) {
......@@ -442,5 +442,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;
}
}
#ifndef DATAMANAGER_H
#define DATAMANAGER_H
#include "config.h"
#include <unordered_map>
#include <vector>
#include <string>
#include <sqlite3.h>
#include "client_card.h"
#include "../ocgcore/card_data.h"
namespace irr {
namespace io {
class IReadFile;
class IFileSystem;
}
}
namespace ygo {
constexpr int MAX_STRING_ID = 0x7ff;
constexpr unsigned int MIN_CARD_ID = (unsigned int)(MAX_STRING_ID + 1) >> 4;
constexpr int MAX_STRING_ID = 0x7ff;
constexpr unsigned int MIN_CARD_ID = (unsigned int)(MAX_STRING_ID + 1) >> 4;
using CardData = card_data;
struct CardDataC : card_data {
uint32_t ot{};
uint32_t category{};
bool is_setcodes(std::vector <uint32_t> values) const {
for (auto& value : values) {
if (is_setcode(value))
return true;
}
return false;
}
};
struct CardString {
std::wstring name;
std::wstring text;
std::wstring desc[16];
};
using code_pointer = std::unordered_map<unsigned int, CardDataC>::const_iterator;
using string_pointer = std::unordered_map<unsigned int, CardString>::const_iterator;
class DataManager {
public:
......@@ -16,7 +45,7 @@ public:
bool ReadDB(sqlite3* pDB);
bool LoadDB(const wchar_t* wfile);
bool LoadStrings(const char* file);
bool LoadStrings(IReadFile* reader);
bool LoadStrings(irr::io::IReadFile* reader);
void ReadStringConfLine(const char* linebuf);
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = nullptr);
......@@ -60,7 +89,12 @@ public:
//read by fread
static unsigned char* DefaultScriptReader(const char* script_name, int* slen);
static IFileSystem* FileSystem;
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;
......
......@@ -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 {
......@@ -41,7 +41,7 @@ public:
void pop_side(int seq);
bool check_limit(code_pointer pointer);
long long filter_effect{};
unsigned long long filter_effect{};
unsigned int filter_type{};
unsigned int filter_type2{};
unsigned int filter_attrib{};
......
#include "deck_manager.h"
#include "myfilesystem.h"
#include "data_manager.h"
#include "network.h"
#include "game.h"
......
......@@ -2,7 +2,7 @@
#define DECKMANAGER_H
#include "config.h"
#include "client_card.h"
#include "data_manager.h"
#include <unordered_map>
#include <vector>
#include <sstream>
......
#include "game.h"
#include "client_card.h"
#include "materials.h"
#include "image_manager.h"
#include "deck_manager.h"
......
#ifndef SINGLE_DUEL_H
#define SINGLE_DUEL_H
#include <set>
#include "network.h"
#include "deck_manager.h"
#include "replay.h"
......
#ifndef TAG_DUEL_H
#define TAG_DUEL_H
#include <set>
#include "network.h"
#include "deck_manager.h"
#include "replay.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