From 638ad1fd2d2dcd72123def9b9cf57305c26db888 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Sat, 5 Jun 2021 20:41:53 +0200 Subject: [PATCH] keep a string of moves/comments when parsing PGN. --- CHESS_JSON.php | 13 ++++++++----- PgnGameParser.php | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHESS_JSON.php b/CHESS_JSON.php index 57cd594..7f9a77e 100755 --- a/CHESS_JSON.php +++ b/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) .';'; } -} \ No newline at end of file +} diff --git a/PgnGameParser.php b/PgnGameParser.php index 8ef93fc..7cb7ba7 100755 --- a/PgnGameParser.php +++ b/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); } -} \ No newline at end of file +}