aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-02-24 16:45:28 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-02-24 16:45:28 +0100
commit829525acb94876a464a359548bce4faf0708bbc7 (patch)
tree066e933cf54d3408a2e1cc408bbcc03961599562
parentf99a7b699a6169003fc8b56f652de44c2e834ca5 (diff)
Update chessarbiter and improve pgn loader
m---------libs/chessarbiter0
m---------libs/pgnp0
-rw-r--r--src/MainWindow.cpp7
-rw-r--r--src/MainWindow.hpp6
-rw-r--r--src/base_tab/BaseTab.cpp10
-rw-r--r--src/base_tab/BaseTab.hpp3
-rw-r--r--src/base_tab/gamebase/PGNGameBase.cpp4
-rw-r--r--src/game_tab/HalfMove.cpp5
8 files changed, 27 insertions, 8 deletions
diff --git a/libs/chessarbiter b/libs/chessarbiter
-Subproject 975ad849d1d1474e601ad2f4bf48ea0e4405251
+Subproject 90050da015f3988ab3188eb19629aed262454fe
diff --git a/libs/pgnp b/libs/pgnp
-Subproject 43434b170c2725d74f2d91f4cc86b85303893f0
+Subproject 5d1796920e7c20e8f99f106935e10b8ec9296ab
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 0a79bc2..5dbbf28 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -4,6 +4,7 @@
#include "preferences/preferences.hpp"
wxDEFINE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
+wxDEFINE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
/// ---------- MainWindow ----------
@@ -52,6 +53,7 @@ MainWindow::MainWindow()
Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, &MainWindow::OnPageChange, this,
wxID_ANY);
Bind(REFRESH_TAB_TITLE, &MainWindow::OnRefreshTabTitle, this, wxID_ANY);
+ Bind(NEW_GAME_EVENT, &MainWindow::OnNewGame2, this, wxID_ANY);
Bind(wxEVT_CLOSE_WINDOW, &MainWindow::OnClose, this);
}
@@ -142,6 +144,11 @@ void MainWindow::OnNewGame(wxCommandEvent &event) {
}
}
+void MainWindow::OnNewGame2(wxCommandEvent &event) {
+ Game *g=(Game*)event.GetClientData();
+ NewGame(g);
+}
+
void MainWindow::OnPageChange(wxAuiNotebookEvent &event) {
TabInfos *infos = dynamic_cast<TabInfos *>(notebook->GetCurrentPage());
if (infos->type != TabInfos::GAME) {
diff --git a/src/MainWindow.hpp b/src/MainWindow.hpp
index 87cf015..e827df3 100644
--- a/src/MainWindow.hpp
+++ b/src/MainWindow.hpp
@@ -1,12 +1,13 @@
-#include "game_tab/GameTab.hpp"
#include "base_tab/BaseTab.hpp"
+#include "game_tab/GameTab.hpp"
#include "ochess.hpp"
#include <wx/aui/auibook.h>
#include <wx/filedlg.h>
-#include <wx/textdlg.h>
#include <wx/preferences.h>
+#include <wx/textdlg.h>
wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
+wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
class MainWindow : public wxFrame {
wxAuiNotebook *notebook;
@@ -17,6 +18,7 @@ class MainWindow : public wxFrame {
void OnExit(wxCommandEvent &event);
void OnClose(wxCloseEvent &e);
void OnNewGame(wxCommandEvent &event);
+ void OnNewGame2(wxCommandEvent &event);
void OnOpen(wxCommandEvent &event);
void OnPageChange(wxAuiNotebookEvent &event);
void OnRefreshTabTitle(wxCommandEvent &event);
diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp
index f1fd107..29b6fc3 100644
--- a/src/base_tab/BaseTab.cpp
+++ b/src/base_tab/BaseTab.cpp
@@ -22,10 +22,13 @@ void BaseTab::OnBim(wxCommandEvent &event) {
void BaseTab::OnOpenGame(wxListEvent &event) {
wxLogDebug("Open!");
- long id=std::stoi(event.GetItem().GetText().ToStdString());
+ long id = std::stoi(event.GetItem().GetText().ToStdString());
Game *g = base->GetGame(id);
if (g != NULL) {
- wxLogDebug("Open game: %s", g->GetTag("White"));
+ wxCommandEvent newGameEvent(NEW_GAME_EVENT, GetId());
+ newGameEvent.SetEventObject(this);
+ newGameEvent.SetClientData(g);
+ ProcessEvent(newGameEvent);
}
}
@@ -41,7 +44,8 @@ void BaseTab::LoadFile(std::string path) {
if (base != NULL) {
long id = 0;
while (base->NextGame()) {
- long index = game_list->InsertItem(0, std::to_string(id)); // want this for col. 1
+ long index =
+ game_list->InsertItem(0, std::to_string(id)); // want this for col. 1
game_list->SetItem(index, 1, base->GetTag("White"));
game_list->SetItem(index, 2, base->GetTag("Black"));
game_list->SetItem(index, 3, base->GetTag("Event"));
diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp
index 5a71cd7..26ee8c1 100644
--- a/src/base_tab/BaseTab.hpp
+++ b/src/base_tab/BaseTab.hpp
@@ -4,6 +4,9 @@
#include "gamebase/PGNGameBase.hpp"
#include "ochess.hpp"
+// Foreign events
+wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
+
class BaseTab : public BasePanelBF, public TabInfos {
GameBase *base;
diff --git a/src/base_tab/gamebase/PGNGameBase.cpp b/src/base_tab/gamebase/PGNGameBase.cpp
index 08c8803..8f9974d 100644
--- a/src/base_tab/gamebase/PGNGameBase.cpp
+++ b/src/base_tab/gamebase/PGNGameBase.cpp
@@ -32,7 +32,7 @@ void PGNGameBase::Reset() {
Game *PGNGameBase::GetGame(std::uint32_t id) {
Reset();
std::uint32_t curid = 0;
- while(NextGame()) {
+ while (NextGame()) {
if (id == curid) {
pgnp::HalfMove *pgnp_moves = new pgnp::HalfMove();
pgn->GetMoves(pgnp_moves);
@@ -41,7 +41,7 @@ Game *PGNGameBase::GetGame(std::uint32_t id) {
if (pgn->HasTag("FEN")) {
fen = pgn->GetTagValue("FEN");
}
- HalfMove *m = new HalfMove(pgnp_moves, fen);
+ HalfMove *m = new HalfMove(pgnp_moves, fen);
Game *g = new Game(m, fen);
for (std::string &s : pgn->GetTagList()) {
g->SetTag(s, pgn->GetTagValue(s));
diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp
index e59794b..1a6b5aa 100644
--- a/src/game_tab/HalfMove.cpp
+++ b/src/game_tab/HalfMove.cpp
@@ -118,7 +118,10 @@ HalfMove *HalfMove::GetMainline() { return (mainline); }
HalfMove::HalfMove(pgnp::HalfMove *m, std::string initial_fen): capture(' ') {
chessarbiter::ChessArbiter arbiter;
arbiter.Setup(initial_fen);
- arbiter.Play(arbiter.ParseSAN(m->move));
+ bool work=arbiter.Play(arbiter.ParseSAN(m->move));
+ if(!work){
+ wxLogDebug("Bug! %s",m->move);
+ }
char capture=arbiter.GetCapture();
if(capture != ' '){
this->capture=capture;