Commit d921cd0f authored by Chen Bill's avatar Chen Bill Committed by GitHub

DataManager: change unknown_string, FileSystem to instance member (#2907)

parent 17715fe4
...@@ -455,7 +455,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -455,7 +455,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
// text // text
wchar_t formatBuffer[2048]; wchar_t formatBuffer[2048];
if(conti_selecting) if(conti_selecting)
myswprintf(formatBuffer, L"%ls", DataManager::unknown_string); myswprintf(formatBuffer, L"%ls", dataManager.unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE) else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0)); myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
else if(selectable_cards[i]->location == LOCATION_OVERLAY) else if(selectable_cards[i]->location == LOCATION_OVERLAY)
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
namespace ygo { namespace ygo {
const wchar_t* DataManager::unknown_string = L"???";
unsigned char DataManager::scriptBuffer[0x100000] = {}; unsigned char DataManager::scriptBuffer[0x100000] = {};
irr::io::IFileSystem* DataManager::FileSystem = nullptr;
DataManager dataManager; DataManager dataManager;
DataManager::DataManager() : _datas(32768), _strings(32768) { DataManager::DataManager() : _datas(32768), _strings(32768) {
...@@ -403,9 +401,9 @@ unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* sl ...@@ -403,9 +401,9 @@ unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* sl
#ifdef _WIN32 #ifdef _WIN32
wchar_t fname[256]{}; wchar_t fname[256]{};
BufferIO::DecodeUTF8(script_name, fname); BufferIO::DecodeUTF8(script_name, fname);
auto reader = FileSystem->createAndOpenFile(fname); auto reader = dataManager.FileSystem->createAndOpenFile(fname);
#else #else
auto reader = FileSystem->createAndOpenFile(script_name); auto reader = dataManager.FileSystem->createAndOpenFile(script_name);
#endif #endif
if (!reader) if (!reader)
return nullptr; return nullptr;
......
...@@ -97,9 +97,10 @@ public: ...@@ -97,9 +97,10 @@ public:
std::unordered_map<unsigned int, std::wstring> _setnameStrings; std::unordered_map<unsigned int, std::wstring> _setnameStrings;
std::unordered_map<unsigned int, std::wstring> _sysStrings; std::unordered_map<unsigned int, std::wstring> _sysStrings;
char errmsg[512]{}; char errmsg[512]{};
const wchar_t* unknown_string{ L"???" };
irr::io::IFileSystem* FileSystem{};
static unsigned char scriptBuffer[0x100000]; static unsigned char scriptBuffer[0x100000];
static const wchar_t* unknown_string;
static uint32_t CardReader(uint32_t, card_data*); static uint32_t CardReader(uint32_t, card_data*);
static unsigned char* ScriptReaderEx(const char* script_path, int* slen); static unsigned char* ScriptReaderEx(const char* script_path, int* slen);
...@@ -108,8 +109,6 @@ public: ...@@ -108,8 +109,6 @@ public:
//read by fread //read by fread
static unsigned char* ReadScriptFromFile(const char* script_name, int* slen); static unsigned char* ReadScriptFromFile(const char* script_name, int* slen);
static irr::io::IFileSystem* FileSystem;
static bool deck_sort_lv(code_pointer l1, code_pointer l2); static bool deck_sort_lv(code_pointer l1, code_pointer l2);
static bool deck_sort_atk(code_pointer l1, code_pointer l2); static bool deck_sort_atk(code_pointer l1, code_pointer l2);
static bool deck_sort_def(code_pointer l1, code_pointer l2); static bool deck_sort_def(code_pointer l1, code_pointer l2);
......
...@@ -280,11 +280,11 @@ FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) { ...@@ -280,11 +280,11 @@ FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
} }
irr::io::IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) { irr::io::IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) {
#ifdef _WIN32 #ifdef _WIN32
auto reader = DataManager::FileSystem->createAndOpenFile(file); auto reader = dataManager.FileSystem->createAndOpenFile(file);
#else #else
char file2[256]; char file2[256];
BufferIO::EncodeUTF8(file, file2); BufferIO::EncodeUTF8(file, file2);
auto reader = DataManager::FileSystem->createAndOpenFile(file2); auto reader = dataManager.FileSystem->createAndOpenFile(file2);
#endif #endif
return reader; return reader;
} }
......
...@@ -906,7 +906,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -906,7 +906,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, L""); myswprintf(formatBuffer, L"");
} else { } else {
if(conti_selecting) if(conti_selecting)
myswprintf(formatBuffer, L"%ls", DataManager::unknown_string); myswprintf(formatBuffer, L"%ls", dataManager.unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE) else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0)); myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
else if(selectable_cards[i + pos]->location == LOCATION_OVERLAY) else if(selectable_cards[i + pos]->location == LOCATION_OVERLAY)
......
...@@ -76,7 +76,7 @@ bool Game::Initialize() { ...@@ -76,7 +76,7 @@ bool Game::Initialize() {
ErrorLog("Failed to load textures!"); ErrorLog("Failed to load textures!");
return false; return false;
} }
DataManager::FileSystem = device->getFileSystem(); dataManager.FileSystem = device->getFileSystem();
if(!dataManager.LoadDB(L"cards.cdb")) { if(!dataManager.LoadDB(L"cards.cdb")) {
ErrorLog("Failed to load card database (cards.cdb)!"); ErrorLog("Failed to load card database (cards.cdb)!");
return false; return false;
...@@ -1145,17 +1145,17 @@ void Game::LoadExpansions() { ...@@ -1145,17 +1145,17 @@ void Game::LoadExpansions() {
} }
if (IsExtension(name, L".zip") || IsExtension(name, L".ypk")) { if (IsExtension(name, L".zip") || IsExtension(name, L".ypk")) {
#ifdef _WIN32 #ifdef _WIN32
DataManager::FileSystem->addFileArchive(fpath, true, false, irr::io::EFAT_ZIP); dataManager.FileSystem->addFileArchive(fpath, true, false, irr::io::EFAT_ZIP);
#else #else
char upath[1024]; char upath[1024];
BufferIO::EncodeUTF8(fpath, upath); BufferIO::EncodeUTF8(fpath, upath);
DataManager::FileSystem->addFileArchive(upath, true, false, irr::io::EFAT_ZIP); dataManager.FileSystem->addFileArchive(upath, true, false, irr::io::EFAT_ZIP);
#endif #endif
return; return;
} }
}); });
for(irr::u32 i = 0; i < DataManager::FileSystem->getFileArchiveCount(); ++i) { for(irr::u32 i = 0; i < dataManager.FileSystem->getFileArchiveCount(); ++i) {
auto archive = DataManager::FileSystem->getFileArchive(i)->getFileList(); auto archive = dataManager.FileSystem->getFileArchive(i)->getFileList();
for(irr::u32 j = 0; j < archive->getFileCount(); ++j) { for(irr::u32 j = 0; j < archive->getFileCount(); ++j) {
#ifdef _WIN32 #ifdef _WIN32
const wchar_t* fname = archive->getFullFileName(j).c_str(); const wchar_t* fname = archive->getFullFileName(j).c_str();
...@@ -1170,9 +1170,9 @@ void Game::LoadExpansions() { ...@@ -1170,9 +1170,9 @@ void Game::LoadExpansions() {
} }
if (IsExtension(fname, L".conf")) { if (IsExtension(fname, L".conf")) {
#ifdef _WIN32 #ifdef _WIN32
auto reader = DataManager::FileSystem->createAndOpenFile(fname); auto reader = dataManager.FileSystem->createAndOpenFile(fname);
#else #else
auto reader = DataManager::FileSystem->createAndOpenFile(uname); auto reader = dataManager.FileSystem->createAndOpenFile(uname);
#endif #endif
dataManager.LoadStrings(reader); dataManager.LoadStrings(reader);
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