Add game clone button

This commit is contained in:
Loic Guegan 2022-12-30 18:43:21 +01:00
parent fc9f6bd6a2
commit 0c9ddd2f0a
5 changed files with 33 additions and 1 deletions

View file

@ -22,6 +22,17 @@ Game::Game(HalfMove *m, std::string initial_fen) : result("*") {
board = chessarbiter::FENParser::Parse(initial_fen).board; board = chessarbiter::FENParser::Parse(initial_fen).board;
} }
Game::Game(const Game* g){
board=g->board;
initial_fen=g->initial_fen;
result=g->result;
tags=g->tags;
if(g->moves != NULL){
moves=new HalfMove(g->moves);
current=nullptr;
}
}
Game::~Game() { Game::~Game() {
if (moves != NULL) { if (moves != NULL) {
delete moves; delete moves;

View file

@ -15,6 +15,7 @@ class Game {
chessarbiter::ChessArbiter arbiter; chessarbiter::ChessArbiter arbiter;
public: public:
Game(const Game* g);
Game(); Game();
Game(std::string fen); Game(std::string fen);
Game(HalfMove *m, std::string initial_fen); Game(HalfMove *m, std::string initial_fen);

View file

@ -61,7 +61,8 @@ void GameTab::OnToolClick(wxCommandEvent &event){
} }
SaveGame(related_file,game); SaveGame(related_file,game);
} else if(id==1){ } else if(id==1){
wxLogDebug("Not yet implemented"); Game *g=new Game(&(*game));
wxGetApp().NewGame(std::shared_ptr<Game>(g));
} }
} }

View file

@ -20,6 +20,23 @@ HalfMove::~HalfMove() {
} }
} }
HalfMove::HalfMove(HalfMove *m){
move_absolute=m->move_absolute;
move=m->move;
fen=m->fen;
capture=m->capture;
IsBlack = m->IsBlack;
Number = m->Number;
nag = m->nag;
SetComment(m->GetComment());
if(m->mainline != NULL){
SetMainline(new HalfMove(m->mainline));
}
for (int i=0; i < m->variations.size(); i++) {
AddVariation(new HalfMove(m->variations[i]));
}
}
void HalfMove::AddVariation(HalfMove *m) { void HalfMove::AddVariation(HalfMove *m) {
m->IsBlack = this->IsBlack; m->IsBlack = this->IsBlack;
m->Number = this->Number; m->Number = this->Number;

View file

@ -25,6 +25,8 @@ class HalfMove : public cgeditor::CGEHalfMove {
public: public:
HalfMove(HalfMove *m);
HalfMove(std::string move_absolute,std::string move_san); HalfMove(std::string move_absolute,std::string move_san);
HalfMove(std::string move_absolute,std::string move_san, std::string fen); HalfMove(std::string move_absolute,std::string move_san, std::string fen);
HalfMove(pgnp::HalfMove *m); HalfMove(pgnp::HalfMove *m);