Browse Source

keep a string of moves/comments when parsing PGN.

master
Bruno Raoult 6 months ago
parent
commit
638ad1fd2d
  1. 13
      CHESS_JSON.php
  2. 3
      PgnGameParser.php

13
CHESS_JSON.php

@ -11,6 +11,7 @@ class CHESS_JSON {
const MOVE_ACTIONS = 'actions';
const MOVE_VARIATIONS = 'variations';
const MOVE_MOVES = 'moves';
const MOVE_MOVES_STRING = 'movesStr';
const MOVE_CAPTURE = 'capture';
const MOVE_PROMOTE_TO = 'promoteTo';
const MOVE_CASTLE = 'castle';
@ -29,10 +30,12 @@ class CHESS_JSON {
const PGN_KEY_ACTION_CLR_ARROW = "cal";
protected static $jsKeys = array('MOVE_FROM', 'MOVE_TO', 'MOVE_NOTATION', 'FEN','MOVE_COMMENT',
'MOVE_ACTION', 'MOVE_VARIATIONS', 'MOVE_MOVES','MOVE_CAPTURE','MOVE_PROMOTE_TO','MOVE_CASTLE',
'GAME_METADATA', 'GAME_EVENT', 'GAME_WHITE','GAME_BLACK', 'GAME_ECO',
protected static $jsKeys = array(
'MOVE_FROM', 'MOVE_TO', 'MOVE_NOTATION', 'FEN',
'MOVE_COMMENT', 'MOVE_ACTION', 'MOVE_VARIATIONS', 'MOVE_MOVES',
'MOVE_MOVES_STRING', 'MOVE_CAPTURE', 'MOVE_PROMOTE_TO', 'MOVE_CASTLE',
'GAME_METADATA', 'GAME_EVENT', 'GAME_WHITE', 'GAME_BLACK',
'GAME_ECO',
);
public static function toJavascript(){
@ -42,4 +45,4 @@ class CHESS_JSON {
}
return 'ludo.CHESS_JSON_KEY = ' . json_encode($ret) .';';
}
}
}

3
PgnGameParser.php

@ -28,6 +28,7 @@ class PgnGameParser{
public function getParsedData(){
$this->gameData = $this->getMetadata();
$this->gameData[CHESS_JSON::MOVE_MOVES_STRING] = $this->getMoveString();
$this->gameData[CHESS_JSON::MOVE_MOVES] = $this->getMoves();
return $this->gameData;
}
@ -140,4 +141,4 @@ class PgnGameParser{
$gameData = preg_replace("/(\s+)/", " ", $gameData);
return trim($gameData);
}
}
}

Loading…
Cancel
Save