Commit 842c7a08 authored by VanillaSalt's avatar VanillaSalt

use std::wstring

parent 85f83185
......@@ -89,28 +89,20 @@ bool DataManager::LoadStrings(const char* file) {
sscanf(linebuf, "!%s", strbuf);
if(!strcmp(strbuf, "system")) {
sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf);
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
_sysStrings[value] = pbuf;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "victory")) {
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf);
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
_victoryStrings[value] = pbuf;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "counter")) {
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf);
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
_counterStrings[value] = pbuf;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "setname")) {
sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf);//using tab for comment
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
_setnameStrings[value] = pbuf;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer;
}
}
fclose(fp);
......@@ -175,33 +167,35 @@ const wchar_t* DataManager::GetDesc(int strCode) {
return unknown_string;
}
const wchar_t* DataManager::GetSysString(int code) {
if(code < 0 || code >= 2048 || _sysStrings[code] == 0)
if(code < 0 || code >= 2048)
return unknown_string;
return _sysStrings[code];
auto csit = _sysStrings.find(code);
if(csit == _sysStrings.end())
return unknown_string;
return csit->second.c_str();
}
const wchar_t* DataManager::GetVictoryString(int code) {
auto csit = _victoryStrings.find(code);
if(csit == _victoryStrings.end())
return unknown_string;
return csit->second;
return csit->second.c_str();
}
const wchar_t* DataManager::GetCounterName(int code) {
auto csit = _counterStrings.find(code);
if(csit == _counterStrings.end())
return unknown_string;
return csit->second;
return csit->second.c_str();
}
const wchar_t* DataManager::GetSetName(int code) {
auto csit = _setnameStrings.find(code);
if(csit == _setnameStrings.end())
return NULL;
return csit->second;
return csit->second.c_str();
}
unsigned int DataManager::GetSetCode(const wchar_t* setname) {
wchar_t strbuff[256];
for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit) {
swscanf(csit->second, L"%[^|]", strbuff);//setname|extra info
if(wcscmp(strbuff, setname) == 0)
auto xpos = csit->second.find_first_of(L'|');//setname|extra info
if(csit->second.compare(0, xpos, setname) == 0)
return csit->first;
}
return 0;
......
......@@ -35,11 +35,11 @@ public:
std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings;
std::unordered_map<unsigned int, wchar_t*> _counterStrings;
std::unordered_map<unsigned int, wchar_t*> _victoryStrings;
std::unordered_map<unsigned int, wchar_t*> _setnameStrings;
std::unordered_map<unsigned int, std::wstring> _counterStrings;
std::unordered_map<unsigned int, std::wstring> _victoryStrings;
std::unordered_map<unsigned int, std::wstring> _setnameStrings;
std::unordered_map<unsigned int, std::wstring> _sysStrings;
wchar_t* _sysStrings[2048];
wchar_t numStrings[256][4];
wchar_t numBuffer[6];
wchar_t attBuffer[128];
......@@ -51,7 +51,7 @@ public:
static wchar_t strBuffer[4096];
static const wchar_t* unknown_string;
static int CardReader(int, void*);
};
extern DataManager dataManager;
......
......@@ -46,8 +46,6 @@ bool Game::Initialize() {
is_building = false;
memset(&dInfo, 0, sizeof(DuelInfo));
memset(chatTiming, 0, sizeof(chatTiming));
for(int i = 0; i < 2048; ++i)
dataManager._sysStrings[i] = 0;
deckManager.LoadLFList();
driver = device->getVideoDriver();
driver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS, false);
......
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