/** * 一つのお題を表す配列から問題行に直列化します。 * @param (string|string[]|float)[][] $word * @param string $directoryName * @return string 末尾に改行 (CRLF) を含みます。 */ protected function serializeQuestionLine(array $word, string $directoryName) : string { $line = ['Q']; if (isset($word['image'][0])) { $line[] = 2; $fileLocation = $word['image'][0]; } elseif (isset($word['audio'][0])) { $line[] = 1; $fileLocation = $word['audio'][0]; } else { $line[] = 0; } $line[] = isset($word['question'][0]) ? $this->serializeQuizField($word['question'][0]) : ''; if (isset($fileLocation)) { $line[] = (\Stringy\StaticStringy::contains($fileLocation, '/') ? '' : "./{$directoryName}/") . $fileLocation; } if (isset($word['specifics'][0])) { $specifics = new URLSearchParams($word['specifics'][0]); if ($specifics->has('start')) { $line[] = 'start=' . round($specifics->get('start') * InteligenceoParser::SECONDS_TO_MILISECONDS); } if ($specifics->has('repeat')) { $line[] = 'repeat=' . $specifics->get('repeat'); } if ($specifics->has('length')) { $line[] = 'length=' . round($specifics->get('length') * InteligenceoParser::SECONDS_TO_MILISECONDS); } if ($specifics->has('speed')) { $line[] = 'speed=' . round($specifics->get('speed') * InteligenceoParser::DECIMAL_TO_PERCENT); } if ($specifics->has('magnification')) { $magnification = round($specifics->get('magnification')); if ($magnification > 0) { $line[] = "zoom_start={$magnification}"; if ($specifics->has('last-magnification')) { $lastMagnification = round($specifics->get('last-magnification')); if ($lastMagnification > 0) { $line[] = "zoom_end={$lastMagnification}"; } } } } if ($specifics->has('pixelization')) { $line[] = 'mozaic=1'; } if ($specifics->has('score')) { $line[] = 'score=' . $specifics->get('score'); if ($specifics->has('last-score')) { $line[] = 'finalscore=' . $specifics->get('last-score'); } } } return implode(',', $line) . "\r\n"; }