Commit 8e1826a8 authored by VanillaSalt's avatar VanillaSalt

add search operator " and -

parent dc47725f
......@@ -775,42 +775,78 @@ void DeckBuilder::StartFilter() {
}
void DeckBuilder::FilterCards() {
results.clear();
struct element_t {
std::wstring keyword;
int setcode;
enum class type_t {
all,
name,
setcode
} type;
bool exclude;
element_t(): setcode(0), type(type_t::all), exclude(false) {}
};
const wchar_t* pstr = mainGame->ebCardName->getText();
std::wstring str = std::wstring(pstr);
std::vector<std::wstring> query_elements;
std::vector<std::vector<std::wstring>::iterator> query_elements_track;
size_t element_start = 0;
while(mainGame->gameConf.search_multiple_keywords) {
size_t element_end = str.find_first_of(mainGame->gameConf.search_multiple_keywords == 1 ? L' ' : L'+', element_start);
if(element_end == std::wstring::npos)
break;
size_t length = element_end - element_start;
if(length > 0) {
query_elements.push_back(str.substr(element_start, length));
std::vector<element_t> query_elements;
if(mainGame->gameConf.search_multiple_keywords) {
const wchar_t separator = mainGame->gameConf.search_multiple_keywords == 1 ? L' ' : L'+';
const wchar_t minussign = L'-';
const wchar_t quotation = L'\"';
size_t element_start = 0;
for(;;) {
element_start = str.find_first_not_of(separator, element_start);
if(element_start == std::wstring::npos)
break;
element_t element;
if(str[element_start] == minussign) {
element.exclude = true;
element_start++;
}
if(element_start >= str.size())
break;
if(str[element_start] == L'$') {
element.type = element_t::type_t::name;
element_start++;
} else if(str[element_start] == L'@') {
element.type = element_t::type_t::setcode;
element_start++;
}
if(element_start >= str.size())
break;
wchar_t delimiter = separator;
if(str[element_start] == quotation) {
delimiter = quotation;
element_start++;
}
size_t element_end = str.find_first_of(delimiter, element_start);
if(element_end != std::wstring::npos) {
size_t length = element_end - element_start;
element.keyword = str.substr(element_start, length);
} else
element.keyword = str.substr(element_start);
element.setcode = dataManager.GetSetCode(element.keyword.c_str());
query_elements.push_back(element);
if(element_end == std::wstring::npos)
break;
element_start = element_end + 1;
} else
}
} else {
element_t element;
size_t element_start = 0;
if(str[element_start] == L'$') {
element.type = element_t::type_t::name;
element_start++;
} else if(str[element_start] == L'@') {
element.type = element_t::type_t::setcode;
element_start++;
}
if(element_start < str.size()) {
element.setcode = dataManager.GetSetCode(element.keyword.c_str());
element.keyword = str.substr(element_start);
query_elements.push_back(element);
}
}
query_elements.push_back(str.substr(element_start));
std::unordered_map<std::wstring, unsigned int> set_code_map;
for(auto elements_iterator = query_elements.begin(); elements_iterator != query_elements.end(); elements_iterator++) {
const wchar_t* element_pointer = elements_iterator->c_str();
if(element_pointer[0] == L'@')
set_code_map[*elements_iterator] = dataManager.GetSetCode(&element_pointer[1]);
else
set_code_map[*elements_iterator] = dataManager.GetSetCode(&element_pointer[0]);
if(element_pointer[0] == 0 || (element_pointer[0] == L'$' && element_pointer[1] == 0) || (element_pointer[0] == L'@' && element_pointer[1] == 0))
query_elements_track.push_back(elements_iterator);
}
for(auto elements_track_iterator = query_elements_track.begin(); elements_track_iterator != query_elements_track.end(); elements_track_iterator++)
query_elements.erase(*elements_track_iterator);
unsigned int set_code = 0;
if(pstr[0] == L'@')
set_code = dataManager.GetSetCode(&pstr[1]);
else
set_code = dataManager.GetSetCode(&pstr[0]);
if(pstr[0] == 0 || (pstr[0] == L'$' && pstr[1] == 0) || (pstr[0] == L'@' && pstr[1] == 0))
pstr = 0;
auto strpointer = dataManager._strings.begin();
for(code_pointer ptr = dataManager._datas.begin(); ptr != dataManager._datas.end(); ++ptr, ++strpointer) {
const CardDataC& data = ptr->second;
......@@ -885,33 +921,29 @@ void DeckBuilder::FilterCards() {
continue;
}
bool is_target = true;
for (auto elements_iterator = query_elements.begin(); elements_iterator != query_elements.end(); elements_iterator++) {
const wchar_t* element_pointer = elements_iterator->c_str();
if (element_pointer[0] == L'$') {
if(!CardNameContains(text.name.c_str(), &element_pointer[1])){
is_target = false;
break;
}
}
else if (element_pointer[0] == L'@' && set_code_map[*elements_iterator]) {
if(!check_set_code(data, set_code_map[*elements_iterator])) {
is_target = false;
break;
}
for (auto elements_iterator = query_elements.begin(); elements_iterator != query_elements.end(); ++elements_iterator) {
bool match = false;
if (elements_iterator->type == element_t::type_t::name) {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str());
} else if (elements_iterator->type == element_t::type_t::setcode) {
match = elements_iterator->setcode && check_set_code(data, elements_iterator->setcode);
} else {
int trycode = BufferIO::GetVal(elements_iterator->c_str());
int trycode = BufferIO::GetVal(elements_iterator->keyword.c_str());
bool tryresult = dataManager.GetData(trycode, 0);
if(!tryresult && !CardNameContains(text.name.c_str(), elements_iterator->c_str()) && text.text.find(elements_iterator->c_str()) == std::wstring::npos
&& (!set_code_map[*elements_iterator] || !check_set_code(data, set_code_map[*elements_iterator]))) {
is_target = false;
break;
}
if(tryresult && data.code != trycode
&& !(data.alias == trycode && (data.alias - data.code < CARD_ARTWORK_VERSIONS_OFFSET || data.code - data.alias < CARD_ARTWORK_VERSIONS_OFFSET))) {
is_target = false;
break;
if(!tryresult) {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str())
|| text.text.find(elements_iterator->keyword) != std::wstring::npos
|| (elements_iterator->setcode && check_set_code(data, elements_iterator->setcode));
} else {
match = data.code == trycode || data.alias == trycode;
}
}
if(elements_iterator->exclude)
match = !match;
if(!match) {
is_target = false;
break;
}
}
if(is_target)
results.push_back(ptr);
......
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