mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Update chessarbiter and improve pgn loader
This commit is contained in:
parent
f99a7b699a
commit
829525acb9
8 changed files with 29 additions and 10 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 975ad849d1d1474e601ad2f4bf48ea0e4405251c
|
Subproject commit 90050da015f3988ab3188eb19629aed262454fef
|
|
@ -1 +1 @@
|
||||||
Subproject commit 43434b170c2725d74f2d91f4cc86b85303893f08
|
Subproject commit 5d1796920e7c20e8f99f106935e10b8ec9296aba
|
|
@ -4,6 +4,7 @@
|
||||||
#include "preferences/preferences.hpp"
|
#include "preferences/preferences.hpp"
|
||||||
|
|
||||||
wxDEFINE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
wxDEFINE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
||||||
|
wxDEFINE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
|
||||||
|
|
||||||
/// ---------- MainWindow ----------
|
/// ---------- MainWindow ----------
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ MainWindow::MainWindow()
|
||||||
Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, &MainWindow::OnPageChange, this,
|
Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, &MainWindow::OnPageChange, this,
|
||||||
wxID_ANY);
|
wxID_ANY);
|
||||||
Bind(REFRESH_TAB_TITLE, &MainWindow::OnRefreshTabTitle, 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);
|
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) {
|
void MainWindow::OnPageChange(wxAuiNotebookEvent &event) {
|
||||||
TabInfos *infos = dynamic_cast<TabInfos *>(notebook->GetCurrentPage());
|
TabInfos *infos = dynamic_cast<TabInfos *>(notebook->GetCurrentPage());
|
||||||
if (infos->type != TabInfos::GAME) {
|
if (infos->type != TabInfos::GAME) {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#include "game_tab/GameTab.hpp"
|
|
||||||
#include "base_tab/BaseTab.hpp"
|
#include "base_tab/BaseTab.hpp"
|
||||||
|
#include "game_tab/GameTab.hpp"
|
||||||
#include "ochess.hpp"
|
#include "ochess.hpp"
|
||||||
#include <wx/aui/auibook.h>
|
#include <wx/aui/auibook.h>
|
||||||
#include <wx/filedlg.h>
|
#include <wx/filedlg.h>
|
||||||
#include <wx/textdlg.h>
|
|
||||||
#include <wx/preferences.h>
|
#include <wx/preferences.h>
|
||||||
|
#include <wx/textdlg.h>
|
||||||
|
|
||||||
wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
|
||||||
|
wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
|
||||||
|
|
||||||
class MainWindow : public wxFrame {
|
class MainWindow : public wxFrame {
|
||||||
wxAuiNotebook *notebook;
|
wxAuiNotebook *notebook;
|
||||||
|
@ -17,6 +18,7 @@ class MainWindow : public wxFrame {
|
||||||
void OnExit(wxCommandEvent &event);
|
void OnExit(wxCommandEvent &event);
|
||||||
void OnClose(wxCloseEvent &e);
|
void OnClose(wxCloseEvent &e);
|
||||||
void OnNewGame(wxCommandEvent &event);
|
void OnNewGame(wxCommandEvent &event);
|
||||||
|
void OnNewGame2(wxCommandEvent &event);
|
||||||
void OnOpen(wxCommandEvent &event);
|
void OnOpen(wxCommandEvent &event);
|
||||||
void OnPageChange(wxAuiNotebookEvent &event);
|
void OnPageChange(wxAuiNotebookEvent &event);
|
||||||
void OnRefreshTabTitle(wxCommandEvent &event);
|
void OnRefreshTabTitle(wxCommandEvent &event);
|
||||||
|
|
|
@ -22,10 +22,13 @@ void BaseTab::OnBim(wxCommandEvent &event) {
|
||||||
|
|
||||||
void BaseTab::OnOpenGame(wxListEvent &event) {
|
void BaseTab::OnOpenGame(wxListEvent &event) {
|
||||||
wxLogDebug("Open!");
|
wxLogDebug("Open!");
|
||||||
long id=std::stoi(event.GetItem().GetText().ToStdString());
|
long id = std::stoi(event.GetItem().GetText().ToStdString());
|
||||||
Game *g = base->GetGame(id);
|
Game *g = base->GetGame(id);
|
||||||
if (g != NULL) {
|
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) {
|
if (base != NULL) {
|
||||||
long id = 0;
|
long id = 0;
|
||||||
while (base->NextGame()) {
|
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, 1, base->GetTag("White"));
|
||||||
game_list->SetItem(index, 2, base->GetTag("Black"));
|
game_list->SetItem(index, 2, base->GetTag("Black"));
|
||||||
game_list->SetItem(index, 3, base->GetTag("Event"));
|
game_list->SetItem(index, 3, base->GetTag("Event"));
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
#include "gamebase/PGNGameBase.hpp"
|
#include "gamebase/PGNGameBase.hpp"
|
||||||
#include "ochess.hpp"
|
#include "ochess.hpp"
|
||||||
|
|
||||||
|
// Foreign events
|
||||||
|
wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
|
||||||
|
|
||||||
class BaseTab : public BasePanelBF, public TabInfos {
|
class BaseTab : public BasePanelBF, public TabInfos {
|
||||||
GameBase *base;
|
GameBase *base;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ void PGNGameBase::Reset() {
|
||||||
Game *PGNGameBase::GetGame(std::uint32_t id) {
|
Game *PGNGameBase::GetGame(std::uint32_t id) {
|
||||||
Reset();
|
Reset();
|
||||||
std::uint32_t curid = 0;
|
std::uint32_t curid = 0;
|
||||||
while(NextGame()) {
|
while (NextGame()) {
|
||||||
if (id == curid) {
|
if (id == curid) {
|
||||||
pgnp::HalfMove *pgnp_moves = new pgnp::HalfMove();
|
pgnp::HalfMove *pgnp_moves = new pgnp::HalfMove();
|
||||||
pgn->GetMoves(pgnp_moves);
|
pgn->GetMoves(pgnp_moves);
|
||||||
|
@ -41,7 +41,7 @@ Game *PGNGameBase::GetGame(std::uint32_t id) {
|
||||||
if (pgn->HasTag("FEN")) {
|
if (pgn->HasTag("FEN")) {
|
||||||
fen = pgn->GetTagValue("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);
|
Game *g = new Game(m, fen);
|
||||||
for (std::string &s : pgn->GetTagList()) {
|
for (std::string &s : pgn->GetTagList()) {
|
||||||
g->SetTag(s, pgn->GetTagValue(s));
|
g->SetTag(s, pgn->GetTagValue(s));
|
||||||
|
|
|
@ -118,7 +118,10 @@ HalfMove *HalfMove::GetMainline() { return (mainline); }
|
||||||
HalfMove::HalfMove(pgnp::HalfMove *m, std::string initial_fen): capture(' ') {
|
HalfMove::HalfMove(pgnp::HalfMove *m, std::string initial_fen): capture(' ') {
|
||||||
chessarbiter::ChessArbiter arbiter;
|
chessarbiter::ChessArbiter arbiter;
|
||||||
arbiter.Setup(initial_fen);
|
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();
|
char capture=arbiter.GetCapture();
|
||||||
if(capture != ' '){
|
if(capture != ' '){
|
||||||
this->capture=capture;
|
this->capture=capture;
|
||||||
|
|
Loading…
Add table
Reference in a new issue