aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-12-30 15:09:24 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-12-30 15:09:24 +0100
commit27ac369fb6b773f642eabed087194ff7e95f9156 (patch)
treebaa1627d2a24f79f3b2bbdabcae8e21c61be1da1 /src
parenteec973bc05c0a7e0c511b392704c6d093c2820b4 (diff)
Enable game saving
Diffstat (limited to 'src')
-rw-r--r--src/base_tab/gamebase/GameBase.cpp16
-rw-r--r--src/base_tab/gamebase/GameBase.hpp3
-rw-r--r--src/game_tab/left_panel/GameTabLeftPanel.cpp11
-rw-r--r--src/game_tab/left_panel/GameTabLeftPanel.hpp1
4 files changed, 28 insertions, 3 deletions
diff --git a/src/base_tab/gamebase/GameBase.cpp b/src/base_tab/gamebase/GameBase.cpp
index 3d7b5d3..a5710df 100644
--- a/src/base_tab/gamebase/GameBase.cpp
+++ b/src/base_tab/gamebase/GameBase.cpp
@@ -16,4 +16,20 @@ std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfN
std::shared_ptr<Game> OpenGameX(const std::string &dbpath, long id){
std::shared_ptr<GameBase> base=OpenDatabase(dbpath);
return base->GetGame(id);
+}
+
+void SaveGame(const std::string &dbpath, std::shared_ptr<Game> g){
+ wxFileName file(dbpath);
+ wxString ext = file.GetExt().Lower();
+ // Create data structure
+ std::vector<std::shared_ptr<Game>> new_games;
+ new_games.push_back(g);
+ std::vector<std::string> dummy_empty_bases;
+ std::vector<std::uint32_t> dummy_empty_ignores;
+ // Save the game
+ if (ext == "pgn") {
+ PGNGameBase::CreateDatabaseFile(dbpath); // Erase if exist
+ GameBase *b=new PGNGameBase(dbpath);
+ b->Save(dummy_empty_ignores,dummy_empty_bases, new_games);
+ }
} \ No newline at end of file
diff --git a/src/base_tab/gamebase/GameBase.hpp b/src/base_tab/gamebase/GameBase.hpp
index b84047b..1ef5f59 100644
--- a/src/base_tab/gamebase/GameBase.hpp
+++ b/src/base_tab/gamebase/GameBase.hpp
@@ -43,4 +43,5 @@ std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfN
* @param id
* @return std::shared_ptr<Game>
*/
-std::shared_ptr<Game> OpenGameX(const std::string &dbpath, long id); \ No newline at end of file
+std::shared_ptr<Game> OpenGameX(const std::string &dbpath, long id);
+void SaveGame(const std::string &dbpath, std::shared_ptr<Game> g); \ No newline at end of file
diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp
index c5bf8ae..4f09bdd 100644
--- a/src/game_tab/left_panel/GameTabLeftPanel.cpp
+++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp
@@ -32,9 +32,16 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
void GameTabLeftPanel::OnToolClick(wxCommandEvent &event){
short id=event.GetId();
if(id==0){
- if(related_file.size()>0){
- // Todo implement save file
+ if(!related_file.size()>0){
+ wxFileDialog
+ newFileDialog(this, _("Save Game"), "", "",
+ "PGN files (*.pgn)|*.pgn", wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
+ if (newFileDialog.ShowModal() == wxID_CANCEL)
+ return;
+ // Create and open new db
+ related_file = newFileDialog.GetPath().ToStdString();
}
+ SaveGame(related_file,game);
}
}
diff --git a/src/game_tab/left_panel/GameTabLeftPanel.hpp b/src/game_tab/left_panel/GameTabLeftPanel.hpp
index 25cbcf0..d9995e4 100644
--- a/src/game_tab/left_panel/GameTabLeftPanel.hpp
+++ b/src/game_tab/left_panel/GameTabLeftPanel.hpp
@@ -3,6 +3,7 @@
#include "../Game.hpp"
#include "board/BoardCanvas.hpp"
#include "ochess.hpp"
+#include "base_tab/gamebase/GameBase.hpp"
// Foreign events
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);