yo35 / kokopu

A JavaScript/TypeScript library implementing the chess game rules and providing tools to read/write the standard chess file formats.
https://www.npmjs.com/package/kokopu
GNU Lesser General Public License v3.0
27 stars 5 forks source link

Variations don't interpret comments before first move. #10

Closed danegraphics closed 4 years ago

danegraphics commented 4 years ago

Often in PGN you'll find comments before the first move to describe the game. And in variations on a move, you'll see a comment before the first move of the variation that describes the whole variation, and not the move specifically.

For example:

{Let's look at some openings} 1. e4 e5 {A classic move} ({Here's the Sicilian instead} 1... c5 {This move attacks d4, taking control of the center})

Both "Let's look at some openings" and "Here's the Sicilian instead" get dropped by pgnRead()

danegraphics commented 4 years ago

In short, I propose that the Variation class have a comment() method that applies to itself, and not to any node.

danegraphics commented 4 years ago

Turns out this exists but is undocumented.

yo35 commented 4 years ago

Hi. Thanks for reporting. This is indeed missing in the documentation, I'll fixed that.

danegraphics commented 4 years ago

@yo35 - In the documentation, could you also include examples of usage? Something that covers a lot more of the API, like the following:


//get the first (or only game) of the pgn
var databaseOfGames = kokopu.pgnRead(pgn);
var firstGame = databaseOfGames.game(0);
//get the variation
var variation = game.mainVariation();
//get the first ply of the variation
var node = variation.first();
//get the comment of the first ply
var comment = node.comment();```
yo35 commented 4 years ago

Tutorials added in documentation as of version 1.3.1.