Commit 4297cb3e authored by Chen Bill's avatar Chen Bill

DataManager: change _datas to private

parent c8fd6335
......@@ -1557,7 +1557,9 @@ void ClientField::UpdateDeclarableList() {
ancard.clear();
for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) {
if(cit->second.name.find(pname) != std::wstring::npos) {
auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings
auto cp = dataManager.GetCodePointer(cit->first);
if (cp == dataManager.datas_end)
continue;
//datas.alias can be double card names or alias
if(is_declarable(cp->second, declare_opcodes)) {
if(pname == cit->second.name || trycode == cit->first) { //exact match or last used
......
......@@ -83,6 +83,8 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
sqlite3_finalize(pStmt);
spmemvfs_close_db(&db);
spmemvfs_env_fini();
datas_begin = _datas.begin();
datas_end = _datas.end();
return true;
}
bool DataManager::LoadStrings(const char* file) {
......
......@@ -36,12 +36,13 @@ public:
const wchar_t* FormatSetName(unsigned long long setcode);
const wchar_t* FormatLinkMarker(int link_marker);
std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings;
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;
code_pointer datas_begin;
code_pointer datas_end;
wchar_t numStrings[301][4];
wchar_t numBuffer[6];
......@@ -57,6 +58,9 @@ public:
static byte* ScriptReaderEx(const char* script_name, int* slen);
static byte* ScriptReader(const char* script_name, int* slen);
static IFileSystem* FileSystem;
private:
std::unordered_map<unsigned int, CardDataC> _datas;
};
extern DataManager dataManager;
......
......@@ -43,8 +43,8 @@ static int parse_filter(const wchar_t* pstr, unsigned int* type) {
static bool check_set_code(const CardDataC& data, int set_code) {
unsigned long long sc = data.setcode;
if (data.alias) {
auto aptr = dataManager._datas.find(data.alias);
if (aptr != dataManager._datas.end())
auto aptr = dataManager.GetCodePointer(data.alias);
if (aptr != dataManager.datas_end)
sc = aptr->second.setcode;
}
bool res = false;
......@@ -1030,7 +1030,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
dragx = event.MouseInput.X;
dragy = event.MouseInput.Y;
draging_pointer = dataManager.GetCodePointer(hovered_code);
if(draging_pointer == dataManager._datas.end())
if(draging_pointer == dataManager.datas_end)
break;
if(hovered_pos == 4) {
if(!check_limit(draging_pointer))
......@@ -1084,7 +1084,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(hovered_pos == 0 || hovered_seq == -1)
break;
auto pointer = dataManager.GetCodePointer(hovered_code);
if(pointer == dataManager._datas.end())
if(pointer == dataManager.datas_end)
break;
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
if(hovered_pos == 1) {
......@@ -1119,7 +1119,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
pop_side(hovered_seq);
} else {
auto pointer = dataManager.GetCodePointer(hovered_code);
if(pointer == dataManager._datas.end())
if(pointer == dataManager.datas_end)
break;
if(!check_limit(pointer))
break;
......@@ -1154,6 +1154,8 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if (is_draging)
break;
auto pointer = dataManager.GetCodePointer(hovered_code);
if (pointer == dataManager.datas_end)
break;
if(!check_limit(pointer))
break;
soundManager.PlaySoundEffect(SOUND_CARD_PICK);
......@@ -1422,7 +1424,7 @@ void DeckBuilder::FilterCards() {
}
}
auto strpointer = dataManager._strings.begin();
for(code_pointer ptr = dataManager._datas.begin(); ptr != dataManager._datas.end(); ++ptr, ++strpointer) {
for(code_pointer ptr = dataManager.datas_begin; ptr != dataManager.datas_end; ++ptr, ++strpointer) {
const CardDataC& data = ptr->second;
const CardString& text = strpointer->second;
if(data.type & TYPE_TOKEN)
......
......@@ -161,7 +161,7 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
else if(cd.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK)) {
if(deck.extra.size() >= 15)
continue;
deck.extra.push_back(dataManager.GetCodePointer(code)); //verified by GetData()
deck.extra.push_back(dataManager.GetCodePointer(code));
} else if(deck.main.size() < 60) {
deck.main.push_back(dataManager.GetCodePointer(code));
}
......@@ -175,7 +175,7 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
if(cd.type & TYPE_TOKEN)
continue;
if(deck.side.size() < 15)
deck.side.push_back(dataManager.GetCodePointer(code)); //verified by GetData()
deck.side.push_back(dataManager.GetCodePointer(code));
}
return errorcode;
}
......
......@@ -1530,8 +1530,8 @@ void Game::ShowCardInfo(int code, bool resize) {
if(!gameConf.hide_setname) {
unsigned long long sc = cd.setcode;
if(cd.alias) {
auto aptr = dataManager._datas.find(cd.alias);
if(aptr != dataManager._datas.end())
auto aptr = dataManager.GetCodePointer(cd.alias);
if(aptr != dataManager.datas_end)
sc = aptr->second.setcode;
}
if(sc) {
......
......@@ -314,11 +314,17 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
for(int i = 0; i < max; ++i) {
int main = replay.ReadInt32();
Deck tmp_deck;
for(int j = 0; j < main; ++j)
tmp_deck.main.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
for (int j = 0; j < main; ++j) {
auto card = dataManager.GetCodePointer(replay.ReadInt32());
if (card != dataManager.datas_end)
tmp_deck.main.push_back(card);
}
int extra = replay.ReadInt32();
for(int j = 0; j < extra; ++j)
tmp_deck.extra.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
for (int j = 0; j < extra; ++j) {
auto card = dataManager.GetCodePointer(replay.ReadInt32());
if (card != dataManager.datas_end)
tmp_deck.extra.push_back(card);
}
FileSystem::SafeFileName(namebuf[i]);
myswprintf(filename, L"deck/%ls-%d %ls.ydk", ex_filename, i + 1, namebuf[i]);
deckManager.SaveDeck(tmp_deck, filename);
......
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