mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Enable game saving
This commit is contained in:
parent
eec973bc05
commit
27ac369fb6
4 changed files with 28 additions and 3 deletions
|
@ -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<Game> OpenGameX(const std::string &dbpath, long id){
|
||||||
std::shared_ptr<GameBase> base=OpenDatabase(dbpath);
|
std::shared_ptr<GameBase> base=OpenDatabase(dbpath);
|
||||||
return base->GetGame(id);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -43,4 +43,5 @@ std::shared_ptr<GameBase> OpenDatabase(const std::string &dbpath, bool createIfN
|
||||||
* @param id
|
* @param id
|
||||||
* @return std::shared_ptr<Game>
|
* @return std::shared_ptr<Game>
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<Game> OpenGameX(const std::string &dbpath, long id);
|
std::shared_ptr<Game> OpenGameX(const std::string &dbpath, long id);
|
||||||
|
void SaveGame(const std::string &dbpath, std::shared_ptr<Game> g);
|
|
@ -32,9 +32,16 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
|
||||||
void GameTabLeftPanel::OnToolClick(wxCommandEvent &event){
|
void GameTabLeftPanel::OnToolClick(wxCommandEvent &event){
|
||||||
short id=event.GetId();
|
short id=event.GetId();
|
||||||
if(id==0){
|
if(id==0){
|
||||||
if(related_file.size()>0){
|
if(!related_file.size()>0){
|
||||||
// Todo implement save file
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "../Game.hpp"
|
#include "../Game.hpp"
|
||||||
#include "board/BoardCanvas.hpp"
|
#include "board/BoardCanvas.hpp"
|
||||||
#include "ochess.hpp"
|
#include "ochess.hpp"
|
||||||
|
#include "base_tab/gamebase/GameBase.hpp"
|
||||||
|
|
||||||
// Foreign events
|
// Foreign events
|
||||||
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
|
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
|
||||||
|
|
Loading…
Add table
Reference in a new issue