oakmac / chessboardjs

JavaScript chessboard
https://chessboardjs.com
MIT License
2.01k stars 408 forks source link

How can I change the piece theme after the board is created? #215

Open frazereastman opened 3 years ago

frazereastman commented 3 years ago

I am creating a chess opening trainer and want to know how I can change the piece theme after the board has been generated using the config settings? Thank you in advance.

hcgreier commented 2 years ago

Hi,

simply put the png files of your theme in a subfolder. They must be named bB.png, bK.png,...,wB.png, wK.png and so on. Then trigger your board and set the correct folder path in the settings object.

let pieceSetup ....(some script to get the folder name)

let board = Chessboard('yourBoardID', {
  pieceTheme: `[path to your themes folder]/${pieceSetup}/{piece}.png`,
  // other settings...
});

Variable "pieceSetup" is the subfolder name with your png files of the pieces. As this is in a string literal you can change it with your script.

greets, hc