本文整理汇总了PHP中Participant::setDrivers方法的典型用法代码示例。如果您正苦于以下问题:PHP Participant::setDrivers方法的具体用法?PHP Participant::setDrivers怎么用?PHP Participant::setDrivers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Participant
的用法示例。
在下文中一共展示了Participant::setDrivers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSessions
/**
* @see \Simresults\Data_Reader::getSessions()
*/
public function getSessions()
{
// Get data
$data = json_decode($this->data, TRUE);
// No session data
if (!($sessions_data = Helper::arrayGet($data, 'sessions'))) {
// Throw exception
throw new Exception\Reader('Cannot read the session data');
}
// Init sessions array
$sessions = array();
// Get extra data for all sessions
$extras = array();
foreach (Helper::arrayGet($data, 'extras', array()) as $extras_data) {
// Get name
$name = Helper::arrayGet($extras_data, 'name');
// Loop all values and add as extra settings
foreach ($extras_data as $extra_data_key => $extra_data_value) {
// Is name
if ($extra_data_key === 'name') {
// Skip this
continue;
}
// Add to extras collection
$extras[ucfirst($name) . ' ' . $extra_data_key] = $extra_data_value;
}
}
// Gather all sessions
foreach ($sessions_data as $session_data) {
// Init session
$session = new Session();
// Get participants (do for each session to prevent re-used objects
// between sessions)
$participants = array();
$players_data = Helper::arrayGet($data, 'players', array());
foreach ($players_data as $player_index => $player_data) {
// Create driver
$driver = new Driver();
$driver->setName(Helper::arrayGet($player_data, 'name'));
// Create participant and add driver
$participant = new Participant();
$participant->setDrivers(array($driver))->setFinishStatus(Participant::FINISH_NORMAL);
// Create vehicle and add to participant
$vehicle = new Vehicle();
$vehicle->setName(Helper::arrayGet($player_data, 'car'));
$participant->setVehicle($vehicle);
// Add participant to collection
$participants[] = $participant;
}
// Practice session by default
$type = Session::TYPE_PRACTICE;
// Check session name to get type
// TODO: Should be checked when full game is released. Also create
// tests for it!
switch (strtolower($name = Helper::arrayGet($session_data, 'name'))) {
case 'qualify session':
case 'qualify':
$type = Session::TYPE_QUALIFY;
break;
case 'warmup session':
$type = Session::TYPE_WARMUP;
break;
case 'race session':
case 'quick race':
case 'race':
$type = Session::TYPE_RACE;
break;
}
// Set session values
$session->setType($type)->setName($name)->setMaxLaps((int) Helper::arrayGet($session_data, 'lapsCount'))->setMaxMinutes((int) Helper::arrayGet($session_data, 'duration'));
// Set game
$game = new Game();
$game->setName('Assetto Corsa');
$session->setGame($game);
// Set server (we do not know...)
$server = new Server();
$server->setName('Unknown or offline');
$session->setServer($server);
// Set track
$track = new Track();
$track->setVenue(Helper::arrayGet($data, 'track'));
$session->setTrack($track);
// Get the laps
$laps_data = Helper::arrayGet($session_data, 'laps', array());
// No laps data
if (!$laps_data) {
// Use best laps if possible
$laps_data = Helper::arrayGet($session_data, 'bestLaps', array());
}
// Process laps
foreach ($laps_data as $lap_data) {
// Init new lap
$lap = new Lap();
// Set participant
$lap->setParticipant($lap_participant = $participants[$lap_data['car']]);
// Set first driver of participant as lap driver. AC does
// not support swapping
//.........这里部分代码省略.........
示例2: getParticipants
//.........这里部分代码省略.........
$swap_driver->setName($driver_name);
// Use human state the same of main driver within XML
$swap_driver->setHuman($main_driver->isHuman());
// Add swap driver to drivers array
$drivers[] = $swap_driver;
// Remember swap driver by name
$drivers_by_name[$driver_name] = $swap_driver;
}
// Add swap driver to drivers per lap
$drivers_per_laps[] = array('start_lap' => (int) $swap_xml->getAttribute('startLap'), 'end_lap' => (int) $swap_xml->getAttribute('endLap'), 'driver' => $swap_driver);
// Not first swap element, so this is a real swap that happend
// within pits
if (!$first_swap) {
// Increment the number of swaps
$number_of_swaps++;
}
// Not first swap anymore
$first_swap = false;
}
// No drivers yet, so no drivers through swap info
if (!$drivers) {
// Add main driver to drivers array because we could not get
// it from the swap info
$drivers[] = $main_driver;
}
// Pitcounter is lower than number of swaps
if ($participant->getPitstops() < $number_of_swaps) {
// Set pitstop counter to the number of swaps
$participant->setPitstops($number_of_swaps);
}
// Add vehicle to participant
$participant->setVehicle($vehicle);
// Add drivers to participant
$participant->setDrivers($drivers);
// Remember whether the drivers are human or not from the look at
// the aids
$is_human_by_aids = null;
// Get lap aids information and convert to friendly array
$aids_xml = $driver_xml->getElementsByTagName('ControlAndAids');
$aids = array();
foreach ($aids_xml as $aid_xml) {
// Match the aids
$matches = array();
preg_match_all('/([a-z]+)(=([a-z0-9]))?[,]?/i', (string) $aid_xml->nodeValue, $matches);
// Prepare aid items array
$aid_items = array();
// Loop each matched aid
if (isset($matches[1])) {
foreach ($matches[1] as $key => $aid_name) {
// Get value
$aid_value = $matches[3][$key];
// Is float
if (is_float($aid_value)) {
// Cast to float
$aid_value = (double) $aid_value;
} elseif (is_numeric($aid_value)) {
// Cast to int
$aid_value = (int) $aid_value;
}
// Is a human player
if ($aid_name === 'PlayerControl') {
// Remember this driver is human
$is_human_by_aids = true;
} elseif (($aid_name === 'UnknownControl' or $aid_name === 'AIControl') and $is_human_by_aids === null) {
// Remember this driver is not human
$is_human_by_aids = false;
示例3: getSessions
/**
* @see \Simresults\Data_Reader::getSessions()
*/
public function getSessions()
{
// Get data
$data = json_decode($this->data, TRUE);
// Get date
preg_match('/\\d{10}/i', $data['Time'], $time_matches);
$date = new \DateTime();
$date->setTimestamp($time_matches[0]);
$date->setTimezone(new \DateTimeZone(self::$default_timezone));
// Get other settings
$other_settings = array();
$known_setting_keys = array('Experience', 'Difficulty', 'FuelUsage', 'MechanicalDamage', 'FlagRules', 'CutRules', 'RaceSeriesFormat', 'WreckerPrevention', 'MandatoryPitstop', 'MandatoryPitstop');
foreach ($known_setting_keys as $setting) {
if ($setting_value = Helper::arrayGet($data, $setting)) {
$other_settings[$setting] = $setting_value;
}
}
// Init sessions array
$sessions = array();
// Gather all sessions
foreach ($data['Sessions'] as $session_data) {
// Init session
$session = new Session();
// Practice session by default
$type = Session::TYPE_PRACTICE;
// Check session type
switch (strtolower($name = $session_data['Type'])) {
case 'qualify':
$type = Session::TYPE_QUALIFY;
break;
case 'warmup':
$type = Session::TYPE_WARMUP;
break;
case 'race':
$type = Session::TYPE_RACE;
break;
}
// Set session values
$session->setType($type)->setDate($date)->setOtherSettings($other_settings);
// Set game
$game = new Game();
$game->setName('RaceRoom Racing Experience');
$session->setGame($game);
// Set server
$server = new Server();
$server->setName(Helper::arrayGet($data, 'Server'));
$session->setServer($server);
// Set track
$track = new Track();
$track->setVenue(Helper::arrayGet($data, 'Track'));
$session->setTrack($track);
// Get participants and their best lap (only lap)
$participants = array();
$players_data = Helper::arrayGet($session_data, 'Players', array());
foreach ($players_data as $player_index => $player_data) {
// Create driver
$driver = new Driver();
$driver->setName(Helper::arrayGet($player_data, 'Username', 'unknown'));
// Create participant and add driver
$participant = new Participant();
$participant->setDrivers(array($driver))->setPosition(Helper::arrayGet($player_data, 'Position', null))->setFinishStatus(Participant::FINISH_NORMAL);
// Create vehicle and add to participant
$vehicle = new Vehicle();
$vehicle->setName(Helper::arrayGet($player_data, 'Car'));
$participant->setVehicle($vehicle);
// Has best lap
if (0 < ($best_lap = Helper::arrayGet($player_data, 'BestLapTime'))) {
// Init new lap
$lap = new Lap();
// Set participant
$lap->setParticipant($participant);
// Set first driver of participant as lap driver. RR does
// not support swapping
$lap->setDriver($participant->getDriver());
// Set lap number
$lap->setNumber(1);
// Set lap time in seconds
$lap->setTime(round($best_lap / 1000, 4));
// Add lap to participant
$participant->addLap($lap);
}
// Add participant to collection
$participants[] = $participant;
}
// Add participants to session
$session->setParticipants($participants);
// Add session to collection
$sessions[] = $session;
}
// Return all sessions
return $sessions;
}
示例4: getSessions
/**
* @see \Simresults\Data_Reader::getSessions()
*/
public function getSessions()
{
// Get array data
$data = $this->array_data;
// Init sessions array
$sessions = array();
// Remember last qualify session to make up grid positions
$last_qualify_session = null;
// Loop each session from data
foreach ($data as $session_data) {
// Remember which vehicles are parsed
$vehicle_names = array();
// Init session
$session = new Session();
// Set session type
$type = null;
switch ($session_data['type']) {
case 'qualify':
$type = Session::TYPE_QUALIFY;
break;
case 'practice':
$type = Session::TYPE_PRACTICE;
break;
case 'warmup':
$type = Session::TYPE_PRACTICE;
break;
case 'race':
$type = Session::TYPE_RACE;
break;
}
$session->setType($type);
// Set session name
if (isset($session_data['name'])) {
$session->setName($session_data['name']);
}
// Set max time
if (isset($session_data['time'])) {
$session->setMaxMinutes($session_data['time']);
}
// Set max laps
if (isset($session_data['laps'])) {
$session->setMaxLaps($session_data['laps']);
}
// Set game
$game = new Game();
$game->setName('Assetto Corsa');
$session->setGame($game);
// Has track
if (isset($session_data['track'])) {
$track = new Track();
$track->setVenue($session_data['track']);
$session->setTrack($track);
}
// Has date
if (isset($session_data['date'])) {
// Set it
$session->setDateString($session_data['date']);
}
// Set server
$server = new Server();
$server->setDedicated(true);
if (isset($session_data['server'])) {
$server->setName($session_data['server']);
} else {
$server->setName('Unknown');
}
$session->setServer($server);
// Add allowed vehicles
foreach ($session_data['car_list'] as $vehicle_name) {
$vehicle = new Vehicle();
$vehicle->setName($vehicle_name);
$session->addAllowedVehicle($vehicle);
}
// Set chats
foreach ($session_data['chats'] as $chat_message) {
$chat = new Chat();
$chat->setMessage($chat_message);
$session->addChat($chat);
}
// Set participants
$participants = array();
foreach ($session_data['participants'] as $part_data) {
// No name
if (!Helper::arrayGet($part_data, 'name')) {
continue;
}
// Create driver
$driver = new Driver();
$driver->setName($part_data['name']);
// Total time not greater than 0
if (0 >= ($total_time = Helper::arrayGet($part_data, 'total_time'))) {
// Total time is null
$total_time = null;
}
// Create participant and add driver
$participant = new Participant();
$participant->setDrivers(array($driver))->setTotalTime($total_time);
//.........这里部分代码省略.........