From a1289dec3dcec278f9cf6d18a001b3146b11b7b2 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 19 Jan 2023 16:33:44 +0100 Subject: [PATCH] Integrate CMI --- .gitmodules | 9 +- CMakeLists.txt | 5 + README.md | 1 + libs/cgeditor | 2 +- libs/chess-move-interface | 1 + libs/pgnp | 2 +- src/base_tab/gamebase/PGNGameBase.cpp | 23 +- src/game_tab/Game.cpp | 10 +- src/game_tab/HalfMove.cpp | 202 ++++-------------- src/game_tab/HalfMove.hpp | 30 +-- .../right_panel/GameTabRightPanel.cpp | 54 ++--- .../right_panel/GameTabRightPanel.hpp | 2 +- .../right_panel/editor/EditorCanvas.cpp | 55 +---- 13 files changed, 118 insertions(+), 278 deletions(-) create mode 160000 libs/chess-move-interface diff --git a/.gitmodules b/.gitmodules index 949cfb5..5892e7c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "libs/cgeditor"] - path = libs/cgeditor - url = https://gitlab.com/manzerbredes/cgeditor.git [submodule "libs/chessarbiter"] path = libs/chessarbiter url = https://gitlab.com/manzerbredes/chessarbiter.git @@ -10,3 +7,9 @@ [submodule "libs/uciadapter"] path = libs/uciadapter url = https://gitlab.com/manzerbredes/uciadapter.git +[submodule "libs/chess-move-interface"] + path = libs/chess-move-interface + url = https://gitlab.com/manzerbredes/chess-move-interface.git +[submodule "cgeditor"] + path = libs/cgeditor + url = https://gitlab.com/manzerbredes/cgeditor.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 130849f..1dbfe5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,11 @@ add_subdirectory(libs/uciadapter) target_link_libraries(ochess uciadapter) include_directories(${UCIADAPTER_INCLUDE_DIR}) +# ChessMoveInterface +add_subdirectory(libs/chess-move-interface) +target_link_libraries(ochess ChessMoveInterface) +include_directories(${CMI_INCLUDE_DIR}) + # Assets add_custom_command(TARGET ochess PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory diff --git a/README.md b/README.md index d6ee6de..fdd316a 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ OChess is based on several satellite projects that implement individual and inde - [pgnp](https://gitlab.com/manzerbredes/pgnp): An efficient PGN parser - [uciadapter](https://gitlab.com/manzerbredes/uciadapter): A cross platform utility to interact with *UCI* chess engines - [cgeditor](https://gitlab.com/manzerbredes/cgeditor): A 2D chess game moves presenter/editor + - [chess-move-interface](https://gitlab.com/manzerbredes/chess-move-interface) A chess half move interface for libraries interoperability ## Acknowledgments - The [chess-openings](https://github.com/lichess-org/chess-openings) project by [lichess-org](https://github.com/lichess-org) for their openings databases \ No newline at end of file diff --git a/libs/cgeditor b/libs/cgeditor index 5e18d43..83c92b1 160000 --- a/libs/cgeditor +++ b/libs/cgeditor @@ -1 +1 @@ -Subproject commit 5e18d43a6ba4fd378178418de6b2ca7a67d64c21 +Subproject commit 83c92b1f48520ed71a9f056badc86c97aafa4e45 diff --git a/libs/chess-move-interface b/libs/chess-move-interface new file mode 160000 index 0000000..7125292 --- /dev/null +++ b/libs/chess-move-interface @@ -0,0 +1 @@ +Subproject commit 7125292878ffc3568018e1e509c9210a074c67a6 diff --git a/libs/pgnp b/libs/pgnp index 2ac4255..f7a24ed 160000 --- a/libs/pgnp +++ b/libs/pgnp @@ -1 +1 @@ -Subproject commit 2ac42558f2b6269ad4d8e0809519f96aae1fd342 +Subproject commit f7a24ed8d5802c834abc4fe54c286ce509dae609 diff --git a/src/base_tab/gamebase/PGNGameBase.cpp b/src/base_tab/gamebase/PGNGameBase.cpp index 5d0bf57..a969451 100644 --- a/src/base_tab/gamebase/PGNGameBase.cpp +++ b/src/base_tab/gamebase/PGNGameBase.cpp @@ -47,7 +47,7 @@ std::shared_ptr PGNGameBase::GetCurrentGame() { g=new Game(fen); } else { - HalfMove *m = new HalfMove(pgnp_moves); + HalfMove *m = new HalfMove(pgnp_moves->GetAsCMI()); m->SetFen(fen); g=new Game(m, fen); } @@ -156,7 +156,7 @@ std::string PGNGameBase::GetPGN(std::shared_ptr g) { } if(m !=nullptr){ - pgn += GetMovesPGN(m,m->IsABlackMove()); + pgn += GetMovesPGN(m,m->IsBlack()); pgn += " "; } @@ -168,32 +168,35 @@ std::string PGNGameBase::GetMovesPGN(HalfMove *m, bool needDots) { std::string part; bool newNeedDots = false; - if (!m->IsABlackMove() || needDots) { - part += std::to_string(m->Number) + "."; + if (!m->IsBlack() || needDots) { + part += std::to_string(m->GetNumber()) + "."; if (needDots) { part += ".."; } } - part += m->move; + part += m->GetSAN(); - if (m->comment.size() > 0) { + if(m->GetNAG()>0) + part += " $" + std::to_string(m->GetNAG()); + + if (m->GetComment().size() > 0) { part += " {"; - part += m->comment; + part += m->GetComment(); part += "}"; newNeedDots = true; } if (m->GetVariations().size() > 0) { newNeedDots = true; - for (HalfMove *v : m->GetVariations()) { + for (CMI::HalfMove *v : m->GetVariations()) { part += " ("; - part += GetMovesPGN(v, m->IsABlackMove()); + part += GetMovesPGN(static_cast(v), m->IsBlack()); part += ")"; } } if (m->GetMainline() != nullptr) { - part += " " + GetMovesPGN(m->GetMainline(), !m->IsABlackMove() && newNeedDots); + part += " " + GetMovesPGN(static_cast(m->GetMainline()), !m->IsBlack() && newNeedDots); } return (part); diff --git a/src/game_tab/Game.cpp b/src/game_tab/Game.cpp index c1aa605..ac1f428 100644 --- a/src/game_tab/Game.cpp +++ b/src/game_tab/Game.cpp @@ -53,7 +53,7 @@ bool Game::IsBlackToPlay() { if (current == nullptr) { return (false); } - return (!current->IsBlack); + return (!current->IsBlack()); } void Game::DeleteTag(std::string tagname) { tags.erase(tagname); } @@ -65,7 +65,7 @@ void Game::DeleteMove(HalfMove *m) { delete m; } else { if (m != nullptr) { - current = m->GetParent(); + current = static_cast(m->GetParent()); if (current != nullptr) { current->RemoveChild(m); } @@ -153,7 +153,7 @@ void Game::GetOpening(std::string &name,std::string &eco){ void Game::Previous() { if (current != nullptr) { - current = current->GetParent(); + current = static_cast(current->GetParent()); } } @@ -167,7 +167,7 @@ std::vector Game::ListTags() { void Game::Next() { if (current != nullptr) { - HalfMove *m = current->GetMainline(); + HalfMove *m = static_cast(current->GetMainline()); if (m != nullptr) { current = m; } @@ -178,7 +178,7 @@ void Game::Next() { HalfMove *Game::GetNextMove(){ if(current!=nullptr) - return current->GetMainline(); + return static_cast(current->GetMainline()); return moves; } diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp index e152ce0..e1c2926 100644 --- a/src/game_tab/HalfMove.cpp +++ b/src/game_tab/HalfMove.cpp @@ -2,22 +2,13 @@ HalfMove::HalfMove(std::string move_absolute,std::string move_san) : capture(' ') { SetAbsoluteMove(move_absolute); - this->move = move_san; + SetSAN(move_san); fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; } HalfMove::HalfMove(std::string move_absolute, std::string move_san, std::string fen) : fen(fen), capture(' ') { SetAbsoluteMove(move_absolute); - this->move = move_san; -} - -HalfMove::~HalfMove() { - if (mainline != nullptr) { - delete mainline; - } - for (HalfMove *m : variations) { - delete m; - } + SetSAN(move_san); } void HalfMove::SetOpening(const std::string &name, const std::string &eco){ @@ -25,8 +16,8 @@ void HalfMove::SetOpening(const std::string &name, const std::string &eco){ while(m!=nullptr){ m->opening=name; m->eco=eco; - if(m->parent != nullptr && m->parent->mainline==m) - m=m->parent; + if(m->GetParent() != nullptr && static_cast(m->GetParent()->GetMainline())==m) + m=static_cast(m->GetParent()); else break; } @@ -43,10 +34,10 @@ std::vector HalfMove::GetLine(){ while(m!=nullptr){ line.push_back(m); // Check if in a variation: - if(m->parent!=nullptr && m->parent->mainline!=m) - m=m->parent->parent; // Because we are in a variation + if(m->GetParent()!=nullptr && static_cast(m->GetParent()->GetMainline())!=m) + m=static_cast(m->GetParent()->GetParent()); // Because we are in a variation else - m=m->parent; + m=static_cast(m->GetParent()); } // Reverse the order to get it in the played order: std::reverse(line.begin(), line.end()); @@ -64,7 +55,7 @@ std::string HalfMove::GetLineAsSAN(){ pgn+=std::to_string(count)+"."; count+=1; } - pgn+=line[i]->move +" "; + pgn+=line[i]->GetSAN() +" "; } return pgn; } @@ -72,29 +63,21 @@ std::string HalfMove::GetLineAsSAN(){ HalfMove::HalfMove(HalfMove *m){ src=m->src; dst=m->dst; - move=m->move; + SetSAN(m->GetSAN()); fen=m->fen; capture=m->capture; - IsBlack = m->IsBlack; - Number = m->Number; - nag = m->nag; - comment=m->comment; - if(m->mainline != nullptr){ - SetMainline(new HalfMove(m->mainline)); + SetIsBlack(m->IsBlack()); + SetNumber(m->GetNumber()); + SetNAG(m->GetNAG()); + SetComment(m->GetComment()); + if(m->GetMainline() != nullptr){ + SetMainline(static_cast(new HalfMove(static_cast(m->GetMainline())))); } - for (int i=0; i < m->variations.size(); i++) { - AddVariation(new HalfMove(m->variations[i])); + for (CMI::HalfMove *v: m->GetVariations()) { + AddVariation(new HalfMove(static_cast(v))); } } -void HalfMove::AddVariation(HalfMove *m) { - m->IsBlack = this->IsBlack; - m->Number = this->Number; - HalfMove::variations.push_back(m); - cgeditor::CGEHalfMove::variations.push_back(m); - m->SetParent(this); -} - std::map HalfMove::GetLineCaptures() { std::map captures; HalfMove *m = this; @@ -105,7 +88,7 @@ std::map HalfMove::GetLineCaptures() { } else { captures[c] = 1; } - m = m->parent; + m = static_cast(m->GetParent()); } while (m != nullptr); return (captures); } @@ -113,96 +96,30 @@ std::map HalfMove::GetLineCaptures() { void HalfMove::SetCapture(char c) { capture = c; } void HalfMove::AddMove(HalfMove *m) { - if (this->mainline == nullptr) { + if (GetMainline() == nullptr) { SetMainline(m); } else { - if (mainline != nullptr) { - mainline->AddVariation(m); - } + if(GetMainline()!=nullptr) + GetMainline()->AddVariation(m); } } -void HalfMove::SetMainline(HalfMove *m) { - if (!this->IsBlack) { - m->IsBlack = true; - m->Number = this->Number; - } else { - m->IsBlack = false; - m->Number = this->Number + 1; - } - HalfMove::mainline = m; - cgeditor::CGEHalfMove::MainLine = m; - if (m != nullptr) { - m->SetParent(this); - } -} - -void HalfMove::SetParent(HalfMove *m) { - HalfMove::parent = m; - CGEHalfMove::Parent = m; -} - -void HalfMove::RemoveChild(HalfMove *m) { - std::uint32_t i = 0; - bool found = false; - for (i; i < HalfMove::variations.size(); i++) { - if (HalfMove::variations[i] == m) { - found = true; - break; - } - } - if (found) { - HalfMove::variations.erase(HalfMove::variations.begin() + i); - } - if (HalfMove::mainline == m) { - HalfMove::mainline = nullptr; - } - cgeditor::CGEHalfMove::RemoveChild((CGEHalfMove *)m); -} - -HalfMove *HalfMove::GetParent() { return (parent); } - -HalfMove *HalfMove::GetRoot() { - HalfMove *m = this; - HalfMove *p = HalfMove::parent; - while (p != nullptr) { - if (p->mainline != m) { - return (m); - } - m = p; - p = m->HalfMove::parent; - } - return (m); -} - -void HalfMove::SetAsMainline() { - HalfMove *root = GetRoot(); - HalfMove *lastRoot; - do { - lastRoot = root; - root->HalfMove::Promote(); - root = GetRoot(); - } while (root != lastRoot); -} - -HalfMove *HalfMove::GetMainline() { return (mainline); } - void HalfMove::SetAbsoluteMove(const std::string &move_absolute){ this->src=move_absolute.substr(0,2); this->dst=move_absolute.substr(2,2); } -HalfMove::HalfMove(pgnp::HalfMove *m) : capture(' ') { - this->move = m->move; - this->nag = m->NAG; - this->IsBlack = m->isBlack; - this->comment=m->comment; - this->Number = m->count; - if (m->MainLine != nullptr) { - this->SetMainline(new HalfMove(m->MainLine)); +HalfMove::HalfMove(CMI::HalfMove *m) : capture(' ') { + SetSAN(m->GetSAN()); + SetNAG(m->GetNAG()); + SetIsBlack(m->IsBlack()); + SetComment(m->GetComment()); + SetNumber(m->GetNumber()); + if (m->GetMainline() != nullptr) { + SetMainline(new HalfMove(m->GetMainline())); } - for (pgnp::HalfMove *v : m->variations) { - this->AddVariation(new HalfMove(v)); + for (CMI::HalfMove *v : m->GetVariations()) { + AddVariation(new HalfMove(v)); } } @@ -213,42 +130,19 @@ void HalfMove::GetAbsoluteMove(std::string &src,std::string &dst){ void HalfMove::SetFen(std::string fen) { this->fen = fen; } -void HalfMove::Promote() { - HalfMove *root = GetRoot(); - if (root->parent != nullptr) { - HalfMove *p = root->parent; - if (p->HalfMove::mainline != root) { - if (root->parent->HalfMove::parent != nullptr) { - HalfMove *pp = root->parent->HalfMove::parent; - if (pp->HalfMove::mainline == p) { - pp->HalfMove::SetMainline(root); - } else { - pp->AddVariation(root); - pp->HalfMove::RemoveChild(p); - } - } - if (p->HalfMove::mainline == root) { - p->HalfMove::SetMainline(nullptr); - } else { - p->HalfMove::RemoveChild(root); - } - root->AddVariation(p); - } - } -} bool HalfMove::HasParent(HalfMove*m){ - return m==parent; + return m==static_cast(GetParent()); } bool HalfMove::HasChild(HalfMove*m){ if(m==nullptr) return false; - if(mainline==m){ + if(static_cast(GetMainline())==m){ return true; } - for(auto var: variations){ - if(var == m) + for(auto var: GetVariations()){ + if(static_cast(var) == m) return true; } return false; @@ -256,38 +150,34 @@ bool HalfMove::HasChild(HalfMove*m){ bool HalfMove::IsVariation() { HalfMove *m = this; - HalfMove *p = HalfMove::parent; + HalfMove *p = static_cast(GetParent()); while (p != nullptr) { - if (p->mainline != m) { + if (static_cast(p->GetMainline()) != m) { return (true); } m = p; - p = m->HalfMove::parent; + p = static_cast(m->GetParent()); } return (false); } std::string HalfMove::GetFen() { return (fen); } -std::vector HalfMove::GetVariations() { return (variations); } - -bool HalfMove::IsABlackMove() { return (IsBlack); } - void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) { arbiter.Setup(fen); - std::string move_absolute=arbiter.ParseSAN(m->move); + std::string move_absolute=arbiter.ParseSAN(m->GetSAN()); m->SetAbsoluteMove(move_absolute); - bool work = arbiter.Play(move_absolute,arbiter.ParseSANPromotion(m->move)); + bool work = arbiter.Play(move_absolute,arbiter.ParseSANPromotion(m->GetSAN())); if (!work) { - wxLogDebug("Bug! %s", m->move); + wxLogDebug("Bug! %s", m->GetSAN()); } char capture = arbiter.GetCapture(); if (capture != ' ') { m->capture = capture; } m->fen = arbiter.GetFEN(); - if (m->mainline != nullptr) { - BuildAndVerify(m->mainline, arbiter.GetFEN()); + if (m->GetMainline() != nullptr) { + BuildAndVerify(static_cast(m->GetMainline()), arbiter.GetFEN()); } else { // Otherwise we are on a leaf! So, guess the opening: std::string name,eco; @@ -295,10 +185,10 @@ void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) { if(eco.size()>0) m->SetOpening(name,eco); } - for (HalfMove *v : m->variations) { - BuildAndVerify(v, fen); + for (CMI::HalfMove *v : m->GetVariations()) { + BuildAndVerify(static_cast(v), fen); } } void HalfMove::BuildAndVerify(std::string initial_fen) { BuildAndVerify(this, initial_fen); -} \ No newline at end of file +} diff --git a/src/game_tab/HalfMove.hpp b/src/game_tab/HalfMove.hpp index 297ca50..6637571 100644 --- a/src/game_tab/HalfMove.hpp +++ b/src/game_tab/HalfMove.hpp @@ -1,5 +1,5 @@ #pragma once -#include "CGEditor.hpp" +#include "CMI.hpp" #include "ChessArbiter.hpp" #include "ochess.hpp" #include "pgnp.hpp" @@ -9,11 +9,7 @@ /** * @brief This class extends CGEHalfMove (to be displayed in the game editor) */ -class HalfMove : public cgeditor::CGEHalfMove { - HalfMove *parent = nullptr; - HalfMove *mainline = nullptr; - chessarbiter::ChessArbiter arbiter; - std::vector variations; +class HalfMove : public CMI::HalfMove { std::string fen; /// @brief Used in to retrieve captured pieces (see GetLineCaptures()) char capture; @@ -22,35 +18,20 @@ class HalfMove : public cgeditor::CGEHalfMove { std::string src,dst; /// @brief Opening reach by that move while taking into account all the parents std::string opening, eco; + chessarbiter::ChessArbiter arbiter; public: HalfMove(HalfMove *m); HalfMove(std::string move_absolute,std::string move_san); HalfMove(std::string move_absolute,std::string move_san, std::string fen); - HalfMove(pgnp::HalfMove *m); + HalfMove(CMI::HalfMove *m); - ~HalfMove(); - /// @brief Add variation to current move - void AddVariation(HalfMove *m); - /// @brief Remove the specified child from mainline and/or variations - void RemoveChild(HalfMove *m); void AddMove(HalfMove *m); - /// @brief Set value of the mailine - void SetMainline(HalfMove *m); - /// @brief Set this move as mainline - void SetAsMainline(); - /// @brief Promote the current move and submove - void Promote(); /// @brief Check if current half move is within a variation bool IsVariation(); /// @brief Get the root of a variation bool HasParent(HalfMove*m); bool HasChild(HalfMove*m); - HalfMove *GetRoot(); - /// @brief Get parent of the current move - HalfMove *GetParent(); - HalfMove *GetMainline(); - std::vector GetVariations(); /// @brief Retrieve the list of moves from the current one to the first one std::vector GetLine(); std::string GetLineAsSAN(); @@ -59,12 +40,9 @@ public: void SetOpening(const std::string &name, const std::string &eco); /// @brief Getters for name and eco void GetOpening(std::string &name, std::string &eco); - /// @brief Set parent of the current move - void SetParent(HalfMove *m); std::string GetFen(); void SetFen(std::string fen); void SetCapture(char c); - bool IsABlackMove(); void GetAbsoluteMove(std::string &src,std::string &dst); void SetAbsoluteMove(const std::string &move_absolute); diff --git a/src/game_tab/right_panel/GameTabRightPanel.cpp b/src/game_tab/right_panel/GameTabRightPanel.cpp index 21b4ed7..5d933b8 100644 --- a/src/game_tab/right_panel/GameTabRightPanel.cpp +++ b/src/game_tab/right_panel/GameTabRightPanel.cpp @@ -28,7 +28,7 @@ GameTabRightPanel::GameTabRightPanel(wxFrame *parent, std::shared_ptr game nag_panel->Bind(wxEVT_BUTTON, [p=this](wxCommandEvent &e){ HalfMove *m = p->game->GetCurrentMove(); if (m != nullptr) { - m->nag=p->GetNagFromStr(((wxButton*)e.GetEventObject())->GetLabel().ToStdString()); + m->SetNAG(p->editor_canvas->GetNAGId(((wxButton*)e.GetEventObject())->GetLabel().ToStdString())); p->editor_canvas->Refresh(); } }); @@ -103,9 +103,9 @@ void GameTabRightPanel::OnCommentChange(wxCommandEvent &event) { wxLogDebug("GameTabRightPanel: comment input change"); HalfMove *m = game->GetCurrentMove(); if (m != nullptr) { - m->comment=event.GetString().Trim().ToStdString(); + m->SetComment(event.GetString().Trim().ToStdString()); // Remove newlines: - for(char &c:m->comment){ + for(char &c:m->GetComment()){ if(c=='\n') c=' '; } @@ -150,7 +150,7 @@ void GameTabRightPanel::Notify() { HalfMove *m = game->GetCurrentMove(); if (m != nullptr) { comment_input->ChangeValue( - m->comment); // ChangeValue do not raise events + m->GetComment()); // ChangeValue do not raise events } editor_canvas->SetMoves(game->GetMoves(), m); // Put it here for now: @@ -190,49 +190,49 @@ void GameTabRightPanel::RefreshTagsList() { } } -std::string GameTabRightPanel::GetNagFromStr(std::string str){ +std::uint8_t GameTabRightPanel::GetNagFromStr(std::string str){ // TODO: Bind more NAG! if(str=="!") - return "$1"; + return 1; else if(str=="?") - return "$2"; + return 2; else if(str=="!!") - return "$3"; + return 3; else if(str=="??") - return "$4"; + return 4; else if(str=="!?") - return "$5"; + return 5; else if(str=="?!") - return "$6"; + return 6; else if(str=="=") - return "$10"; + return 10; else if(str=="∞") - return "$13"; + return 13; else if(str=="⩲") - return "$14"; + return 14; else if(str=="⩱") - return "$15"; + return 15; else if(str=="±") - return "$16"; + return 16; else if(str=="∓") - return "$17"; + return 17; else if(str=="+-") - return "$18"; + return 18; else if(str=="-+") - return "$19"; + return 19; else if(str=="⨀") - return "$22"; + return 22; else if(str=="○") - return "$26"; + return 26; else if(str=="⟳") - return "$32"; + return 32; else if(str=="↑") - return "$36"; + return 36; else if(str=="→") - return "$40"; + return 40; else if(str=="⯹") - return "$44"; + return 44; else if(str=="⨁") - return "$138"; - return ""; + return 138; + return 0; } diff --git a/src/game_tab/right_panel/GameTabRightPanel.hpp b/src/game_tab/right_panel/GameTabRightPanel.hpp index 903b83d..73b058a 100644 --- a/src/game_tab/right_panel/GameTabRightPanel.hpp +++ b/src/game_tab/right_panel/GameTabRightPanel.hpp @@ -30,5 +30,5 @@ public: void OnLiveAnalysis(wxCommandEvent &event); void ApplyPreferences(); void OnLiveEngineClose(wxCloseEvent &e); - std::string GetNagFromStr(std::string str); + std::uint8_t GetNagFromStr(std::string str); }; \ No newline at end of file diff --git a/src/game_tab/right_panel/editor/EditorCanvas.cpp b/src/game_tab/right_panel/editor/EditorCanvas.cpp index 0e413c8..9f9c2e3 100644 --- a/src/game_tab/right_panel/editor/EditorCanvas.cpp +++ b/src/game_tab/right_panel/editor/EditorCanvas.cpp @@ -115,52 +115,7 @@ void EditorCanvas::DrawElement(const cgeditor::Element &e) { dc->DrawRectangle(recToDraw); } if(e.prop & cgeditor::Property::Nag){ - if(text=="$0") - text=""; - else if(text=="$1") - text="!"; - else if(text=="$2") - text="?"; - else if(text=="$3") - text="!!"; - else if(text=="$4") - text="??"; - else if(text=="$5") - text="!?"; - else if(text=="$6") - text="?!"; - else if(text=="$10") - text="="; - else if(text=="$13") - text="∞"; - else if(text=="$14") - text="⩲"; - else if(text=="$15") - text="⩱"; - else if(text=="$16") - text="±"; - else if(text=="$17") - text="∓"; - else if(text=="$18") - text="+-"; - else if(text=="$19") - text="-+"; - else if(text=="$22"||text=="$23") - text="⨀"; - else if(text=="$26"||text=="$27") - text="○"; - else if(text=="$32"||text=="$33") - text="⟳"; - else if(text=="$36"||text=="$37") - text="↑"; - else if(text=="$40"||text=="$41") - text="→"; - else if(text=="$44" || text=="$45") - text="⯹"; - else if(text=="$138" || text=="$139") - text="⨁"; - else - text="NA"; + text=e.text; } // Draw move text if (CGEditor::status.UseMoveIcons) { @@ -177,12 +132,16 @@ void EditorCanvas::DrawElement(const cgeditor::Element &e) { void EditorCanvas::HandleEvent(const cgeditor::Event &e) { if (e.type == cgeditor::Event::Goto) { game->SetCurrent((HalfMove *)e.move); + SyncCache(); } else if (e.type == cgeditor::Event::Delete) { - game->DeleteMove((HalfMove *)e.move); + game->DeleteMove((HalfMove *)e.move); + SyncCache(); } else if (e.type == cgeditor::Event::Promote) { game->PromoteMove((HalfMove *)e.move); + SyncCache(); } else if (e.type == cgeditor::Event::SetAsMainline) { - game->SetMoveAsMainline((HalfMove *)e.move); + game->SetMoveAsMainline((HalfMove *)e.move); + SyncCache(); } wxCommandEvent event(GAME_CHANGE, GetId()); event.SetEventObject(this);