Commit 1b59f4c6 authored by mercury233's avatar mercury233 Committed by GitHub

support search part of setname (#2546)

parent 07614071
...@@ -14,6 +14,14 @@ using CardData = card_data; ...@@ -14,6 +14,14 @@ using CardData = card_data;
struct CardDataC : card_data { struct CardDataC : card_data {
unsigned int ot{}; unsigned int ot{};
unsigned int category{}; unsigned int category{};
bool is_setcodes(std::vector <uint32> values) const {
for (auto& value : values) {
if (is_setcode(value))
return true;
}
return false;
}
}; };
struct CardString { struct CardString {
std::wstring name; std::wstring name;
......
...@@ -267,13 +267,22 @@ const wchar_t* DataManager::GetSetName(int code) { ...@@ -267,13 +267,22 @@ const wchar_t* DataManager::GetSetName(int code) {
return NULL; return NULL;
return csit->second.c_str(); return csit->second.c_str();
} }
unsigned int DataManager::GetSetCode(const wchar_t* setname) { std::vector<unsigned int> DataManager::GetSetCodes(std::wstring setname) {
std::vector<unsigned int> matchingCodes;
for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit) { for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit) {
auto xpos = csit->second.find_first_of(L'|');//setname|another setname or extra info auto xpos = csit->second.find_first_of(L'|');//setname|another setname or extra info
if(csit->second.compare(0, xpos, setname) == 0 || csit->second.compare(xpos + 1, csit->second.length(), setname) == 0) if(setname.size() < 2) {
return csit->first; if(csit->second.compare(0, xpos, setname) == 0
|| csit->second.compare(xpos + 1, csit->second.length(), setname) == 0)
matchingCodes.push_back(csit->first);
} else {
if(csit->second.substr(0, xpos).find(setname) != std::wstring::npos
|| csit->second.substr(xpos + 1).find(setname) != std::wstring::npos) {
matchingCodes.push_back(csit->first);
} }
return 0; }
}
return matchingCodes;
} }
const wchar_t* DataManager::GetNumString(int num, bool bracket) { const wchar_t* DataManager::GetNumString(int num, bool bracket) {
if(!bracket) if(!bracket)
......
...@@ -30,7 +30,7 @@ public: ...@@ -30,7 +30,7 @@ public:
const wchar_t* GetVictoryString(int code); const wchar_t* GetVictoryString(int code);
const wchar_t* GetCounterName(int code); const wchar_t* GetCounterName(int code);
const wchar_t* GetSetName(int code); const wchar_t* GetSetName(int code);
unsigned int GetSetCode(const wchar_t* setname); std::vector<unsigned int> GetSetCodes(std::wstring setname);
const wchar_t* GetNumString(int num, bool bracket = false); const wchar_t* GetNumString(int num, bool bracket = false);
const wchar_t* FormatLocation(int location, int sequence); const wchar_t* FormatLocation(int location, int sequence);
const wchar_t* FormatAttribute(int attribute); const wchar_t* FormatAttribute(int attribute);
......
...@@ -1337,14 +1337,14 @@ void DeckBuilder::FilterCards() { ...@@ -1337,14 +1337,14 @@ void DeckBuilder::FilterCards() {
results.clear(); results.clear();
struct element_t { struct element_t {
std::wstring keyword; std::wstring keyword;
unsigned int setcode; std::vector<unsigned int> setcodes;
enum class type_t { enum class type_t {
all, all,
name, name,
setcode setcode
} type; } type;
bool exclude; bool exclude;
element_t(): setcode(0), type(type_t::all), exclude(false) {} element_t(): type(type_t::all), exclude(false) {}
}; };
const wchar_t* pstr = mainGame->ebCardName->getText(); const wchar_t* pstr = mainGame->ebCardName->getText();
std::wstring str = std::wstring(pstr); std::wstring str = std::wstring(pstr);
...@@ -1385,7 +1385,7 @@ void DeckBuilder::FilterCards() { ...@@ -1385,7 +1385,7 @@ void DeckBuilder::FilterCards() {
element.keyword = str.substr(element_start, length); element.keyword = str.substr(element_start, length);
} else } else
element.keyword = str.substr(element_start); element.keyword = str.substr(element_start);
element.setcode = dataManager.GetSetCode(element.keyword.c_str()); element.setcodes = dataManager.GetSetCodes(element.keyword);
query_elements.push_back(element); query_elements.push_back(element);
if(element_end == std::wstring::npos) if(element_end == std::wstring::npos)
break; break;
...@@ -1403,7 +1403,7 @@ void DeckBuilder::FilterCards() { ...@@ -1403,7 +1403,7 @@ void DeckBuilder::FilterCards() {
} }
if(element_start < str.size()) { if(element_start < str.size()) {
element.keyword = str.substr(element_start); element.keyword = str.substr(element_start);
element.setcode = dataManager.GetSetCode(element.keyword.c_str()); element.setcodes = dataManager.GetSetCodes(element.keyword);
query_elements.push_back(element); query_elements.push_back(element);
} }
} }
...@@ -1490,14 +1490,14 @@ void DeckBuilder::FilterCards() { ...@@ -1490,14 +1490,14 @@ void DeckBuilder::FilterCards() {
if (elements_iterator->type == element_t::type_t::name) { if (elements_iterator->type == element_t::type_t::name) {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str()); match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str());
} else if (elements_iterator->type == element_t::type_t::setcode) { } else if (elements_iterator->type == element_t::type_t::setcode) {
match = elements_iterator->setcode && data.is_setcode(elements_iterator->setcode); match = data.is_setcodes(elements_iterator->setcodes);
} else { } else {
int trycode = BufferIO::GetVal(elements_iterator->keyword.c_str()); int trycode = BufferIO::GetVal(elements_iterator->keyword.c_str());
bool tryresult = dataManager.GetData(trycode, 0); bool tryresult = dataManager.GetData(trycode, 0);
if(!tryresult) { if(!tryresult) {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str()) match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str())
|| text.text.find(elements_iterator->keyword) != std::wstring::npos || text.text.find(elements_iterator->keyword) != std::wstring::npos
|| (elements_iterator->setcode && data.is_setcode(elements_iterator->setcode)); || data.is_setcodes(elements_iterator->setcodes);
} else { } else {
match = data.code == trycode || data.alias == trycode; match = data.code == trycode || data.alias == trycode;
} }
......
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