Permalink
Browse files

Move some code from ParserSM to ParserBase

  • Loading branch information...
Keripo committed Jan 2, 2015
1 parent c39ecaa commit 70bbe1a24ceed7c01331e28ed5bc6dd9f81de04b
Showing with 32 additions and 22 deletions.
  1. +22 −8 beats2/Assets/Scripts/Parser/ParserBase.cs
  2. +10 −14 beats2/Assets/Scripts/Parser/ParserSM.cs
@@ -20,6 +20,20 @@ public abstract class ParserBase
{
private const string TAG = "ParserBase";
+ protected FileInfo _inputFile;
+ protected DirectoryInfo _parentDirectory;
+ protected Simfile _simfile = new Simfile();
+
+ protected ParserBase(FileInfo inputFile, DirectoryInfo parentDirectory)
+ {
+ _inputFile = inputFile;
+ _parentDirectory = parentDirectory;
+ }
+
+ public abstract void LoadMetadata();
+
+ public abstract void LoadCharts();
+
protected int ParseInt(string value)
{
int parsed;
@@ -79,28 +93,28 @@ protected bool ParseSection(string s, string separator, out string key, out stri
}
}
- protected string FindFile(string filename, string[] extensions, bool restrictExtensions, DirectoryInfo parentDirectory)
+ protected string FindFile(string filename, string[] extensions, bool restrictExtensions)
{
string path = FileLoader.FindFile(filename, extensions, restrictExtensions);
if (string.IsNullOrEmpty(path)) {
- path = FileLoader.FindFile(Path.Combine(filename, parentDirectory.FullName), extensions, restrictExtensions);
+ path = FileLoader.FindFile(Path.Combine(filename, _parentDirectory.FullName), extensions, restrictExtensions);
}
return path;
}
- protected string FindImage(string filename, DirectoryInfo parentDirectory)
+ protected string FindImage(string filename)
{
- return FindFile(filename, FileLoader.IMAGE_EXTENSIONS, false, parentDirectory);
+ return FindFile(filename, FileLoader.IMAGE_EXTENSIONS, false);
}
- protected string FindLyrics(string filename, DirectoryInfo parentDirectory)
+ protected string FindLyrics(string filename)
{
- return FindFile(filename, FileLoader.LYRICS_EXTENSIONS, false, parentDirectory);
+ return FindFile(filename, FileLoader.LYRICS_EXTENSIONS, false);
}
- protected string FindAudio(string filename, DirectoryInfo parentDirectory)
+ protected string FindAudio(string filename)
{
- return FindFile(filename, FileLoader.AUDIO_EXTENSIONS, true, parentDirectory);
+ return FindFile(filename, FileLoader.AUDIO_EXTENSIONS, true);
}
}
}
@@ -19,22 +19,18 @@ namespace Beats2.Parser
/// </summary>
public class ParserSM : ParserBase
{
- private const string TAG = "SMParser";
+ private const string TAG = "ParserSM";
- private FileInfo _inputFile;
- private DirectoryInfo _parentDirectory;
- private Simfile _simfile = new Simfile();
private List<Event> _events = new List<Event>();
private List<string> _notesData = new List<string>();
private bool _isMetadataLoaded = false;
public ParserSM(FileInfo inputFile, DirectoryInfo parentDirectory)
+ : base(inputFile, parentDirectory)
{
- _inputFile = inputFile;
- _parentDirectory = parentDirectory;
}
- public void LoadMetadata()
+ public override void LoadMetadata()
{
if (!_inputFile.Exists) {
throw new ParserException(string.Format("Input file does not exist: {0}", _inputFile.FullName));
@@ -72,7 +68,7 @@ public void LoadMetadata()
}
}
- public void LoadCharts()
+ public override void LoadCharts()
{
if (!_isMetadataLoaded) {
throw new ParserException("Metadata must be loaded first");
@@ -112,24 +108,24 @@ private void ParseTag(string tag, string value)
_simfile.metadata.infoCredits = value;
break;
case "BANNER":
- _simfile.metadata.graphicBanner = FindImage(value, _parentDirectory);
+ _simfile.metadata.graphicBanner = FindImage(value);
break;
case "BACKGROUND":
- _simfile.metadata.graphicBackground = FindImage(value, _parentDirectory);
+ _simfile.metadata.graphicBackground = FindImage(value);
break;
case "CDTITLE":
case "JACKET":
case "CDIMAGE":
case "DISCIMAGE":
if (_simfile.metadata.graphicCover == null) {
- _simfile.metadata.graphicCover = FindImage(value, _parentDirectory);
+ _simfile.metadata.graphicCover = FindImage(value);
}
break;
case "LYRICSPATH":
ParseLyricsPath(value);
break;
case "MUSIC":
- _simfile.metadata.musicPath = FindAudio(value, _parentDirectory);
+ _simfile.metadata.musicPath = FindAudio(value);
break;
case "OFFSET":
_simfile.metadata.musicOffset = ParseFloat(value);
@@ -196,7 +192,7 @@ private void ParseTag(string tag, string value)
private void ParseLyricsPath(string value)
{
- string lyricPath = FindLyrics(value, _parentDirectory);
+ string lyricPath = FindLyrics(value);
if (string.IsNullOrEmpty(lyricPath)) {
Logger.Warn(TAG, "Unable to find lyrics file: {0}", lyricPath);
} else {
@@ -254,7 +250,7 @@ private void ParseBgChanges(string value)
// See http://www.stepmania.com/forums/general-stepmania/show/1393#post3757
filename = filename.Substring(0, filename.IndexOf('='));
}
- string filePath = FindImage(filename, _parentDirectory);
+ string filePath = FindImage(filename);
if (beat < 0f) {
Logger.Warn(TAG, "Negative beat value events ignored");
} else if (string.IsNullOrEmpty(filename)) {

0 comments on commit 70bbe1a

Please sign in to comment.