Skip to content

Commit 70bbe1a

Browse files
committed
Move some code from ParserSM to ParserBase
1 parent c39ecaa commit 70bbe1a

2 files changed

Lines changed: 32 additions & 22 deletions

File tree

beats2/Assets/Scripts/Parser/ParserBase.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ public abstract class ParserBase
2020
{
2121
private const string TAG = "ParserBase";
2222

23+
protected FileInfo _inputFile;
24+
protected DirectoryInfo _parentDirectory;
25+
protected Simfile _simfile = new Simfile();
26+
27+
protected ParserBase(FileInfo inputFile, DirectoryInfo parentDirectory)
28+
{
29+
_inputFile = inputFile;
30+
_parentDirectory = parentDirectory;
31+
}
32+
33+
public abstract void LoadMetadata();
34+
35+
public abstract void LoadCharts();
36+
2337
protected int ParseInt(string value)
2438
{
2539
int parsed;
@@ -79,28 +93,28 @@ protected bool ParseSection(string s, string separator, out string key, out stri
7993
}
8094
}
8195

82-
protected string FindFile(string filename, string[] extensions, bool restrictExtensions, DirectoryInfo parentDirectory)
96+
protected string FindFile(string filename, string[] extensions, bool restrictExtensions)
8397
{
8498
string path = FileLoader.FindFile(filename, extensions, restrictExtensions);
8599
if (string.IsNullOrEmpty(path)) {
86-
path = FileLoader.FindFile(Path.Combine(filename, parentDirectory.FullName), extensions, restrictExtensions);
100+
path = FileLoader.FindFile(Path.Combine(filename, _parentDirectory.FullName), extensions, restrictExtensions);
87101
}
88102
return path;
89103
}
90104

91-
protected string FindImage(string filename, DirectoryInfo parentDirectory)
105+
protected string FindImage(string filename)
92106
{
93-
return FindFile(filename, FileLoader.IMAGE_EXTENSIONS, false, parentDirectory);
107+
return FindFile(filename, FileLoader.IMAGE_EXTENSIONS, false);
94108
}
95109

96-
protected string FindLyrics(string filename, DirectoryInfo parentDirectory)
110+
protected string FindLyrics(string filename)
97111
{
98-
return FindFile(filename, FileLoader.LYRICS_EXTENSIONS, false, parentDirectory);
112+
return FindFile(filename, FileLoader.LYRICS_EXTENSIONS, false);
99113
}
100114

101-
protected string FindAudio(string filename, DirectoryInfo parentDirectory)
115+
protected string FindAudio(string filename)
102116
{
103-
return FindFile(filename, FileLoader.AUDIO_EXTENSIONS, true, parentDirectory);
117+
return FindFile(filename, FileLoader.AUDIO_EXTENSIONS, true);
104118
}
105119
}
106120
}

beats2/Assets/Scripts/Parser/ParserSM.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,18 @@ namespace Beats2.Parser
1919
/// </summary>
2020
public class ParserSM : ParserBase
2121
{
22-
private const string TAG = "SMParser";
22+
private const string TAG = "ParserSM";
2323

24-
private FileInfo _inputFile;
25-
private DirectoryInfo _parentDirectory;
26-
private Simfile _simfile = new Simfile();
2724
private List<Event> _events = new List<Event>();
2825
private List<string> _notesData = new List<string>();
2926
private bool _isMetadataLoaded = false;
3027

3128
public ParserSM(FileInfo inputFile, DirectoryInfo parentDirectory)
29+
: base(inputFile, parentDirectory)
3230
{
33-
_inputFile = inputFile;
34-
_parentDirectory = parentDirectory;
3531
}
3632

37-
public void LoadMetadata()
33+
public override void LoadMetadata()
3834
{
3935
if (!_inputFile.Exists) {
4036
throw new ParserException(string.Format("Input file does not exist: {0}", _inputFile.FullName));
@@ -72,7 +68,7 @@ public void LoadMetadata()
7268
}
7369
}
7470

75-
public void LoadCharts()
71+
public override void LoadCharts()
7672
{
7773
if (!_isMetadataLoaded) {
7874
throw new ParserException("Metadata must be loaded first");
@@ -112,24 +108,24 @@ private void ParseTag(string tag, string value)
112108
_simfile.metadata.infoCredits = value;
113109
break;
114110
case "BANNER":
115-
_simfile.metadata.graphicBanner = FindImage(value, _parentDirectory);
111+
_simfile.metadata.graphicBanner = FindImage(value);
116112
break;
117113
case "BACKGROUND":
118-
_simfile.metadata.graphicBackground = FindImage(value, _parentDirectory);
114+
_simfile.metadata.graphicBackground = FindImage(value);
119115
break;
120116
case "CDTITLE":
121117
case "JACKET":
122118
case "CDIMAGE":
123119
case "DISCIMAGE":
124120
if (_simfile.metadata.graphicCover == null) {
125-
_simfile.metadata.graphicCover = FindImage(value, _parentDirectory);
121+
_simfile.metadata.graphicCover = FindImage(value);
126122
}
127123
break;
128124
case "LYRICSPATH":
129125
ParseLyricsPath(value);
130126
break;
131127
case "MUSIC":
132-
_simfile.metadata.musicPath = FindAudio(value, _parentDirectory);
128+
_simfile.metadata.musicPath = FindAudio(value);
133129
break;
134130
case "OFFSET":
135131
_simfile.metadata.musicOffset = ParseFloat(value);
@@ -196,7 +192,7 @@ private void ParseTag(string tag, string value)
196192

197193
private void ParseLyricsPath(string value)
198194
{
199-
string lyricPath = FindLyrics(value, _parentDirectory);
195+
string lyricPath = FindLyrics(value);
200196
if (string.IsNullOrEmpty(lyricPath)) {
201197
Logger.Warn(TAG, "Unable to find lyrics file: {0}", lyricPath);
202198
} else {
@@ -254,7 +250,7 @@ private void ParseBgChanges(string value)
254250
// See http://www.stepmania.com/forums/general-stepmania/show/1393#post3757
255251
filename = filename.Substring(0, filename.IndexOf('='));
256252
}
257-
string filePath = FindImage(filename, _parentDirectory);
253+
string filePath = FindImage(filename);
258254
if (beat < 0f) {
259255
Logger.Warn(TAG, "Negative beat value events ignored");
260256
} else if (string.IsNullOrEmpty(filename)) {

0 commit comments

Comments
 (0)