Replaced Pairtwo Color Values for generic Values

This commit is contained in:
Jeroen De Meerleer 2019-03-19 15:58:41 +01:00
parent bad50fc75c
commit 7b6962843c
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
4 changed files with 28 additions and 11 deletions

View File

@ -12,9 +12,7 @@ use MyCLabs\Enum\Enum;
class Color extends Enum
{
const black = 255; // Implementing two's-complement for these values only is not worth the trick
const black3 = 253; // Especially if you can just do unsigned
const white = 1;
const white3 = 3;
const none = 0;
const black = 'B';
const white = 'W';
const none = '*';
}

View File

@ -34,7 +34,6 @@ use JeroenED\Libpairtwo\Models\Sws as SwsModel;
use JeroenED\Libpairtwo\Enums\TournamentSystem;
use DateTime;
/**
* This class reads a SWS file
*
@ -505,12 +504,26 @@ class Sws extends SwsModel
$offset += $length;
$length = 1;
$pairing->setColor(new Color(self::ReadData('Int', substr($swscontents, $offset, $length))));
switch (self::ReadData('Int', substr($swscontents, $offset, $length))) {
case 255:
case 253:
$color = 'B';
break;
case 1:
case 3:
$color = 'W';
break;
case 0:
default:
$color = '*';
break;
}
$pairing->setColor(new Color($color));
$offset += $length;
$length = 1;
Switch(self::ReadData('Int', substr($swscontents, $offset, $length)))
{
switch (self::ReadData('Int', substr($swscontents, $offset, $length))) {
case 0:
$result = '*';
break;

View File

@ -89,7 +89,7 @@ class Tournament extends TournamentModel
$result = $pairing->getResult();
$game = new Game();
if ($color->getValue() == Color::white || $color->getValue() == Color::white3) {
if ($color->getValue() == Color::white) {
if(! is_null($player)) $game->setWhite($player);
if(! is_null($opponent)) $game->setBlack($opponent);
switch ($result->getValue()) {
@ -115,7 +115,7 @@ class Tournament extends TournamentModel
default:
$game->setResult(new Gameresult('-')); break;
}
} elseif ($color->getValue() == Color::black || $color->getValue() == Color::black3) {
} elseif ($color->getValue() == Color::black) {
if(! is_null($player)) $game->setBlack($player);
if(! is_null($opponent)) $game->setWhite($opponent);
switch ($result->getValue()) {

View File

@ -62,4 +62,10 @@ echo "Absent P3: " . $sws->getTournament()->getPlayerById(2)->getAbsent() . P
echo "Date Round 1: " . $sws->getTournament()->getRoundByNo(0)->getDate()->format('d/m/Y') . PHP_EOL;
echo "Date Round 2: " . $sws->getTournament()->getRoundByNo(1)->getDate()->format('d/m/Y') . PHP_EOL;
echo "Date Round 3: " . $sws->getTournament()->getRoundByNo(2)->getDate()->format('d/m/Y') . PHP_EOL;
echo "Color Pairing 1: " . $sws->getTournament()->getPairings()[1]->getColor()->getKey() . PHP_EOL;
echo "Color Pairing 2: " . $sws->getTournament()->getPairings()[2]->getColor()->getKey() . PHP_EOL;
echo "Color Pairing 3: " . $sws->getTournament()->getPairings()[3]->getColor()->getKey() . PHP_EOL;
echo "Player Pairing 1: " . $sws->getTournament()->getPairings()[0]->getPlayer()->getName() . PHP_EOL;
echo "Player Pairing 2: " . $sws->getTournament()->getPairings()[1]->getPlayer()->getName() . PHP_EOL;
echo "Player Pairing 3: " . $sws->getTournament()->getPairings()[2]->getPlayer()->getName() . PHP_EOL;