Commit 15d26211 authored by VanillaSalt's avatar VanillaSalt

use wstring

parent 895e6e7a
...@@ -39,9 +39,9 @@ struct CardDataC { ...@@ -39,9 +39,9 @@ struct CardDataC {
unsigned int category; unsigned int category;
}; };
struct CardString { struct CardString {
wchar_t* name; std::wstring name;
wchar_t* text; std::wstring text;
wchar_t* desc[16]; std::wstring desc[16];
}; };
typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer; typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer;
......
...@@ -1370,7 +1370,7 @@ void ClientField::UpdateDeclarableCodeType(bool enter) { ...@@ -1370,7 +1370,7 @@ void ClientField::UpdateDeclarableCodeType(bool enter) {
if(dataManager.GetString(trycode, &cstr) && dataManager.GetData(trycode, &cd) && is_declarable(cd, declarable_type)) { if(dataManager.GetString(trycode, &cstr) && dataManager.GetData(trycode, &cd) && is_declarable(cd, declarable_type)) {
mainGame->lstANCard->clear(); mainGame->lstANCard->clear();
ancard.clear(); ancard.clear();
mainGame->lstANCard->addItem(cstr.name); mainGame->lstANCard->addItem(cstr.name.c_str());
ancard.push_back(trycode); ancard.push_back(trycode);
return; return;
} }
...@@ -1379,15 +1379,15 @@ void ClientField::UpdateDeclarableCodeType(bool enter) { ...@@ -1379,15 +1379,15 @@ void ClientField::UpdateDeclarableCodeType(bool enter) {
mainGame->lstANCard->clear(); mainGame->lstANCard->clear();
ancard.clear(); ancard.clear();
for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) { for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) {
if(wcsstr(cit->second.name, pname) != 0) { if(cit->second.name.find(pname) != std::wstring::npos) {
auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings
//datas.alias can be double card names or alias //datas.alias can be double card names or alias
if(is_declarable(cp->second, declarable_type)) { if(is_declarable(cp->second, declarable_type)) {
if(wcscmp(pname, cit->second.name) == 0) { //exact match if(pname == cit->second.name) { //exact match
mainGame->lstANCard->insertItem(0, cit->second.name, -1); mainGame->lstANCard->insertItem(0, cit->second.name.c_str(), -1);
ancard.insert(ancard.begin(), cit->first); ancard.insert(ancard.begin(), cit->first);
} else { } else {
mainGame->lstANCard->addItem(cit->second.name); mainGame->lstANCard->addItem(cit->second.name.c_str());
ancard.push_back(cit->first); ancard.push_back(cit->first);
} }
} }
...@@ -1402,7 +1402,7 @@ void ClientField::UpdateDeclarableCodeOpcode(bool enter) { ...@@ -1402,7 +1402,7 @@ void ClientField::UpdateDeclarableCodeOpcode(bool enter) {
if(dataManager.GetString(trycode, &cstr) && dataManager.GetData(trycode, &cd) && is_declarable(cd, opcode)) { if(dataManager.GetString(trycode, &cstr) && dataManager.GetData(trycode, &cd) && is_declarable(cd, opcode)) {
mainGame->lstANCard->clear(); mainGame->lstANCard->clear();
ancard.clear(); ancard.clear();
mainGame->lstANCard->addItem(cstr.name); mainGame->lstANCard->addItem(cstr.name.c_str());
ancard.push_back(trycode); ancard.push_back(trycode);
return; return;
} }
...@@ -1411,15 +1411,15 @@ void ClientField::UpdateDeclarableCodeOpcode(bool enter) { ...@@ -1411,15 +1411,15 @@ void ClientField::UpdateDeclarableCodeOpcode(bool enter) {
mainGame->lstANCard->clear(); mainGame->lstANCard->clear();
ancard.clear(); ancard.clear();
for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) { for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) {
if(wcsstr(cit->second.name, pname) != 0) { if(cit->second.name.find(pname) != std::wstring::npos) {
auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings
//datas.alias can be double card names or alias //datas.alias can be double card names or alias
if(is_declarable(cp->second, opcode)) { if(is_declarable(cp->second, opcode)) {
if(wcscmp(pname, cit->second.name) == 0) { //exact match if(pname == cit->second.name) { //exact match
mainGame->lstANCard->insertItem(0, cit->second.name, -1); mainGame->lstANCard->insertItem(0, cit->second.name.c_str(), -1);
ancard.insert(ancard.begin(), cit->first); ancard.insert(ancard.begin(), cit->first);
} else { } else {
mainGame->lstANCard->addItem(cit->second.name); mainGame->lstANCard->addItem(cit->second.name.c_str());
ancard.push_back(cit->first); ancard.push_back(cit->first);
} }
} }
......
...@@ -17,8 +17,7 @@ bool DataManager::LoadDB(const char* file) { ...@@ -17,8 +17,7 @@ bool DataManager::LoadDB(const char* file) {
return Error(pDB); return Error(pDB);
CardDataC cd; CardDataC cd;
CardString cs; CardString cs;
for(int i = 0; i < 16; ++i) cs.desc[i] = 0; int step = 0;
int step = 0, len = 0;
do { do {
step = sqlite3_step(pStmt); step = sqlite3_step(pStmt);
if(step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE) if(step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE)
...@@ -44,27 +43,21 @@ bool DataManager::LoadDB(const char* file) { ...@@ -44,27 +43,21 @@ bool DataManager::LoadDB(const char* file) {
cd.attribute = sqlite3_column_int(pStmt, 9); cd.attribute = sqlite3_column_int(pStmt, 9);
cd.category = sqlite3_column_int(pStmt, 10); cd.category = sqlite3_column_int(pStmt, 10);
_datas.insert(std::make_pair(cd.code, cd)); _datas.insert(std::make_pair(cd.code, cd));
len = BufferIO::DecodeUTF8((const char*)sqlite3_column_text(pStmt, 12), strBuffer); if(const char* text = (const char*)sqlite3_column_text(pStmt, 12)) {
if(len) { BufferIO::DecodeUTF8(text, strBuffer);
cs.name = new wchar_t[len + 1]; cs.name = strBuffer;
memcpy(cs.name, strBuffer, (len + 1)*sizeof(wchar_t));
} else cs.name = 0;
len = BufferIO::DecodeUTF8((const char*)sqlite3_column_text(pStmt, 13), strBuffer);
if(len) {
cs.text = new wchar_t[len + 1];
memcpy(cs.text, strBuffer, (len + 1)*sizeof(wchar_t));
} else {
cs.text = new wchar_t[1];
cs.text[0] = 0;
} }
for(int i = 14; i < 30; ++i) { if(const char* text = (const char*)sqlite3_column_text(pStmt, 13)) {
len = BufferIO::DecodeUTF8((const char*)sqlite3_column_text(pStmt, i), strBuffer); BufferIO::DecodeUTF8(text, strBuffer);
if(len) { cs.text = strBuffer;
cs.desc[i - 14] = new wchar_t[len + 1];
memcpy(cs.desc[i - 14], strBuffer, (len + 1)*sizeof(wchar_t));
} else cs.desc[i - 14] = 0;
} }
_strings.insert(std::make_pair(cd.code, cs)); for(int i = 0; i < 16; ++i) {
if(const char* text = (const char*)sqlite3_column_text(pStmt, i + 14)) {
BufferIO::DecodeUTF8(text, strBuffer);
cs.desc[i] = strBuffer;
}
}
_strings.emplace(cd.code, cs);
} }
} while(step != SQLITE_DONE); } while(step != SQLITE_DONE);
sqlite3_finalize(pStmt); sqlite3_finalize(pStmt);
...@@ -126,8 +119,8 @@ code_pointer DataManager::GetCodePointer(int code) { ...@@ -126,8 +119,8 @@ code_pointer DataManager::GetCodePointer(int code) {
bool DataManager::GetString(int code, CardString* pStr) { bool DataManager::GetString(int code, CardString* pStr) {
auto csit = _strings.find(code); auto csit = _strings.find(code);
if(csit == _strings.end()) { if(csit == _strings.end()) {
pStr->name = (wchar_t*)unknown_string; pStr->name = unknown_string;
pStr->text = (wchar_t*)unknown_string; pStr->text = unknown_string;
return false; return false;
} }
*pStr = csit->second; *pStr = csit->second;
...@@ -137,16 +130,16 @@ const wchar_t* DataManager::GetName(int code) { ...@@ -137,16 +130,16 @@ const wchar_t* DataManager::GetName(int code) {
auto csit = _strings.find(code); auto csit = _strings.find(code);
if(csit == _strings.end()) if(csit == _strings.end())
return unknown_string; return unknown_string;
if(csit->second.name) if(!csit->second.name.empty())
return csit->second.name; return csit->second.name.c_str();
return unknown_string; return unknown_string;
} }
const wchar_t* DataManager::GetText(int code) { const wchar_t* DataManager::GetText(int code) {
auto csit = _strings.find(code); auto csit = _strings.find(code);
if(csit == _strings.end()) if(csit == _strings.end())
return unknown_string; return unknown_string;
if(csit->second.text) if(!csit->second.text.empty())
return csit->second.text; return csit->second.text.c_str();
return unknown_string; return unknown_string;
} }
const wchar_t* DataManager::GetDesc(int strCode) { const wchar_t* DataManager::GetDesc(int strCode) {
...@@ -157,8 +150,8 @@ const wchar_t* DataManager::GetDesc(int strCode) { ...@@ -157,8 +150,8 @@ const wchar_t* DataManager::GetDesc(int strCode) {
auto csit = _strings.find(code); auto csit = _strings.find(code);
if(csit == _strings.end()) if(csit == _strings.end())
return unknown_string; return unknown_string;
if(csit->second.desc[offset]) if(!csit->second.desc[offset].empty())
return csit->second.desc[offset]; return csit->second.desc[offset].c_str();
return unknown_string; return unknown_string;
} }
const wchar_t* DataManager::GetSysString(int code) { const wchar_t* DataManager::GetSysString(int code) {
......
...@@ -848,12 +848,12 @@ void DeckBuilder::FilterCards() { ...@@ -848,12 +848,12 @@ void DeckBuilder::FilterCards() {
} }
if(pstr) { if(pstr) {
if(pstr[0] == L'$') { if(pstr[0] == L'$') {
if(!CardNameContains(text.name, &pstr[1])) if(!CardNameContains(text.name.c_str(), &pstr[1]))
continue; continue;
} else if(pstr[0] == L'@' && set_code) { } else if(pstr[0] == L'@' && set_code) {
if(!check_set_code(data, set_code)) continue; if(!check_set_code(data, set_code)) continue;
} else { } else {
if(!CardNameContains(text.name, pstr) && wcsstr(text.text, pstr) == 0 if(!CardNameContains(text.name.c_str(), pstr) && text.text.find(pstr) == std::wstring::npos
&& (!set_code || !check_set_code(data, set_code))) && (!set_code || !check_set_code(data, set_code)))
continue; continue;
} }
......
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