aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-30 18:43:21 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-30 18:43:21 +0100
commit0c9ddd2f0a1e8a2c88ed22fde1828c0fe21ff4dd (patch)
tree055b8a3607929ba28aceb05a9e59208a51779308 /src/game_tab
parentfc9f6bd6a2cb86d42f4d3df87f128efa7501ea48 (diff)
Add game clone button
Diffstat (limited to 'src/game_tab')
-rw-r--r--src/game_tab/Game.cpp11
-rw-r--r--src/game_tab/Game.hpp1
-rw-r--r--src/game_tab/GameTab.cpp3
-rw-r--r--src/game_tab/HalfMove.cpp17
-rw-r--r--src/game_tab/HalfMove.hpp2
5 files changed, 33 insertions, 1 deletions
diff --git a/src/game_tab/Game.cpp b/src/game_tab/Game.cpp
index 39605ce..49bb4d8 100644
--- a/src/game_tab/Game.cpp
+++ b/src/game_tab/Game.cpp
@@ -22,6 +22,17 @@ Game::Game(HalfMove *m, std::string initial_fen) : result("*") {
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() {
if (moves != NULL) {
delete moves;
diff --git a/src/game_tab/Game.hpp b/src/game_tab/Game.hpp
index f70ebee..25284ee 100644
--- a/src/game_tab/Game.hpp
+++ b/src/game_tab/Game.hpp
@@ -15,6 +15,7 @@ class Game {
chessarbiter::ChessArbiter arbiter;
public:
+ Game(const Game* g);
Game();
Game(std::string fen);
Game(HalfMove *m, std::string initial_fen);
diff --git a/src/game_tab/GameTab.cpp b/src/game_tab/GameTab.cpp
index 4657cb4..3326f12 100644
--- a/src/game_tab/GameTab.cpp
+++ b/src/game_tab/GameTab.cpp
@@ -61,7 +61,8 @@ void GameTab::OnToolClick(wxCommandEvent &event){
}
SaveGame(related_file,game);
} else if(id==1){
- wxLogDebug("Not yet implemented");
+ Game *g=new Game(&(*game));
+ wxGetApp().NewGame(std::shared_ptr<Game>(g));
}
}
diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp
index 5b7ebc4..9a4558c 100644
--- a/src/game_tab/HalfMove.cpp
+++ b/src/game_tab/HalfMove.cpp
@@ -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) {
m->IsBlack = this->IsBlack;
m->Number = this->Number;
diff --git a/src/game_tab/HalfMove.hpp b/src/game_tab/HalfMove.hpp
index 92b0645..da3c919 100644
--- a/src/game_tab/HalfMove.hpp
+++ b/src/game_tab/HalfMove.hpp
@@ -25,6 +25,8 @@ class HalfMove : public cgeditor::CGEHalfMove {
public:
+
+ HalfMove(HalfMove *m);
HalfMove(std::string move_absolute,std::string move_san);
HalfMove(std::string move_absolute,std::string move_san, std::string fen);
HalfMove(pgnp::HalfMove *m);