5 use Services\ISimfileParser
;
8 class SimfileParser
implements ISimfileParser
11 // 'light' => 'Novice',
12 // 'beginner' => 'Novice',
14 // 'medium' => 'Medium',
16 // 'challenge' => 'Expert',
19 private $_smFileLines;
21 public function __construct($simfileData)
23 $this->_smFileLines
= explode("\n", $simfileData);
26 public function title()
28 $title = $this->extractKey('TITLE');
29 if(!$title) throw new Exception ('Invalid SM file. Title missing');
34 public function stops()
36 return $this->extractKey('STOPS') ?
'Yes' : 'No';
39 public function steps($mode, $difficulty)
43 foreach ($this->_smFileLines
as $index => $line) {
44 if (strpos($line, '#NOTES') !== false
) {
45 $mode = substr(trim($lines[$index +
1]), 0, -1) == 'dance-single' ?
'single' : null
;
46 $notes[$mode][] = array(
47 'artist' => substr(trim($lines[$index +
2]), 0, -1),
48 'difficulty' => substr(trim($lines[$index +
3]), 0, -1),
49 'rating' => substr(trim($lines[$index +
4]), 0, -1)
57 private function extractKey($key) {
58 foreach ($lines as $line) {
59 $pos = strpos($line, '#' . $key . ':');
60 if($pos !== false
) return substr(trim($line), strlen($key) +
2, -1);