8eb04090757ad325a4313b7f7453680adec5894b
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 //XXX: Should I explode on ';' instead? That seems like it might be a more reliable delimiter
24 $this->_smFileLines
= explode("\n", $simfileData);
27 public function title()
29 $title = $this->extractKey('TITLE');
30 if(!$title) throw new Exception ('Invalid SM file. Title missing');
35 public function stops()
37 return $this->extractKey('STOPS') ?
'Yes' : 'No';
40 public function steps($mode, $difficulty)
44 foreach ($this->_smFileLines
as $index => $line) {
45 if (strpos($line, '#NOTES') !== false
) {
46 $mode = substr(trim($lines[$index +
1]), 0, -1) == 'dance-single' ?
'single' : null
;
47 $notes[$mode][] = array(
48 'artist' => substr(trim($lines[$index +
2]), 0, -1),
49 'difficulty' => substr(trim($lines[$index +
3]), 0, -1),
50 'rating' => substr(trim($lines[$index +
4]), 0, -1)
58 private function extractKey($key) {
59 foreach ($lines as $line) {
60 $pos = strpos($line, '#' . $key . ':');
61 if($pos !== false
) return substr(trim($line), strlen($key) +
2, -1);