Commit 848348ca authored by Chen Bill's avatar Chen Bill Committed by GitHub

deckManager: add LoadCurrentDeck, SaveDeckBuffer (#2571)

* update LoadDeck from int array

* update LoadDeck from std::istringstream

* reorder

* rename to LoadCurrentDeck

* akways clear current_deck in LoadCurrentDeck

* reorder

* change LoadDeck from std::istringstream

* set errorcode for TYPE_TOKEN

* use LoadDeck in export deck

* update LoadSide

* fix CheckDeck

* fix LoadLFListSingle

* minor fix

* add SaveDeckBuffer

* fix LoadSide

* update LoadDeck(Deck&, std::istringstream&
parent 080d7781
......@@ -462,7 +462,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
}
for(int i = 0; i < (int)mainGame->lstDecks->getItemCount(); i++) {
if(!mywcsncasecmp(mainGame->lstDecks->getListItem(i), deckname, 256)) {
deckManager.LoadDeck(filepath);
deckManager.LoadCurrentDeck(filepath);
prev_deck = i;
mainGame->cbDBDecks->setSelected(prev_deck);
mainGame->lstDecks->setSelected(prev_deck);
......@@ -496,7 +496,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
ChangeCategory(catesel);
for(int i = 0; i < (int)mainGame->lstDecks->getItemCount(); i++) {
if(!mywcsncasecmp(mainGame->lstDecks->getListItem(i), newdeckname, 256)) {
deckManager.LoadDeck(newfilepath);
deckManager.LoadCurrentDeck(newfilepath);
prev_deck = i;
mainGame->cbDBDecks->setSelected(prev_deck);
mainGame->lstDecks->setSelected(prev_deck);
......@@ -523,7 +523,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(decksel != -1) {
mainGame->lstDecks->setSelected(decksel);
mainGame->cbDBDecks->setSelected(decksel);
deckManager.LoadDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
}
RefreshReadonly(prev_category);
prev_deck = decksel;
......@@ -560,7 +560,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
ChangeCategory(catesel);
for(int i = 0; i < (int)mainGame->lstDecks->getItemCount(); i++) {
if(!mywcsncasecmp(mainGame->lstDecks->getListItem(i), deckname, 256)) {
deckManager.LoadDeck(newfilepath);
deckManager.LoadCurrentDeck(newfilepath);
prev_deck = i;
mainGame->cbDBDecks->setSelected(prev_deck);
mainGame->lstDecks->setSelected(prev_deck);
......@@ -598,7 +598,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
ChangeCategory(catesel);
for(int i = 0; i < (int)mainGame->lstDecks->getItemCount(); i++) {
if(!mywcsncasecmp(mainGame->lstDecks->getListItem(i), deckname, 256)) {
deckManager.LoadDeck(newfilepath);
deckManager.LoadCurrentDeck(newfilepath);
prev_deck = i;
mainGame->cbDBDecks->setSelected(prev_deck);
mainGame->lstDecks->setSelected(prev_deck);
......@@ -651,7 +651,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_SIDE_RELOAD: {
deckManager.LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
break;
}
case BUTTON_BIG_CARD_ORIG_SIZE: {
......@@ -697,7 +697,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
sel = count - 1;
mainGame->cbDBDecks->setSelected(sel);
if(sel != -1)
deckManager.LoadDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->stACMessage->setText(dataManager.GetSysString(1338));
mainGame->PopupElement(mainGame->wACMessage, 20);
prev_deck = sel;
......@@ -711,7 +711,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
ChangeCategory(catesel);
} else if(prev_operation == COMBOBOX_DBDECKS) {
int decksel = mainGame->cbDBDecks->getSelected();
deckManager.LoadDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
prev_deck = decksel;
is_modified = false;
} else if(prev_operation == BUTTON_MANAGE_DECK) {
......@@ -828,7 +828,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
}
int decksel = mainGame->cbDBDecks->getSelected();
if(decksel >= 0) {
deckManager.LoadDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
}
prev_deck = decksel;
is_modified = false;
......@@ -987,7 +987,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
wchar_t catepath[256];
deckManager.GetCategoryPath(catepath, mainGame->lstCategories->getSelected(), mainGame->lstCategories->getListItem(mainGame->lstCategories->getSelected()));
myswprintf(filepath, L"%ls/%ls.ydk", catepath, mainGame->lstDecks->getListItem(decksel));
deckManager.LoadDeck(filepath, showing_pack);
deckManager.LoadCurrentDeck(filepath, showing_pack);
RefreshPackListScroll();
prev_deck = decksel;
break;
......@@ -1634,7 +1634,7 @@ void DeckBuilder::ChangeCategory(int catesel) {
mainGame->RefreshDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->cbDBDecks->setSelected(0);
RefreshReadonly(catesel);
deckManager.LoadDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
is_modified = false;
prev_category = catesel;
prev_deck = 0;
......
This diff is collapsed.
......@@ -48,19 +48,20 @@ public:
const std::unordered_map<int, int>* GetLFListContent(int lfhash);
int CheckDeck(Deck& deck, int lfhash, int rule);
int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_packlist = false);
int LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist = false);
bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec);
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
FILE* OpenDeckFile(const wchar_t* file, const char* mode);
IReadFile* OpenDeckReader(const wchar_t* file);
bool LoadDeck(const wchar_t* file, bool is_packlist = false);
bool LoadDeck(std::istringstream* deckStream, bool is_packlist = false);
bool LoadCurrentDeck(const wchar_t* file, bool is_packlist = false);
bool LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool SaveDeck(Deck& deck, const wchar_t* file);
bool DeleteDeck(const wchar_t* file);
bool CreateCategory(const wchar_t* name);
bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
bool DeleteCategory(const wchar_t* name);
bool SaveDeckBuffer(const int deckbuf[], const wchar_t* name);
};
extern DeckManager deckManager;
......
......@@ -175,7 +175,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
case BUTTON_HP_READY: {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
mainGame->gMutex.lock();
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->env->addMessageBox(L"", dataManager.GetSysString(1406));
......@@ -295,40 +295,40 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
if(mainGame->lstReplayList->getSelected() == -1)
break;
Replay replay;
wchar_t ex_filename[256];
wchar_t namebuf[4][20];
wchar_t filename[256];
wchar_t ex_filename[256]{};
wchar_t namebuf[4][20]{};
wchar_t filename[256]{};
myswprintf(ex_filename, L"%ls", mainGame->lstReplayList->getListItem(mainGame->lstReplayList->getSelected()));
if(!replay.OpenReplay(ex_filename))
break;
const ReplayHeader& rh = replay.pheader;
if(rh.flag & REPLAY_SINGLE_MODE)
break;
int max = (rh.flag & REPLAY_TAG) ? 4 : 2;
int player_count = (rh.flag & REPLAY_TAG) ? 4 : 2;
//player name
for(int i = 0; i < max; ++i)
for(int i = 0; i < player_count; ++i)
replay.ReadName(namebuf[i]);
//skip pre infos
for(int i = 0; i < 4; ++i)
replay.ReadInt32();
//deck
for(int i = 0; i < max; ++i) {
std::vector<int> deckbuf;
for(int i = 0; i < player_count; ++i) {
deckbuf.clear();
int main = replay.ReadInt32();
Deck tmp_deck;
deckbuf.push_back(main);
for (int j = 0; j < main; ++j) {
auto card = dataManager.GetCodePointer(replay.ReadInt32());
if (card != dataManager.datas_end)
tmp_deck.main.push_back(card);
deckbuf.push_back(replay.ReadInt32());
}
int extra = replay.ReadInt32();
deckbuf.push_back(extra);
for (int j = 0; j < extra; ++j) {
auto card = dataManager.GetCodePointer(replay.ReadInt32());
if (card != dataManager.datas_end)
tmp_deck.extra.push_back(card);
deckbuf.push_back(replay.ReadInt32());
}
deckbuf.push_back(0);
FileSystem::SafeFileName(namebuf[i]);
myswprintf(filename, L"deck/%ls-%d %ls.ydk", ex_filename, i + 1, namebuf[i]);
deckManager.SaveDeck(tmp_deck, filename);
deckManager.SaveDeckBuffer(deckbuf.data(), filename);
}
mainGame->stACMessage->setText(dataManager.GetSysString(1335));
mainGame->PopupElement(mainGame->wACMessage, 20);
......@@ -426,7 +426,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
case BUTTON_DECK_EDIT: {
mainGame->RefreshCategoryDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
if(open_file && deckManager.LoadDeck(open_file_name)) {
if(open_file && deckManager.LoadCurrentDeck(open_file_name)) {
#ifdef WIN32
wchar_t *dash = wcsrchr(open_file_name, L'\\');
#else
......@@ -464,7 +464,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
open_file = false;
} else if(mainGame->cbDBCategory->getSelected() != -1 && mainGame->cbDBDecks->getSelected() != -1) {
deckManager.LoadDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->ebDeckname->setText(L"");
}
mainGame->HideElement(mainGame->wMainMenu);
......@@ -547,7 +547,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
tm* st = localtime(&curtime);
wcsftime(infobuf, 256, L"%Y/%m/%d %H:%M:%S\n", st);
repinfo.append(infobuf);
wchar_t namebuf[4][20];
wchar_t namebuf[4][20]{};
ReplayMode::cur_replay.ReadName(namebuf[0]);
ReplayMode::cur_replay.ReadName(namebuf[1]);
if(ReplayMode::cur_replay.pheader.flag & REPLAY_TAG) {
......@@ -633,7 +633,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->env->setFocus(mainGame->wHostPrepare);
if(static_cast<irr::gui::IGUICheckBox*>(caller)->isChecked()) {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
mainGame->gMutex.lock();
static_cast<irr::gui::IGUICheckBox*>(caller)->setChecked(false);
soundManager.PlaySoundEffect(SOUND_INFO);
......
......@@ -253,7 +253,7 @@ public:
#define NETPLAYER_TYPE_OBSERVER 7
#define CTOS_RESPONSE 0x1 // byte array
#define CTOS_UPDATE_DECK 0x2 // int32_t array
#define CTOS_UPDATE_DECK 0x2 // mainc, sidec, int32_t[mainc + sidec]
#define CTOS_HAND_RESULT 0x3 // CTOS_HandResult
#define CTOS_TP_RESULT 0x4 // CTOS_TPResult
#define CTOS_PLAYER_INFO 0x10 // CTOS_PlayerInfo
......
......@@ -440,7 +440,7 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
pduel = create_duel(duel_seed);
set_player_info(pduel, 0, host_info.start_lp, host_info.start_hand, host_info.draw_count);
set_player_info(pduel, 1, host_info.start_lp, host_info.start_hand, host_info.draw_count);
int opt = (int)host_info.duel_rule << 16;
unsigned int opt = (unsigned int)host_info.duel_rule << 16;
if(host_info.no_shuffle_deck)
opt |= DUEL_PSEUDO_SHUFFLE;
last_replay.WriteInt32(host_info.start_lp, false);
......
......@@ -417,7 +417,7 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
pduel = create_duel(duel_seed);
set_player_info(pduel, 0, host_info.start_lp, host_info.start_hand, host_info.draw_count);
set_player_info(pduel, 1, host_info.start_lp, host_info.start_hand, host_info.draw_count);
int opt = (int)host_info.duel_rule << 16;
unsigned int opt = (unsigned int)host_info.duel_rule << 16;
if(host_info.no_shuffle_deck)
opt |= DUEL_PSEUDO_SHUFFLE;
opt |= DUEL_TAG_MODE;
......
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