aboutsummaryrefslogtreecommitdiffstats
path: root/tools/ScoreConverter/UScores.pas
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-08-27 15:26:05 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-08-27 15:26:05 +0000
commit2c87ea1040f8fc02fcadbf920d02685198a0c216 (patch)
treefda8cb97a4ebcae55701f30dc2e356f5fd609738 /tools/ScoreConverter/UScores.pas
parent50d173a828e75d2b8bc439c8b65bc8bb1127fe48 (diff)
downloadusdx-2c87ea1040f8fc02fcadbf920d02685198a0c216.tar.gz
usdx-2c87ea1040f8fc02fcadbf920d02685198a0c216.tar.xz
usdx-2c87ea1040f8fc02fcadbf920d02685198a0c216.zip
Artwork/Game/Modis/Tools changed to lower case
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1314 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'tools/ScoreConverter/UScores.pas')
-rw-r--r--tools/ScoreConverter/UScores.pas102
1 files changed, 102 insertions, 0 deletions
diff --git a/tools/ScoreConverter/UScores.pas b/tools/ScoreConverter/UScores.pas
new file mode 100644
index 00000000..801d796e
--- /dev/null
+++ b/tools/ScoreConverter/UScores.pas
@@ -0,0 +1,102 @@
+unit UScores;
+
+interface
+
+uses USongs;
+
+procedure ReadScore(var Song: TSong);
+procedure WriteScore(var Song: TSong);
+procedure AddScore(var Song: TSong; Level: integer; Name: string; Score: integer);
+
+implementation
+
+uses IniFiles, SysUtils;
+
+procedure ReadScore(var Song: TSong);
+var
+ F: TIniFile;
+ S: string;
+ P: integer;
+ Lev: integer;
+ LevS: string;
+begin
+ F := TIniFile.Create(Song.Path + ChangeFileExt(Song.FileName, '.sco'));
+
+ for Lev := 0 to 2 do begin
+ case Lev of
+ 0: LevS := 'Easy';
+ 1: LevS := 'Normal';
+ 2: LevS := 'Hard';
+ end;
+
+ P := 1;
+ S := F.ReadString(LevS + IntToStr(P), 'Name', '');
+ while (S <> '') and (P<=5) do begin
+ SetLength(Song.Score[Lev], P);
+ Song.Score[Lev, P-1].Name := S;
+ Song.Score[Lev, P-1].Score := F.ReadInteger(LevS + IntToStr(P), 'Score', 0);
+
+ Inc(P);
+ S := F.ReadString(LevS + IntToStr(P), 'Name', '');
+ end;
+ end;
+end;
+
+procedure AddScore(var Song: TSong; Level: integer; Name: string; Score: integer);
+var
+ S: integer;
+ S2: integer;
+begin
+ S := 0;
+ while (S <= High(Song.Score[Level])) and (Score <= Song.Score[Level, S].Score) do
+ Inc(S);
+ // S has the number for new score
+
+
+ // we create new score
+ SetLength(Song.Score[Level], Length(Song.Score[Level]) + 1);
+
+ // we move down old scores
+ for S2 := High(Song.Score[Level])-1 downto S do
+ Song.Score[Level, S2+1] := Song.Score[Level, S2];
+
+ // we fill new score
+ Song.Score[Level, S].Name := Name;
+ Song.Score[Level, S].Score := Score;
+
+ if Length(Song.Score[Level]) > 5 then begin
+ SetLength(Song.Score[Level], 5);
+ end;
+end;
+
+procedure WriteScore(var Song: TSong);
+var
+ F: TIniFile;
+ S: integer;
+ Lev: integer;
+ LevS: string;
+ FileName: string;
+begin
+ FileName := Song.Path + ChangeFileExt(Song.FileName, '.sco');
+ if (not FileExists(FileName)) or (FileExists(FileName) and DeleteFile(FileName)) then begin
+ // file has been deleted -> creating new file
+ F := TIniFile.Create(FileName);
+
+ for Lev := 0 to 2 do begin
+ case Lev of
+ 0: LevS := 'Easy';
+ 1: LevS := 'Normal';
+ 2: LevS := 'Hard';
+ end;
+
+ for S := 0 to high(Song.Score[Lev]) do begin
+ F.WriteString(LevS + IntToStr(S+1), 'Name', Song.Score[Lev, S].Name);
+ F.WriteInteger(LevS + IntToStr(S+1), 'Score', Song.Score[Lev, S].Score);
+
+ end; // for S
+ end; // for Lev
+ F.Free;
+ end; // if
+end;
+
+end.