当前位置: 首页>>代码示例>>PHP>>正文


PHP Participant::createInstance方法代码示例

本文整理汇总了PHP中Participant::createInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Participant::createInstance方法的具体用法?PHP Participant::createInstance怎么用?PHP Participant::createInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Participant的用法示例。


在下文中一共展示了Participant::createInstance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: readSessions

 /**
  * @see \Simresults\Data_Reader::readSessions()
  */
 protected function readSessions()
 {
     // Get array data
     $data = $this->array_data;
     // Init sessions array
     $sessions = array();
     // Loop each session from data
     foreach ($data as $session_data) {
         // Remember which vehicles are parsed
         $vehicle_names = array();
         // Init session
         $session = Session::createInstance();
         // 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 = Participant::createInstance();
             $participant->setDrivers(array($driver))->setTotalTime($total_time);
             // Has total time parsed data and should not be a forced DNF
             if ($total_time and !Helper::arrayGet($part_data, 'force_dnf')) {
//.........这里部分代码省略.........
开发者ID:mauserrifle,项目名称:simresults,代码行数:101,代码来源:AssettoCorsaServer.php

示例2: readSessions

 /**
  * @see \Simresults\Data_Reader::readSessions()
  */
 protected function readSessions()
 {
     // 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 = Session::createInstance();
         // 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();
             // Has name
             if ($name = Helper::arrayGet($player_data, 'Username') or $name = Helper::arrayGet($player_data, 'FullName')) {
                 $driver->setName($name);
             } else {
                 $driver->setName('unknown');
             }
             // Create participant and add driver
             $participant = Participant::createInstance();
             $participant->setDrivers(array($driver))->setPosition(Helper::arrayGet($player_data, 'Position', null));
             // Has finish status
             if ($status = Helper::arrayGet($player_data, 'FinishStatus')) {
                 // Figure out status
                 switch (strtolower($status)) {
                     case 'finished':
                         $participant->setFinishStatus(Participant::FINISH_NORMAL);
                         break;
                     case 'disqualified':
                         $participant->setFinishStatus(Participant::FINISH_DQ);
                         break;
                     default:
                         $participant->setFinishStatus(Participant::FINISH_DNF);
                         break;
                 }
             } else {
                 $participant->setFinishStatus(Participant::FINISH_NORMAL);
             }
             // Has total time
             if ($total_time = Helper::arrayGet($player_data, 'TotalTime')) {
                 $participant->setTotalTime(round($player_data['TotalTime'] / 1000, 4));
             }
             // Create vehicle and add to participant
             $vehicle = new Vehicle();
             $vehicle->setName(Helper::arrayGet($player_data, 'Car'));
             $participant->setVehicle($vehicle);
             // Has laps
             if ($laps = Helper::arrayGet($player_data, 'RaceSessionLaps')) {
                 foreach ($laps as $lap_key => $lap_data) {
                     // Negative lap time, skip
                     if ($lap_data['Time'] < 0) {
                         continue;
//.........这里部分代码省略.........
开发者ID:mauserrifle,项目名称:simresults,代码行数:101,代码来源:RaceRoomServer.php

示例3: readSessions

 /**
  * @see \Simresults\Data_Reader::readSessions()
  */
 protected function readSessions()
 {
     // 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 = Session::createInstance();
         // 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 = Participant::createInstance();
             $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
//.........这里部分代码省略.........
开发者ID:mauserrifle,项目名称:simresults,代码行数:101,代码来源:AssettoCorsa.php

示例4: getParticipant

 /**
  * Helper to get new participant instance
  *
  * @param  string        $name
  * @param  string        $guid
  * @param  string        $car
  * @param  string        $team
  * @param  int           $vehicle_ballast
  * @return Participant
  */
 protected function getParticipant($name, $guid, $car, $team = null, $vehicle_ballast = null, $vehicle_skin = null)
 {
     // Create driver
     $driver = new Driver();
     $driver->setName($name)->setDriverId($guid);
     // Create participant and add driver
     $participant = Participant::createInstance();
     $participant->setDrivers(array($driver))->setFinishStatus(Participant::FINISH_NORMAL)->setTeam($team);
     // Create vehicle and add to participant
     $vehicle = new Vehicle();
     $vehicle->setName($car);
     // Has ballast
     if ($vehicle_ballast) {
         $vehicle->setBallast($vehicle_ballast);
     }
     // Has skin
     if ($vehicle_skin) {
         $vehicle->setSkin($vehicle_skin);
     }
     $participant->setVehicle($vehicle);
     return $participant;
 }
开发者ID:mauserrifle,项目名称:simresults,代码行数:32,代码来源:AssettoCorsaServerJson.php

示例5: getParticipant

 /**
  * Helper to get new participant instance
  *
  * @param  array        $part_data
  * @return Participant
  */
 protected function getParticipant($part_data)
 {
     // Create driver
     $driver = new Driver();
     $driver->setName($part_data['name'])->setHuman(false);
     // Has steam id
     if (isset($part_data['steamid'])) {
         $driver->setDriverId($part_data['steamid']);
         $driver->setHuman(true);
     }
     // Create participant and add driver
     $participant = Participant::createInstance();
     $participant->setDrivers(array($driver))->setFinishStatus(Participant::FINISH_NORMAL);
     // Create vehicle and add to participant
     $vehicle = new Vehicle();
     // TODO: Parse livery too?
     // $vehicle->setType( (string) $part_data['setup']['LiveryId']);
     // Has vehicle in root
     $vehicle_id = null;
     if (isset($part_data['VehicleId'])) {
         $vehicle_id = $part_data['VehicleId'];
     } elseif (isset($part_data['setup']) and isset($part_data['setup']['VehicleId'])) {
         $vehicle_id = $part_data['setup']['VehicleId'];
     }
     // Have friendly vehicle name
     if (isset($this->attribute_names['vehicles'][$vehicle_id])) {
         $vehicle->setName($this->attribute_names['vehicles'][$part_data['setup']['VehicleId']]['name']);
         $vehicle->setClass($this->attribute_names['vehicles'][$part_data['setup']['VehicleId']]['class']);
     } else {
         $vehicle->setName((string) $vehicle_id);
     }
     $participant->setVehicle($vehicle);
     return $participant;
 }
开发者ID:mauserrifle,项目名称:simresults,代码行数:40,代码来源:ProjectCarsServer.php

示例6: getParticipants

 /**
  * Get participants sorted by ending position
  *
  * @return  array
  */
 protected function getParticipants()
 {
     // Drivers already read
     if ($this->participants !== null) {
         // Return already read participants
         return $this->participants;
     }
     // Init drivers array
     $participants = array();
     // Remember all lap positions to detect corruption later
     $lap_positions = array();
     // Remeber all lap instances per lap number so we fix position
     // corruption on them
     $all_laps_by_lap_number = array();
     // Loop each driver (if any)
     /* @var $driver_xml \DOMNode */
     foreach ($this->dom->getElementsByTagName('Driver') as $driver_xml) {
         // Create new driver
         $main_driver = new Driver();
         // Get position
         $position = (int) $this->dom_value('Position', $driver_xml);
         // Set driver values
         $main_driver->setName($this->dom_value('Name', $driver_xml))->setHuman((bool) $this->dom_value('isPlayer', $driver_xml));
         // Create new vehicle
         $vehicle = new Vehicle();
         // Set vehicle values
         $vehicle->setName($this->dom_value('VehName', $driver_xml))->setType($this->dom_value('CarType', $driver_xml))->setClass($this->dom_value('CarClass', $driver_xml))->setNumber((int) $this->dom_value('CarNumber', $driver_xml));
         // Create participant
         $participant = Participant::createInstance();
         // Set participant values
         $participant->setTeam($this->dom_value('TeamName', $driver_xml))->setPosition((int) $this->dom_value('Position', $driver_xml))->setClassPosition((int) $this->dom_value('ClassPosition', $driver_xml))->setGridPosition((int) $this->dom_value('GridPos', $driver_xml))->setClassGridPosition((int) $this->dom_value('ClassGridPos', $driver_xml))->setPitstops((int) $this->dom_value('Pitstops', $driver_xml));
         // Has finish time
         if ($finish_time = (double) $this->dom_value('FinishTime', $driver_xml)) {
             // Overwrite total time, because rfactor results tend to be
             // corrupted at times
             $participant->setTotalTime($finish_time);
         }
         // Get finish status value
         $finish_status = strtolower($this->dom_value('FinishStatus', $driver_xml));
         // Has finished
         if ($finish_status === 'finished normally') {
             // Set finish status
             $participant->setFinishStatus(Participant::FINISH_NORMAL);
         } elseif ($finish_status === 'dq') {
             // Set disqualified status
             $participant->setFinishStatus(Participant::FINISH_DQ);
         } elseif ($finish_status === 'dnf') {
             // Set did not finish status
             $participant->setFinishStatus(Participant::FINISH_DNF);
             // Set finish comment (if any)
             if ($finish_status = $this->dom_value('DNFReason', $driver_xml)) {
                 $participant->setFinishComment($finish_status);
             }
         } else {
             // Set no finish status
             $participant->setFinishStatus(Participant::FINISH_NONE);
         }
         // Get the driver swaps
         $swaps_xml = $driver_xml->getElementsByTagName('Swap');
         // Init drivers array, a participant can have multiple
         $drivers = array();
         // Remember the drivers per laps
         $drivers_per_laps = array();
         // Remember drivers by name so we can re-use them
         $drivers_by_name = array();
         // Remember the number of swaps (always -1 of number of swap
         // elements in XML, because first driver starts on grid, which is
         // actually not really a swap)
         $number_of_swaps = 0;
         // Loop each swap
         $first_swap = true;
         // First swap reminder, can't use $swap_xml_key
         // to detect because it is bugged in hhvm!
         foreach ($swaps_xml as $swap_xml_key => $swap_xml) {
             // Empty driver name
             if (!($driver_name = $swap_xml->nodeValue)) {
                 // Skip this swap
                 continue;
             }
             // Driver already processed
             if (array_key_exists($driver_name, $drivers_by_name)) {
                 // Use existing found driver instance
                 $swap_driver = $drivers_by_name[$driver_name];
             } else {
                 // Create new driver
                 $swap_driver = new Driver();
                 // Set name
                 $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;
             }
//.........这里部分代码省略.........
开发者ID:mauserrifle,项目名称:simresults,代码行数:101,代码来源:Rfactor2.php


注:本文中的Participant::createInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。