Now games can be imported

This commit is contained in:
Loic Guegan 2022-02-26 12:48:52 +01:00
parent e0a1894928
commit b1a82ff568
5 changed files with 38 additions and 7 deletions

View file

@ -57,9 +57,9 @@ MainWindow::MainWindow()
Bind(NEW_GAME_EVENT, &MainWindow::OnNewGame, this, wxID_ANY); Bind(NEW_GAME_EVENT, &MainWindow::OnNewGame, this, wxID_ANY);
Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this); Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this);
/*BaseTab *bt = new BaseTab((wxFrame *)notebook, "/home/loic/hartwig.pgn"); BaseTab *bt = new BaseTab((wxFrame *)notebook, "/home/loic/hartwig_tests.pgn");
notebook->AddPage(bt, bt->GetLabel()); notebook->AddPage(bt, bt->GetLabel());
notebook->SetSelection(notebook->GetPageIndex(bt));*/ notebook->SetSelection(notebook->GetPageIndex(bt));
} }
void MainWindow::OnSettings(wxCommandEvent &event) { void MainWindow::OnSettings(wxCommandEvent &event) {

View file

@ -24,5 +24,19 @@ void AppendGameDialog::OnImport(wxCommandEvent &event) {
std::vector<GameBase *> new_games_bases; std::vector<GameBase *> new_games_bases;
std::vector<Game *> new_games; std::vector<Game *> new_games;
wxArrayInt selections;
game_list->GetSelections(selections);
for (int &i : selections) {
TabInfos *tinfo = tinfos[i];
if (tinfo->type == TabInfos::BASE) {
new_games_bases.push_back(static_cast<GameBase *>(tinfo->GetBase()));
} else if (tinfo->type == TabInfos::GAME) {
new_games.push_back(static_cast<Game *>(tinfo->GetGame()));
}
}
base->Save(to_ignore, new_games_bases, new_games);
this->Close(); this->Close();
} }

View file

@ -1,6 +1,6 @@
#include "BaseTab.hpp" #include "BaseTab.hpp"
#include <wx/filename.h>
#include "AppendGameDialog.hpp" #include "AppendGameDialog.hpp"
#include <wx/filename.h>
BaseTab::BaseTab(wxFrame *parent, std::string base_file) BaseTab::BaseTab(wxFrame *parent, std::string base_file)
: BasePanelBF(parent), base_file(base_file), TabInfos(TabInfos::BASE), : BasePanelBF(parent), base_file(base_file), TabInfos(TabInfos::BASE),
@ -25,8 +25,11 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
} }
void BaseTab::OnImport(wxCommandEvent &event) { void BaseTab::OnImport(wxCommandEvent &event) {
AppendGameDialog *dia=new AppendGameDialog(this,base); AppendGameDialog *dia = new AppendGameDialog(this, base);
dia->ShowModal(); dia->ShowModal();
game_list->DeleteAllItems();
deleted.clear();
LoadFile();
} }
void BaseTab::OnDelete(wxCommandEvent &event) { void BaseTab::OnDelete(wxCommandEvent &event) {

View file

@ -84,6 +84,20 @@ void PGNGameBase::Save(std::vector<std::uint32_t> to_ignore,
} }
// Now add new games // Now add new games
for (GameBase *current : new_games_bases) {
current->Reset();
while (current->NextGame()) {
if (several) {
new_pgn.Write("\n\n");
} else {
several = true;
}
Game *g = current->GetCurrentGame();
new_pgn.Write(g->GetPGN());
delete g;
}
}
for (Game *g : new_games) { for (Game *g : new_games) {
if (several) { if (several) {
new_pgn.Write("\n\n"); new_pgn.Write("\n\n");

View file

@ -1,13 +1,13 @@
#include "Game.hpp" #include "Game.hpp"
Game::Game() : current(NULL), moves(NULL) { Game::Game() : current(NULL), moves(NULL), result("*") {
tags["White"] = ""; tags["White"] = "";
tags["Black"] = ""; tags["Black"] = "";
initial_fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; initial_fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
board = "rnbqkbnrpppppppp PPPPPPPPRNBQKBNR"; board = "rnbqkbnrpppppppp PPPPPPPPRNBQKBNR";
} }
Game::Game(std::string fen) : current(NULL), moves(NULL) { Game::Game(std::string fen) : current(NULL), moves(NULL), result("*") {
tags["White"] = ""; tags["White"] = "";
tags["Black"] = ""; tags["Black"] = "";
tags["FEN"] = fen; tags["FEN"] = fen;
@ -15,7 +15,7 @@ Game::Game(std::string fen) : current(NULL), moves(NULL) {
board = chessarbiter::FENParser::Parse(fen).board; board = chessarbiter::FENParser::Parse(fen).board;
} }
Game::Game(HalfMove *m, std::string initial_fen) { Game::Game(HalfMove *m, std::string initial_fen): result("*") {
moves = m; moves = m;
current = m; current = m;
this->initial_fen = initial_fen; this->initial_fen = initial_fen;