aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/USong_TextFile.pas
diff options
context:
space:
mode:
authors_alexander <s_alexander@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-04-03 15:00:10 +0000
committers_alexander <s_alexander@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-04-03 15:00:10 +0000
commit2bd6d1d2ea8d36eedac96053a7e4a818da22f654 (patch)
treee179e402ab7dbc9bac88ac788308b9b8697e8704 /Game/Code/Classes/USong_TextFile.pas
parent6b0661cdb54c8764d25883065ec22697cc2d18f5 (diff)
downloadusdx-2bd6d1d2ea8d36eedac96053a7e4a818da22f654.tar.gz
usdx-2bd6d1d2ea8d36eedac96053a7e4a818da22f654.tar.xz
usdx-2bd6d1d2ea8d36eedac96053a7e4a818da22f654.zip
rewriting of the txt file parser
removed unused variables from TLines and TLine, removed TMelody overworked the TLines and TLine records git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1000 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/Classes/USong_TextFile.pas')
-rw-r--r--Game/Code/Classes/USong_TextFile.pas86
1 files changed, 86 insertions, 0 deletions
diff --git a/Game/Code/Classes/USong_TextFile.pas b/Game/Code/Classes/USong_TextFile.pas
new file mode 100644
index 00000000..a3e605de
--- /dev/null
+++ b/Game/Code/Classes/USong_TextFile.pas
@@ -0,0 +1,86 @@
+unit USong_TextFile;
+
+interface
+
+{$IFDEF FPC}
+ {$MODE Delphi}
+{$ENDIF}
+
+{$I switches.inc}
+
+uses
+ Classes,
+ SysUtils,
+ USong;
+
+type
+ {*******************
+ Child of the new TSong class.
+ implements filehandling to load a song from a text file
+ *******************}
+ TSong_TextFile = class(TSong)
+ protected
+ SongFile: TextFile;
+
+ Function OpenSongFile: Boolean;
+ Function IsDataAvailable: Boolean;
+ Function GetNextLine(): String;
+ Procedure CloseSongFile;
+ end;
+
+implementation
+
+uses
+ ULog;
+
+//--------
+// Open the SongFile
+//--------
+Function TSong_TextFile.OpenSongFile: Boolean;
+begin
+ Result := False;
+
+ if not FileExists(FilePath + FileName) then
+ Log.LogError('File does not exsist', FilePath + FileName)
+ else
+ begin
+ try
+ AssignFile(SongFile, FilePath + FileName);
+ Reset(SongFile);
+ Result := True;
+ except
+ Log.LogError('Faild to open file', FilePath + FileName)
+ end;
+ end;
+end;
+
+//--------
+// More data in songfile available?
+//--------
+Function TSong_TextFile.IsDataAvailable: Boolean;
+begin
+ Result := not eof(SongFile);
+end;
+
+//--------
+// Returns the next line from the SongFile
+//--------
+Function TSong_TextFile.GetNextLine(): String;
+begin
+ ReadLn(SongFile, Result);
+ Result := Trim(Result);
+end;
+
+//--------
+// Close the SongFile
+//--------
+Procedure TSong_TextFile.CloseSongFile;
+begin
+ try
+ CloseFile(SongFile);
+ except
+ Log.LogError('Error closing file', FilePath + FileName);
+ end;
+end;
+
+end. \ No newline at end of file