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

How to get comment of a move? #30

Closed
horaceho opened this issue Nov 27, 2015 · 11 comments
Closed

How to get comment of a move? #30

horaceho opened this issue Nov 27, 2015 · 11 comments
Assignees

Comments

@horaceho
Copy link

After a game is loaded, how can I

  • goto the first upcoming move which contains a comment, and
  • get the comment text of a move?

Thanks

@adamreisnz
Copy link
Owner

Great question, I don't seem to have created an easy interface to deal with comments yet. I'll look into improving that and will update the demo's to include comments.

For now, you can do something like this (try in demo-player.html):

<p>
  Comments:<br>
  <span ng-repeat="comment in Game.node.comments">{{comment}}<br></span>
</p>

You can access the current tree node via Game.node, and if there are comments it will be an array with string comments in it, so you can navigate the game nodes via game.next() and then check if game.node.comments is empty or not.

I will add some enhancements to let game.next() return true or false based on the success state, and also some helpers to determine the number of moves in the game etc.

@adamreisnz adamreisnz self-assigned this Nov 27, 2015
@adamreisnz
Copy link
Owner

I've had another look at the code and I think the easiest way for you to programmatically find nodes with comments would be something like this:

//Load JGF data into a new game object
var game = new Game(jgf);

//Get the root node
var node = game.root;
var firstComment = '';

//Process children
while (node.children.length > 0) {

  //Get the first variation
  //Optionally, you can process all the children (variation nodes)
  node = node.children[0];

  //Check if comments present in node
  if (typeof node.comments !== 'undefined') {
    firstComment = node.comments.join('\n\n');
    break;
  }
}

Let me know if that helps.

@horaceho
Copy link
Author

horaceho commented Dec 1, 2015

Great! Even better if there are APIs for the above, something like:

 Player.nextWithComment()
 Player.nextWithVariation()
 Player.nextWithCommentOrVariation()
 Player.previousWithComment()
 Player.previousWithVariation()
 Player.previousWithCommentOrVariation()

Plus navigation APIs inside variations (I have not looked into this part yet), users can easily traverse among game comments and variations.

@adamreisnz
Copy link
Owner

Thanks for the suggestion, I will look into adding methods like that to the player.

The Game service API contains methods for navigating between variations, try:

Game.next(i); //Where i is the variation number
Game.lastFork()

I will add the lastFork method to Player as well.

@adamreisnz
Copy link
Owner

Added in 1.2.2

@horaceho
Copy link
Author

horaceho commented Dec 1, 2015

Thank you!

@adamreisnz
Copy link
Owner

I have added the following methods to the Game and Player services in version 1.2.5:

Player.previousFork(); //renamed from Player.lastFork()
Player.nextFork();
Game.previousFork(); //renamed from Game.lastFork()
Game.nextFork();

I have also added some example code to the demo-player.html to illustrate how you can display variations with their name and navigate to them. It also illustrates how to use the nextFork() and previousFork() methods.

As for the comments, I don't feel this should be the responsibility of the player, as it feels like business logic to me which might be specific to your implementation of the player. However, you can feel free to extend the Player service using a decorator and add those methods if needed, or do it via scoped controller methods instead.

Let me know if there's anything else I can help with.

@horaceho
Copy link
Author

horaceho commented Dec 2, 2015

Thanks very much for the update!

Regards comments, I'd like to suggest a scenario which may bring convenience for Player UI building.

In a commented game record, typically pro game record, a comment show up every ten or so moves. So a game with very detail comments usually are broken down to fifteen to twenty or so diagrams.

For example, if there are comments in move 17 and 29, in early part of a game. Of course, the user can click Next Move 17 times and see the first comment. Another presentation is, when the user click "Next Comment" button, the Player will stop at move 29, shows number for the moves from 18 to 29, and usually the pro comment tells what's happening in the moves, something like, "move 20 is strong, move 25 is weak, move 29 is forcing white to the edges..."

In the above scenario, a lookup/jump to next/previous comment API will be very helpful, for example:

 Player.nextComment();
 node = Game.previousComment().next();
 fromMove = node.moveNumber();
 toMove = Game.currentNode().moveNumber();
 Player.showMoveNumbers(fromMove, toMove);

@adamreisnz adamreisnz reopened this Dec 2, 2015
@adamreisnz
Copy link
Owner

Yeah, I suppose it could come in handy for review of games. Alright, I'll add something in for navigating to/from comments.

I also like the idea of an API to number some or all of the moves. Will add that in as well.

@adamreisnz
Copy link
Owner

Added the following API methods in 1.3.0:

Player.nextComment();
Player.previousComment();
Player.showMoveNumbers(fromMove, toMove);
Game.nextComment();
Game.previousComment();
Game.getMoveNodes(fromMove, toMove);
Game.getMoveNode(move);

The following already existed:

Game.getNode() //Get current node

There's a small issue regarding setup nodes being counted as move nodes. I will address that shortly. But it should work fine for game records without setup nodes.

@horaceho
Copy link
Author

horaceho commented Dec 2, 2015

Wonderful! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants