Reserved metadata moved from metadata sub array
This commit is contained in:
@@ -1384,5 +1384,4 @@ class FenParser0x88
|
||||
}
|
||||
return $fen . " ". $this->getColorCode(). " ". $this->getCastle()." ". $this->fenParts['enPassant']." ". $this->getHalfMoves()." ". $this->getFullMoves();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -54,6 +54,6 @@ class GameParser {
|
||||
}
|
||||
|
||||
private function getStartFen(){
|
||||
return $this->game[CHESS_JSON::GAME_METADATA][CHESS_JSON::FEN];
|
||||
return $this->game[CHESS_JSON::FEN];
|
||||
}
|
||||
}
|
@@ -8,27 +8,35 @@ class PgnGameParser{
|
||||
|
||||
private $gameData = array();
|
||||
|
||||
private $specialMetadata = array(
|
||||
'event','site','white','black','result','plycount','eco','fen','timecontrol','round','date','annotator','termination'
|
||||
);
|
||||
|
||||
public function __construct($pgnGame){
|
||||
$this->pgnGame = trim($pgnGame);
|
||||
#echo $this->pgnGame."<br>";
|
||||
$this->moveBuilder = new MoveBuilder();
|
||||
}
|
||||
|
||||
public function getParsedData(){
|
||||
$this->gameData = array();
|
||||
$this->gameData[CHESS_JSON::GAME_METADATA] = $this->getMetadata();
|
||||
$this->gameData = $this->getMetadata();
|
||||
$this->gameData[CHESS_JSON::MOVE_MOVES] = $this->getMoves();
|
||||
return $this->gameData;
|
||||
}
|
||||
|
||||
private function getMetadata(){
|
||||
$ret = array();
|
||||
$ret = array(
|
||||
CHESS_JSON::GAME_METADATA=>array()
|
||||
);
|
||||
$lines = explode("\n", $this->pgnGame);
|
||||
foreach($lines as $line){
|
||||
$line = trim($line);
|
||||
if(substr($line, 0, 1) === '[' && substr($line, strlen($line)-1, 1) === ']'){
|
||||
$metadata = $this->getMetadataKeyAndValue($line);
|
||||
$ret[$metadata['key']] = $metadata['value'];
|
||||
if(in_array($metadata['key'], $this->specialMetadata)){
|
||||
$ret[$metadata['key']] = $metadata['value'];
|
||||
}else{
|
||||
$ret[CHESS_JSON::GAME_METADATA][$metadata['key']] = $metadata['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!isset($ret[CHESS_JSON::FEN])) {
|
||||
|
@@ -100,23 +100,3 @@ class PgnParser {
|
||||
return $this->games;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors','on');
|
||||
|
||||
require_once("GameParser.php");
|
||||
require_once("FenParser0x88.php");
|
||||
require_once("PgnGameParser.php");
|
||||
require_once("MoveBuilder.php");
|
||||
require_once("Board0x88Config.php");
|
||||
require_once("../CHESS_JSON.php");
|
||||
|
||||
$parser = new PgnParser('file.pgn');
|
||||
$games = $parser->getGames();
|
||||
echo json_encode($games[0]);
|
||||
echo "<br><br>";
|
||||
#outputTime();
|
||||
|
||||
*/
|
||||
|
||||
|
Reference in New Issue
Block a user