Reading playernames

This commit is contained in:
Jeroen De Meerleer 2019-02-01 17:02:33 +01:00
parent 491004a604
commit e5fc94aca8
3 changed files with 23 additions and 4 deletions

View File

@ -338,15 +338,20 @@ class Sws extends SwsModel
$sws->getTournament()->addPlayer($player);
}
/* $length = 68 * $sws->getBinaryData("NewPlayer");
$sws->setBinaryData("Players", self::ReadData('String', substr($swscontents, $offset, $length)));
$offset += $length;*/
// PlayerNames
$length = (Integer)$sws->getBinaryData("NewNamePos") + 0;
$sws->setBinaryData("PlayerNames", self::ReadData('String', substr($swscontents, $offset, $length)));
$offset += $length;
for ($i = 0; $i < $sws->getBinaryData("NewPlayer"); $i++) {
$namelength = $sws->getBinaryData("Players($i)_NameLength");
$nameoffset = $sws->getBinaryData("Players($i)_NamePos");
$player = $sws->getTournament()->getPlayerById($i);
$player->setName(self::ReadData("String", substr($sws->getBinaryData("PlayerNames"), $nameoffset, $namelength)));
$sws->getTournament()->updatePlayer($i, $player);
}
// TournamentName
$length = 80;
$sws->getTournament()->setName(self::ReadData('String', substr($swscontents, $offset, $length)));

View File

@ -30,4 +30,15 @@ class Tournament extends TournamentModel
$newArray[] = $Player;
$this->setPlayers($newArray);
}
/**
* @param $id
* @param Player $player
*/
public function updatePlayer($id, Player $player)
{
$newArray = $this->GetPlayers();
$newArray[$id] = $player;
$this->setPlayers($newArray);
}
}

View File

@ -50,5 +50,8 @@ echo "Fide Elo P3: " . $sws->getTournament()->getPlayerById(2)->getFideElo() .
echo "KBSB Elo P1: " . $sws->getTournament()->getPlayerById(0)->getKbsbElo() . PHP_EOL;
echo "KBSB Elo P2: " . $sws->getTournament()->getPlayerById(1)->getKbsbElo() . PHP_EOL;
echo "KBSB Elo P3: " . $sws->getTournament()->getPlayerById(2)->getKbsbElo() . PHP_EOL;
echo "Name P1: " . $sws->getTournament()->getPlayerById(0)->getName() . PHP_EOL;
echo "Name P2: " . $sws->getTournament()->getPlayerById(1)->getName() . PHP_EOL;
echo "Name P3: " . $sws->getTournament()->getPlayerById(2)->getName() . PHP_EOL;
//echo $sws->getBinaryData("Tournament");
//echo $sws->getBinaryData("Players");*/