Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: premoved piece disappearing #120

Merged
merged 4 commits into from
Jan 23, 2024

Conversation

Manukyanq
Copy link
Contributor

The fix of #118

Copy link

vercel bot commented Dec 25, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-chessboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 23, 2024 4:58pm

@Manukyanq
Copy link
Contributor Author

I've fixed also another issue, when two premoved pieces target the same square the last premoved piece should be visible not the first one. In the example below, we do two premoves: rook to a1, then queen to a1, and logically the queen should be visible after these two moves not the rook

Screen.Recording.2023-12-28.at.13.24.37.mov

@@ -18,6 +19,38 @@ export function Squares() {
showBoardNotation,
} = useChessboard();

const premovesHistory: any[] = useMemo(() => {
Copy link
Contributor Author

@Manukyanq Manukyanq Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this make sense to be upped to the chessboard-context state, and keep all the premoves in this new format ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

premoves: [
    {
      sourceSq: "f1",
      targetSq: "e2",
      piece: "wB",
    },
    {
      sourceSq: "c2",
      targetSq: "d3",
      piece: "wP",
    },
    {
      sourceSq: "e2",
      targetSq: "d3",
      piece: "wB",
    },
    {
      sourceSq: "g1",
      targetSq: "f3",
      piece: "wN",
    },
    {
      sourceSq: "f3",
      targetSq: "g1",
      piece: "wN",
    },
    {
      sourceSq: "g1",
      targetSq: "f3",
      piece: "wN",
    },
  ],

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

premovesHistory: [
    {
      piece: "wN",
      premovesRoute: [
        {
          sourceSq: "g1",
          targetSq: "f3",
        },
        {
          sourceSq: "f3",
          targetSq: "g1",
        },
        {
          sourceSq: "g1",
          targetSq: "f3",
        },
      ],
      index: 5,
    },
    {
      piece: "wB",
      premovesRoute: [
        {
          sourceSq: "f1",
          targetSq: "e2",
        },
        {
          sourceSq: "e2",
          targetSq: "d3",
        },
      ],
      index: 2,
    },
    {
      piece: "wP",
      premovesRoute: [
        {
          sourceSq: "c2",
          targetSq: "d3",
        },
      ],
      index: 1,
    },
  ],

@Clariity
Copy link
Owner

Could an option be to look through the premove queue backwards and see what the latest premove target on the square is?

Am away from my pc now until mid January so won't be able to look deeply into it

@Manukyanq
Copy link
Contributor Author

Could an option be to look through the premove queue backwards and see what the latest premove target on the square is?

Am away from my pc now until mid January so won't be able to look deeply into it

I think the complexity is the same. Or do I miss something?

src/chessboard/components/Squares.tsx Outdated Show resolved Hide resolved
src/chessboard/components/Squares.tsx Outdated Show resolved Hide resolved
src/chessboard/components/Squares.tsx Outdated Show resolved Hide resolved
src/chessboard/components/Squares.tsx Outdated Show resolved Hide resolved
src/chessboard/components/Squares.tsx Outdated Show resolved Hide resolved
src/chessboard/components/Squares.tsx Outdated Show resolved Hide resolved
@Clariity Clariity merged commit d78dff4 into Clariity:main Jan 23, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants