Reserved metadata moved from metadata sub array

This commit is contained in:
Alf Magne Kalleland
2013-02-06 23:31:04 +01:00
parent 1b229275b9
commit c6782583fc
4 changed files with 14 additions and 27 deletions

View File

@@ -1384,5 +1384,4 @@ class FenParser0x88
}
return $fen . " ". $this->getColorCode(). " ". $this->getCastle()." ". $this->fenParts['enPassant']." ". $this->getHalfMoves()." ". $this->getFullMoves();
}
}

View File

@@ -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];
}
}

View File

@@ -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])) {

View File

@@ -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();
*/