From 8df306c9e96eea6beee79b6afa452dbf531b69ab Mon Sep 17 00:00:00 2001 From: Metehan Gezer Date: Thu, 12 Oct 2023 16:10:48 +0300 Subject: [PATCH] check all pieces --- .github/workflows/build-windows.yml | 39 ---------- .github/workflows/build-windows.yml.disabled | 75 ++++++++++++++++++++ CMakeLists.txt | 12 +++- src/canvas/game_canvas.cpp | 2 - src/canvas/loading_canvas.cpp | 4 +- src/canvas/loading_canvas.h | 2 +- src/canvas/menu_canvas.cpp | 70 +++++++++--------- src/canvas/menu_canvas.h | 10 +-- src/chess/chess_board.cpp | 15 ++-- znet | 2 +- 10 files changed, 134 insertions(+), 97 deletions(-) delete mode 100644 .github/workflows/build-windows.yml create mode 100644 .github/workflows/build-windows.yml.disabled diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml deleted file mode 100644 index 39786da..0000000 --- a/.github/workflows/build-windows.yml +++ /dev/null @@ -1,39 +0,0 @@ -# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage. -# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml -name: Build Windows - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Release - -jobs: - build: - # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. - # You can convert this to a matrix build if you need cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: windows-latest - - steps: - - uses: actions/checkout@v3 - - - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - - name: Build - # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - - name: Test - working-directory: ${{github.workspace}}/build - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{env.BUILD_TYPE}} - diff --git a/.github/workflows/build-windows.yml.disabled b/.github/workflows/build-windows.yml.disabled new file mode 100644 index 0000000..ab00028 --- /dev/null +++ b/.github/workflows/build-windows.yml.disabled @@ -0,0 +1,75 @@ +# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml +name: Build Windows + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +# https://github.com/GlistEngine/glistzbin-win64/releases/download/v.2.0.2/glistzbin-win64-2.0.2.zip +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: windows-2022 + + steps: + - uses: actions/checkout@v3 + + - name: checkout submodule + run: | + git submodule update --init --recursive + + #working-directory: ${{github.workspace}}/glist/myglistapps/${{github.repository}} + - name: Set path + run: | + Add-Content $env:GITHUB_PATH "D:/a/chesstacos/chesstacos/zbin/glistzbin-win64/clang64/bin" + Add-Content $env:GITHUB_PATH "D:/a/chesstacos/chesstacos/zbin/glistzbin-win64/CMake/bin" + + - name: Clone GlistEngine + uses: GuillaumeFalourd/clone-github-repo-action@v2.2 + with: + depth: 1 + branch: 'main' + owner: 'GlistEngine' + repository: 'GlistEngine' + + - name: cd zbin + run: | + mkdir ${{github.workspace}}/zbin + cd ${{github.workspace}}/zbin + + - name: Download zbin + uses: suisei-cn/actions-download-file@v1 + id: glistzbin-win64 # Remember to give an ID if you need the output + with: + url: 'https://github.com/GlistEngine/glistzbin-win64/releases/download/v.2.0.2/glistzbin-win64-2.0.2.zip' + target: ${{github.workspace}}/zbin + + - name: Extract zip + run: | + 7z l "D:/a/chesstacos/chesstacos/zbin/glistzbin-win64-2.0.2.zip" + 7z x "D:/a/chesstacos/chesstacos/zbin/glistzbin-win64-2.0.2.zip" -o"D:/a/chesstacos/chesstacos/zbin" + + - name: List + run: | + cd ${{github.workspace}} + tree /f + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B '${{github.workspace}}/build' -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTOP_DIR='D:/a/chesstacos/chesstacos' -S . + + - name: Build + # Build your program with the given configuration + run: cmake --build '${{github.workspace}}/build' --config ${{env.BUILD_TYPE}} + + diff --git a/CMakeLists.txt b/CMakeLists.txt index 6accc79..c765071 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,8 +25,12 @@ endif() # Clang compiler definition for Windows. Do not change this value for other OS. # For UNIX like systems, configure the compiler via OS commands. if(WIN32) - set(CMAKE_C_COMPILER "${CMAKE_SOURCE_DIR}/../../zbin/glistzbin-win64/clang64/bin/clang.exe") - set(CMAKE_CXX_COMPILER "${CMAKE_SOURCE_DIR}/../../zbin/glistzbin-win64/clang64/bin/clang++.exe") + if(NOT DEFINED CMAKE_C_COMPILER) + set(CMAKE_C_COMPILER "${CMAKE_SOURCE_DIR}/../../zbin/glistzbin-win64/clang64/bin/clang.exe") + endif() + if(NOT DEFINED CMAKE_CXX_COMPILER) + set(CMAKE_CXX_COMPILER "${CMAKE_SOURCE_DIR}/../../zbin/glistzbin-win64/clang64/bin/clang++.exe") + endif() endif(WIN32) @@ -65,7 +69,9 @@ set(APP_DIR ${CMAKE_SOURCE_DIR}) project (${APP_NAME}) set(CMAKE_BUILD_TYPE Debug) -set(TOP_DIR ${APP_DIR}/../..) +if(NOT DEFINED TOP_DIR) + set(TOP_DIR ${APP_DIR}/../..) +endif() set(MAIN_DIR ${TOP_DIR}/GlistEngine) set(ENGINE_DIR ${MAIN_DIR}/engine) diff --git a/src/canvas/game_canvas.cpp b/src/canvas/game_canvas.cpp index 65a2afa..2b9335b 100644 --- a/src/canvas/game_canvas.cpp +++ b/src/canvas/game_canvas.cpp @@ -156,7 +156,6 @@ bool GameCanvas::Move(int x, int y, int to_x, int to_y) { if (piece->GetType() == kPieceTypePawn) { if (to_y == 0 && piece->GetColor() == kPieceColorBlack) { // black promote - // promote after switch if (player_color_ == kPieceColorBlack) { SetInfoText("Promote your pawn!"); promoting_ = true; @@ -172,7 +171,6 @@ bool GameCanvas::Move(int x, int y, int to_x, int to_y) { } } else if (to_y == 7 && piece->GetColor() == kPieceColorWhite) { // white promote - // promote after switch if (player_color_ == kPieceColorWhite) { SetInfoText("Promote your pawn!"); promoting_ = true; diff --git a/src/canvas/loading_canvas.cpp b/src/canvas/loading_canvas.cpp index f8c74d5..23df902 100644 --- a/src/canvas/loading_canvas.cpp +++ b/src/canvas/loading_canvas.cpp @@ -2,7 +2,7 @@ #include "menu_canvas.h" LoadingCanvas::LoadingCanvas(gApp* root) : gBaseCanvas(root) { - this->root = root; + this->root_ = root; } LoadingCanvas::~LoadingCanvas() { @@ -45,7 +45,7 @@ void LoadingCanvas::draw() { renderer->setColor(255, 255, 255, std::min(opacity, 255)); glist_logo_.draw(glist_x_, glist_y_, glist_width_, glist_height_); } else { - root->setCurrentCanvas(new MenuCanvas(root)); + root_->setCurrentCanvas(new MenuCanvas(root_)); } renderer->setColor(old_color); } diff --git a/src/canvas/loading_canvas.h b/src/canvas/loading_canvas.h index b63999e..571daf2 100644 --- a/src/canvas/loading_canvas.h +++ b/src/canvas/loading_canvas.h @@ -35,7 +35,7 @@ class LoadingCanvas : public gBaseCanvas { void hideNotify() {} private: - gApp* root; + gApp* root_; gImage brand_logo_; int brand_width_, brand_height_, brand_x_, brand_y_; gImage glist_logo_; diff --git a/src/canvas/menu_canvas.cpp b/src/canvas/menu_canvas.cpp index 01afc64..d72b294 100644 --- a/src/canvas/menu_canvas.cpp +++ b/src/canvas/menu_canvas.cpp @@ -5,7 +5,7 @@ #include "task_canvas.h" MenuCanvas::MenuCanvas(gApp* root) : gBaseCanvas(root) { - this->root = root; + this->root_ = root; } MenuCanvas::~MenuCanvas() { @@ -14,12 +14,12 @@ MenuCanvas::~MenuCanvas() { void MenuCanvas::setup() { int buttons_x = getWidth() / 2; int buttons_y = getHeight() / 2 + 100; - join_button = new Button("JOIN", buttons_x, buttons_y, 180, 60); - host_button = new Button("HOST", buttons_x, buttons_y + 70, 180, 60); - quit_button = new Button("QUIT", buttons_x, buttons_y + 140, 180, 60); - logo_font.loadFont("PixeloidSansBold.ttf", 64, false, 80); - fade_in_ = !root->loaded_; - root->loaded_ = true; + join_button_ = new Button("JOIN", buttons_x, buttons_y, 180, 60); + host_button_ = new Button("HOST", buttons_x, buttons_y + 70, 180, 60); + quit_button_ = new Button("QUIT", buttons_x, buttons_y + 140, 180, 60); + logo_font_.loadFont("PixeloidSansBold.ttf", 64, false, 80); + fade_in_ = !root_->loaded_; + root_->loaded_ = true; fade_in_timer_ = 0.0f; fade_color_ = CreateRGB(0x1c1e25); back_color_ = CreateRGB(0x4c5465); @@ -37,17 +37,17 @@ void MenuCanvas::update() { return; } - join_button->Update(); - host_button->Update(); - quit_button->Update(); - if (host_button->GetState() == ButtonState::Pressed) { - host_button->Lock(); - root->setCurrentCanvas(new TaskCanvas(root, CreateRef(root))); - } else if (join_button->GetState() == ButtonState::Pressed) { - join_button->Lock(); - root->setCurrentCanvas(new JoinCanvas(root)); - } else if (quit_button->GetState() == ButtonState::Pressed) { - quit_button->Lock(); + join_button_->Update(); + host_button_->Update(); + quit_button_->Update(); + if (host_button_->GetState() == ButtonState::Pressed) { + host_button_->Lock(); + root_->setCurrentCanvas(new TaskCanvas(root_, CreateRef(root_))); + } else if (join_button_->GetState() == ButtonState::Pressed) { + join_button_->Lock(); + root_->setCurrentCanvas(new JoinCanvas(root_)); + } else if (quit_button_->GetState() == ButtonState::Pressed) { + quit_button_->Lock(); appmanager->stop(); } } @@ -62,43 +62,43 @@ void MenuCanvas::draw() { setColor(255, 255, 255, std::min((int) ((fade_in_timer_ - 0.5f) * 255.0f), 255)); } // buttons - join_button->Draw(); - host_button->Draw(); - quit_button->Draw(); + join_button_->Draw(); + host_button_->Draw(); + quit_button_->Draw(); // logo - RenderUtil::DrawFont(&logo_font, "Chess Tacos", getWidth() / 2 - logo_font.getStringWidth("Chess Tacos") / 2, 150, 8); + RenderUtil::DrawFont(&logo_font_, "Chess Tacos", getWidth() / 2 - logo_font_.getStringWidth("Chess Tacos") / 2, 150, 8); setColor(og_color); RenderUtil::DrawFont(kVersion, 0, getHeight() - 33, {100, 100, 100}, false, true); - root->DrawCursor(); + root_->DrawCursor(); } void MenuCanvas::mouseMoved(int x, int y) { - root->SetCursorPos(x, y); + root_->SetCursorPos(x, y); if (fade_in_) { return; } - join_button->OnMouseMoved(x, y); - host_button->OnMouseMoved(x, y); - quit_button->OnMouseMoved(x, y); + join_button_->OnMouseMoved(x, y); + host_button_->OnMouseMoved(x, y); + quit_button_->OnMouseMoved(x, y); } void MenuCanvas::mousePressed(int x, int y, int button) { - root->SetCursorType(CursorType::kHandClosed); + root_->SetCursorType(CursorType::kHandClosed); if (fade_in_) { return; } - join_button->OnMousePressed(x, y); - host_button->OnMousePressed(x, y); - quit_button->OnMousePressed(x, y); + join_button_->OnMousePressed(x, y); + host_button_->OnMousePressed(x, y); + quit_button_->OnMousePressed(x, y); } void MenuCanvas::mouseReleased(int x, int y, int button) { - root->SetCursorType(CursorType::kArrow); + root_->SetCursorType(CursorType::kArrow); if (fade_in_) { return; } - join_button->OnMouseReleased(x, y); - host_button->OnMouseReleased(x, y); - quit_button->OnMouseReleased(x, y); + join_button_->OnMouseReleased(x, y); + host_button_->OnMouseReleased(x, y); + quit_button_->OnMouseReleased(x, y); } diff --git a/src/canvas/menu_canvas.h b/src/canvas/menu_canvas.h index 803dbb3..771163d 100644 --- a/src/canvas/menu_canvas.h +++ b/src/canvas/menu_canvas.h @@ -40,11 +40,11 @@ class MenuCanvas : public gBaseCanvas { void hideNotify() {} private: - gApp* root; - Button* join_button; - Button* host_button; - Button* quit_button; - gFont logo_font; + gApp* root_; + Button* join_button_; + Button* host_button_; + Button* quit_button_; + gFont logo_font_; bool fade_in_; RGB fade_color_; RGB back_color_; diff --git a/src/chess/chess_board.cpp b/src/chess/chess_board.cpp index 3c709d4..c39de42 100644 --- a/src/chess/chess_board.cpp +++ b/src/chess/chess_board.cpp @@ -60,15 +60,12 @@ bool ChessBoard::IsValidMove(int x, int y, int to_x, int to_y) { return false; } if (piece->IsValidMove(x, y, to_x, to_y)) { - if (piece->GetType() == kPieceTypeKing) { - SetPiece(to_x, to_y, piece); - SetPiece(x, y, nullptr); - auto state = CheckState(GetOppositeColor(piece->GetColor())); - SetPiece(x, y, piece); - SetPiece(to_x, to_y, to_piece); - return state == ChessState::Playing; - } - return true; + SetPiece(to_x, to_y, piece); + SetPiece(x, y, nullptr); + auto state = CheckState(GetOppositeColor(piece->GetColor())); + SetPiece(x, y, piece); + SetPiece(to_x, to_y, to_piece); + return state == ChessState::Playing; } return false; } diff --git a/znet b/znet index 795c576..7e7fda0 160000 --- a/znet +++ b/znet @@ -1 +1 @@ -Subproject commit 795c576ea372d8847e78ca95f4c216bcb32073de +Subproject commit 7e7fda0b43b6c77b0ace904bfb2a6f0d370660b7