Now games from databases can be edited and saved

This commit is contained in:
Loic Guegan 2022-02-25 12:06:27 +01:00
parent c6f648cfb4
commit 6ccdc954c5
3 changed files with 14 additions and 1 deletions

View file

@ -2,7 +2,8 @@
#include <wx/filename.h>
BaseTab::BaseTab(wxFrame *parent, std::string base_file)
: BasePanelBF(parent), base_file(base_file), TabInfos(TabInfos::BASE), base(NULL) {
: BasePanelBF(parent), base_file(base_file), TabInfos(TabInfos::BASE),
base(NULL) {
game_list->InsertColumn(0, L"id", wxLIST_FORMAT_LEFT, 50);
game_list->InsertColumn(1, L"White", wxLIST_FORMAT_LEFT, 200);
@ -38,6 +39,9 @@ void BaseTab::OnDelete(wxCommandEvent &event) {
void BaseTab::OnSave(wxCommandEvent &event) {
std::vector<GameBase *> new_games_bases;
std::vector<Game *> new_games;
new_games.insert(
new_games.end(), edited.begin(),
edited.end()); // Add edited game (since they are also deleted)
base->Save(deleted, new_games_bases, new_games);
game_list->DeleteAllItems();
deleted.clear();
@ -49,6 +53,9 @@ void BaseTab::OnOpenGame(wxListEvent &event) {
long id = std::stoi(event.GetItem().GetText().ToStdString());
Game *g = base->GetGame(id);
if (g != NULL) {
edited.push_back(g);
deleted.push_back(id);
game_list->SetItemBackgroundColour(event.GetIndex(), *wxGREEN);
wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
newGameEvent.SetEventObject(this);
newGameEvent.SetClientData(g);

View file

@ -11,6 +11,7 @@ wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
class BaseTab : public BasePanelBF, public TabInfos {
GameBase *base;
std::vector<std::uint32_t> deleted;
std::vector<Game*> edited;
std::string base_file;
public:

View file

@ -79,6 +79,11 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
}
// Now add new games
for (Game *g : new_games) {
new_pgn.Write(g->GetPGN());
new_pgn.Write("\n\n");
}
// new_games->Reset();
// while (new_games->NextGame()) {
// Game *g = new_games->GetCurrentGame();