mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-06-18 00:30:26 +02:00
Compare commits
No commits in common. "71d1f2e500b9a5549c6ad039c92e1d47fdc37929" and "4c725bc271cdcb0b00a135e9a33c8f23441d4fd0" have entirely different histories.
71d1f2e500
...
4c725bc271
|
@ -6,10 +6,9 @@ class Sws
|
||||||
{
|
{
|
||||||
private $Release;
|
private $Release;
|
||||||
private $Tournament;
|
private $Tournament;
|
||||||
private $BinaryData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return String
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getRelease()
|
public function getRelease()
|
||||||
{
|
{
|
||||||
|
@ -17,15 +16,15 @@ class Sws
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $Release
|
* @param mixed $Release
|
||||||
*/
|
*/
|
||||||
public function setRelease(String $Release): void
|
public function setRelease($Release)
|
||||||
{
|
{
|
||||||
$this->Release = $Release;
|
$this->Release = $Release;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Tournament
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getTournament()
|
public function getTournament()
|
||||||
{
|
{
|
||||||
|
@ -33,32 +32,10 @@ class Sws
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Tournament $Tournament
|
* @param mixed $Tournament
|
||||||
*/
|
*/
|
||||||
public function setTournament(Tournament $Tournament): void
|
public function setTournament($Tournament)
|
||||||
{
|
{
|
||||||
$this->Tournament = $Tournament;
|
$this->Tournament = $Tournament;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns binary data from the sws-file
|
|
||||||
*
|
|
||||||
* @param string
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getBinaryData(String $key)
|
|
||||||
{
|
|
||||||
return $this->BinaryData[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets binary data
|
|
||||||
*
|
|
||||||
* @param string
|
|
||||||
* @param string
|
|
||||||
*/
|
|
||||||
public function setBinaryData(String $key, String $data): void
|
|
||||||
{
|
|
||||||
$this->BinaryData[$key] = $data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
222
src/Sws.php
222
src/Sws.php
|
@ -29,235 +29,25 @@ namespace JeroenED\Libpairtwo;
|
||||||
use JeroenED\Libpairtwo\Models\Tournament;
|
use JeroenED\Libpairtwo\Models\Tournament;
|
||||||
use JeroenED\Libpairtwo\Models\Sws as MyModel;
|
use JeroenED\Libpairtwo\Models\Sws as MyModel;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class reads a SWS file
|
* This class reads a SWS file
|
||||||
*
|
*
|
||||||
* @author Jeroen De Meerleer
|
* @author Jeroen De Meerleer
|
||||||
*/
|
*/
|
||||||
class Sws
|
class Sws {
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param string $swsfile
|
|
||||||
* @return MyModel
|
|
||||||
*/
|
|
||||||
public static function ReadSws(string $swsfile)
|
public static function ReadSws(string $swsfile)
|
||||||
{
|
{
|
||||||
$swshandle = fopen($swsfile, 'rb');
|
$swshandle = fopen($swsfile, 'rb');
|
||||||
$swscontents = fread($swshandle, filesize($swsfile));
|
|
||||||
fclose($swshandle);
|
|
||||||
|
|
||||||
$sws = new MyModel();
|
$sws = new MyModel();
|
||||||
$offset = 0;
|
$sws->setRelease(fread($swshandle, 4));
|
||||||
|
|
||||||
|
|
||||||
$length = 4;
|
|
||||||
$sws->setRelease(Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
$sws->setTournament(new Tournament());
|
$sws->setTournament(new Tournament());
|
||||||
|
|
||||||
// UserCountry
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("UserCountry", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// SavedOffset
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("SavedOffset", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// NewPlayer
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("NewPlayer", hexdec(Self::ReadHexData(substr($swscontents, $offset, $length))));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// AmericanHandicap
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("AmericanHandicap", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// LowOrder
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("LowOrder", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// PairingMethod
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("PairingMethod", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// AmericanPresence
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("AmericanPresence", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// CheckSameClub
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("CheckSameClub", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// NoColorCheck
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("NoColorCheck", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// SeparateCategories
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("SeparateCategories", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// EloUsed
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("EloUsed", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// AlternateColors
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("AlternateColors", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// MaxMeetings
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("MaxMeetings", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// MaxDistance
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("MaxDistance", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// MinimizeKeizer
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("MinimizeKeizer", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// MinRoundsMeetings
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("MinRoundsMeetings", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// MaxRoundsAbsent
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("MaxRoundsAbsent", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// SpecialPoints
|
|
||||||
$length = 4 * 6;
|
|
||||||
$sws->setBinaryData("SpecialPoints", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// NewNamePos
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("NewNamePos", hexdec(Self::ReadHexData(substr($swscontents, $offset, $length))));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// CurrentRound
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("CurrentRound", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// CreatedRounds
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("CreatedRounds", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// CreatedPlayers
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("CreatedPlayers", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// MaxSelection
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("MaxSelection", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// NumberOfRounds
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("NumberOfRounds", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// NumberOfPairings
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("NumberOfPairings", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// CreatedPairings
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("CreatedPairings", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// PairingElems
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("PairingElems", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// RandomSeed
|
|
||||||
$length = 4;
|
|
||||||
$sws->setBinaryData("RandomSeed", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// TieOrder
|
|
||||||
$length = 4 * 5;
|
|
||||||
$sws->setBinaryData("TieOrder", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// Categorie
|
|
||||||
$length = 4 * 10;
|
|
||||||
$sws->setBinaryData("Categorie", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// ExtraPoints
|
|
||||||
$length = 4 * 20;
|
|
||||||
$sws->setBinaryData("ExtraPoints", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// SelectP
|
|
||||||
$length = 4 * 20;
|
|
||||||
$sws->setBinaryData("SelectP", Self::ReadHexData(substr($swscontents, $offset, $length)));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// Players
|
|
||||||
$length = 68 * $sws->getBinaryData("NewPlayer");
|
|
||||||
$sws->setBinaryData("Players", substr($swscontents, $offset, $length));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// PlayerNames
|
|
||||||
$length = $sws->getBinaryData("NewNamePos");
|
|
||||||
$sws->setBinaryData("PlayerNames", substr($swscontents, $offset, $length));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// TournamentName
|
|
||||||
$length = 80;
|
|
||||||
$sws->getTournament()->setName(substr($swscontents, $offset, $length));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// TournamentOrganiser
|
|
||||||
$length = 50;
|
|
||||||
$sws->getTournament()->setOrganiser(substr($swscontents, $offset, $length));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// TournamentTempo
|
|
||||||
$length = 50;
|
|
||||||
$sws->getTournament()->setTempo(substr($swscontents, $offset, $length));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// TournamentCountry
|
|
||||||
$length = 32;
|
|
||||||
$sws->getTournament()->setOrganiserCountry(substr($swscontents, $offset, $length));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
// Arbiters
|
|
||||||
$length = 128;
|
|
||||||
$sws->getTournament()->setArbiter(substr($swscontents, $offset, $length));
|
|
||||||
$offset += $length;
|
|
||||||
|
|
||||||
return $sws;
|
return $sws;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function ReadHexData(String $data)
|
|
||||||
{
|
|
||||||
$hex = implode(unpack("H*", $data));
|
|
||||||
$hex = str_replace("00", "", $hex);
|
|
||||||
return $hex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,4 @@ Use JeroenED\Libpairtwo\Sws;
|
||||||
require_once '../vendor/autoload.php';
|
require_once '../vendor/autoload.php';
|
||||||
|
|
||||||
$sws = Sws::readSws('../res/testsws.sws');
|
$sws = Sws::readSws('../res/testsws.sws');
|
||||||
echo "Name: " . $sws->getTournament()->getName() . "\n";
|
echo $sws->getRelease();
|
||||||
echo "Organiser: " . $sws->getTournament()->getOrganiser(). "\n";
|
|
||||||
echo "Tempo: " . $sws->getTournament()->getTempo() . "\n";
|
|
||||||
echo "Country: " . $sws->getTournament()->getOrganiserCountry() . "\n";
|
|
||||||
echo "Arbiter: " . $sws->getTournament()->getArbiter() . "\n";
|
|
||||||
//echo $sws->getBinaryData("Tournament");
|
|
||||||
//echo $sws->getBinaryData("Players");
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user