From 27ac369fb6b773f642eabed087194ff7e95f9156 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Fri, 30 Dec 2022 15:09:24 +0100 Subject: Enable game saving --- src/base_tab/gamebase/GameBase.cpp | 16 ++++++++++++++++ src/base_tab/gamebase/GameBase.hpp | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src/base_tab') 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 OpenDatabase(const std::string &dbpath, bool createIfN std::shared_ptr OpenGameX(const std::string &dbpath, long id){ std::shared_ptr base=OpenDatabase(dbpath); return base->GetGame(id); +} + +void SaveGame(const std::string &dbpath, std::shared_ptr g){ + wxFileName file(dbpath); + wxString ext = file.GetExt().Lower(); + // Create data structure + std::vector> new_games; + new_games.push_back(g); + std::vector dummy_empty_bases; + std::vector 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 OpenDatabase(const std::string &dbpath, bool createIfN * @param id * @return std::shared_ptr */ -std::shared_ptr OpenGameX(const std::string &dbpath, long id); \ No newline at end of file +std::shared_ptr OpenGameX(const std::string &dbpath, long id); +void SaveGame(const std::string &dbpath, std::shared_ptr g); \ No newline at end of file -- cgit v1.2.3