shaack / cm-chessboard

A JavaScript chessboard without dependencies. Rendered in SVG, coded in ES6. Views FEN, handles move input, animated, responsive, expandable
MIT License
209 stars 63 forks source link

Behaviour of enableMoveInput(eventHandler, color = undefined) #115

Closed djeetee closed 1 year ago

djeetee commented 1 year ago

Hi Stefan,

could you shed some light on the behaviour of enableMoveInput() when the color is not specified? In other words, how does (or could) the method determine which side to enable input for?

The reason for the question is hard to explain but I'm experiencing frozen boards (i have multiple concurrently open ones) when the color is specified but some seem to behave normally when the color is not specified.

Another thing i noticed is that Chrome gives me a memory low error in its dev tools when color is specified.

More info (maybe useful): say it is black to move. I click one of white's pieces, moveInputStarted is triggered for white but i cannot complete the move. I then click one of black's pieces and complete the move. the move is completed but i get the following error:

image

The error seems to be happening inside VueJS

This is how set up the inputHandler:

    activeBoard.board.enableMoveInput(
      (event) => this.inputHandler(event),
      activeBoard.turn
    )

I don't think I'm handling enablingMoveInput correctly but then again if I always move the piece of the side whose turn it is everything works perfectly.

I just think that for some reason, the board is getting confused about whose turn it is.

While on the topic of enableMoveInput() is there a reason why would a moveInputStarted event is triggered when a piece is clicked but no validateMoveInput event follows when a valid destination is clicked? I have noticed this happening when the board becomes unresponsive for either side.

thank you,

shaack commented 1 year ago

Hard to say, maybe you enable the MoveInput many multiple times and don't disable it.

djeetee commented 1 year ago

Hey Stefan, I took a break and reviewed the code. Sure enough it was a bug in my code that was causing all the issues I was inquiring about. That caused the validateMoveInput event not to fire. It also caused the whole inputHandler() to misbehave when using the color parameter.

I still get the occasional Message length exceeded.... in Chrome and I'm unable to figure out what is causing it. Lots of reports online about that message in different environment and nothing specific.

So, cm-chessboard is still humming along beautifully and I'm very happy with what I was able to achieve with it. Can't wait to share the final product when it's done. Lots more to work on still.

thanks for getting back to me.

shaack commented 1 year ago

Hi! Many thanks for your feedback. Glad to hear that it kind of works now. Unfortunately i have not seen yet these "Message length exceeded" messages yet. For me it looks also more like a thing of Vue when I google about it. I look forward to read more about your project. Don't hesitate to ask, if you have more questions about the cm-chessboard or my other projects. BTW, I read about your z80 coding in your profile, my first computer was a ZX Spectrum. 👍

djeetee commented 1 year ago

Ah! the Spectrum and its gummy keyboard. the good o'days! my next project is a time machine to travel back. I miss hearing the sound of the loading programs off the cassette tapes. Funny.

shaack commented 1 year ago

Haha, yes, like waiting 45 minutes for a program to load and having a loading error after 30 minutes. :) I loved the sound. Also the keyboard. It was very fast in coding because all possible commands have been as shortcuts on the keyboard. Therefore and because of the gummy keyboard, coding was more like kneading on the ZX Spectrum.