aboutsummaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* turned off platform specific warnings as we know that they aretobigun2008-08-081-0/+3
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1234 b956fd51-792f-4845-bead-9b4dfca2ff2c
* warnings suppressedtobigun2008-08-081-0/+4
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1233 b956fd51-792f-4845-bead-9b4dfca2ff2c
* result-values for TMenu.Draw() addedtobigun2008-08-087-4/+9
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1232 b956fd51-792f-4845-bead-9b4dfca2ff2c
* somw warnings removedtobigun2008-08-086-3/+36
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1231 b956fd51-792f-4845-bead-9b4dfca2ff2c
* - TStatResult is an abstract class now.tobigun2008-08-083-171/+234
| | | | | | | - GetStats returns a TList of TStatResult now - Free the result-list with FreeStats git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1230 b956fd51-792f-4845-bead-9b4dfca2ff2c
* - Reset-Timestamp changed from STRING to INTEGER (stored as UNIX-timestamp)tobigun2008-08-072-12/+44
| | | | | | - Version-number for database-file added git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1229 b956fd51-792f-4845-bead-9b4dfca2ff2c
* - Introduced TStatType.tobigun2008-08-073-160/+182
| | | | | | - Replaced TSQLiteTable with the new TSQLiteUniTable. The ..UniTable-version does not retrieve data at once (this feature is not needed/wanted in most cases). The major advantage of this version is a better handling of datatypes. TSQLiteTable does not handle datatypes correctly (and even crashes) if the field-types are not one of the SQLite types (e.g. an INT(12) field will crash if it accessed by FieldAsInteger, the same applies to "integer" but the upper-case version "INTEGER" works). With TSQLiteUniTable those crashes should not occur. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1228 b956fd51-792f-4845-bead-9b4dfca2ff2c
* SUM/COUNT replaced by AVGtobigun2008-08-071-5/+5
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1227 b956fd51-792f-4845-bead-9b4dfca2ff2c
* - strings are bound now to avoid failures with unquoted stringstobigun2008-08-071-192/+243
| | | | | | | | | | - better error/exception handling - Strings (PlayerName, Artist, Title) are stored as UTF8 - TSQLiteTable objects returned by GetTable() are freed now. Memory was not released before causing memory leaks. - replaced `` with []. Both are not ANSI SQL compatible, `` is used in MySQL, [] in MSSQL. In contrast to `` SQLite states that [] is supported. "" is not used as it is interpreted as a string if an identifier with this name does not exist. This will make debugging mor difficult as SQLite does not return an error code if an identifier was misspelled. - cleanup git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1226 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Update of SQLiteTable3. The file was additionally patched to support ↵tobigun2008-08-074-125/+865
| | | | | | Format()-style bindings (BindData) and FieldAsBlobPtr. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1225 b956fd51-792f-4845-bead-9b4dfca2ff2c
* moved AllocateHWnd/DeallocateHWnd from UCommon.pas to WinAllocation.pas. Do ↵tobigun2008-08-067-115/+135
| | | | | | NOT use them in USDX code. They are just by the DirWatch and Midi... libs in FPC (Windows). git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1224 b956fd51-792f-4845-bead-9b4dfca2ff2c
* avoid seeking if video is not initializedtobigun2008-08-061-0/+3
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1223 b956fd51-792f-4845-bead-9b4dfca2ff2c
* RenderAspect is not neededtobigun2008-08-061-4/+9
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1222 b956fd51-792f-4845-bead-9b4dfca2ff2c
* support for projectM 1.2tobigun2008-08-065-16/+31
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1221 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Fix for USDX first run and no config.ini problem (ini is saved on startup)mogguh2008-08-031-1/+5
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1220 b956fd51-792f-4845-bead-9b4dfca2ff2c
* usage of glPushAttrib(GL_VIEWPORT_BIT) to save the viewport settings.tobigun2008-07-211-2/+5
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1219 b956fd51-792f-4845-bead-9b4dfca2ff2c
* fpc 2.2.2 fix, clocale is not available for windowstobigun2008-07-211-0/+2
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1218 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Fixed a bug in UScreenTop5: instead of a lokal var a config value was ↵whiteshark02008-07-191-1/+1
| | | | | | changed to a not existing value when there was a game w/ 6 Players. This causes Player 5's and 6's Scores not to apear in the highscores at the first song and may cause a crash when the config will be saved after singing. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1217 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Some changes in ReadScore and WriteScore to prevent for crashes caused by ↵whiteshark02008-07-191-3/+14
| | | | | | more than 5 score entrys per song/difficulty git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1216 b956fd51-792f-4845-bead-9b4dfca2ff2c
* renamed TLineState to TLyricsStatetobigun2008-07-192-6/+6
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1215 b956fd51-792f-4845-bead-9b4dfca2ff2c
* renamed TLineState to TLyricsStatetobigun2008-07-195-57/+57
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1214 b956fd51-792f-4845-bead-9b4dfca2ff2c
* clean-up, removed some unused stufftobigun2008-07-192-124/+36
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1213 b956fd51-792f-4845-bead-9b4dfca2ff2c
* PTexture addedtobigun2008-07-191-8/+9
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1212 b956fd51-792f-4845-bead-9b4dfca2ff2c
* lyric engine patches, solvestobigun2008-07-196-459/+568
| | | | | | | | | | - pixeled/transparent fonts bug - some lines were erroneously marked active or disabled - state was not initialized correctly - negative gap problem (TLyricLine.Start was of type cardinal) - some more lyrics bugs git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1211 b956fd51-792f-4845-bead-9b4dfca2ff2c
* - SetFontBlend addedtobigun2008-07-191-117/+127
| | | | | | - clean-up git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1210 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Fonts now look better in TEXTURE_TYPE_TRANSPARENT mode.tobigun2008-07-194-0/+0
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1209 b956fd51-792f-4845-bead-9b4dfca2ff2c
* references to UMacResources.pp removedtobigun2008-07-172-4/+0
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1208 b956fd51-792f-4845-bead-9b4dfca2ff2c
* - UPlatformXYZ.pas clean-uptobigun2008-07-176-172/+216
| | | | | | | - TPlatform now implements common behaviour - added TPlatform.Init() git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1207 b956fd51-792f-4845-bead-9b4dfca2ff2c
* - cleanuptobigun2008-07-171-65/+60
| | | | | | | | - partition into logical sections - Mac app-bundle clean-up - log-dir stuff removed (log dir will be moved to the ~/.ultrastart/logs soon as we do not need special permissions as in /var/log) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1206 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Mac OS X version check addedtobigun2008-07-171-0/+12
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1205 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Renamed the old ULyrics_bak.pas to UEditorLyrics.pas as it is used in the ↵tobigun2008-07-174-440/+243
| | | | | | editor only. This might be replaced by ULyrics.pas later. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1204 b956fd51-792f-4845-bead-9b4dfca2ff2c
* update of install-sh (taken from automake 1.10). This should fix the problem ↵tobigun2008-07-161-202/+470
| | | | | | that occurs if a filename contains spaces. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1203 b956fd51-792f-4845-bead-9b4dfca2ff2c
* removed outdated filestobigun2008-07-166-4981/+17
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1202 b956fd51-792f-4845-bead-9b4dfca2ff2c
* New place for the Resources for Mac OS X: $HOME/Appliations ↵k-m_schindler2008-07-154-15/+53
| | | | | | Support/UltraStarDeluxe/Resources git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1201 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Cleaning up our SVN, removing unneeded files.mogguh2008-07-153-204/+0
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1200 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Cleaning up our SVN, removing unneeded files.mogguh2008-07-153-0/+0
| | | | | | These DLLs will be provided via wiki.ultrastardeluxe.org git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1199 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Cleaning up our SVN, removing unneeded files.mogguh2008-07-1513-910/+0
| | | | | | zlportio is no longer needed. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1198 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Cleaning up our SVN, removing unneeded files.mogguh2008-07-15253-36748/+0
| | | | | | | | Linux: Visuals are within the ProjectM package Windows: The needed files will be on wiki.ultrastardeluxe.org MacOSX: As on Windows, the files will show up on our wiki git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1197 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Changed the projectM version to the dll version provided at the wiki ↵mogguh2008-07-151-2/+2
| | | | | | (compile:windows) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1196 b956fd51-792f-4845-bead-9b4dfca2ff2c
* As sdl_ttf isn't of any use for now, I uncommented all occurrences of it.mogguh2008-07-154-10/+12
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1195 b956fd51-792f-4845-bead-9b4dfca2ff2c
* Lyric help bar works againtobigun2008-07-141-73/+119
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1194 b956fd51-792f-4845-bead-9b4dfca2ff2c
* cleanuptobigun2008-07-141-52/+49
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1193 b956fd51-792f-4845-bead-9b4dfca2ff2c
* - conversion of TLyricLine into a class. tobigun2008-07-141-134/+149
| | | | | | | - Added GetLowerLine/GetUpperLine. - cleanup git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1192 b956fd51-792f-4845-bead-9b4dfca2ff2c
* TLine.LyricWidth (width of the line in pixels) is marked as deprecated. Do ↵tobigun2008-07-141-2/+4
| | | | | | not use this as the stored width is not correct. Use TLyricsEngine.GetUpperLine().Width instead. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1191 b956fd51-792f-4845-bead-9b4dfca2ff2c
* converted remaining BMPs to PNGtobigun2008-07-1410-12/+12
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1190 b956fd51-792f-4845-bead-9b4dfca2ff2c
* removed unused local vartobigun2008-07-121-1/+0
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1189 b956fd51-792f-4845-bead-9b4dfca2ff2c
* - cleanup/comments for TDisplay.Create tobigun2008-07-122-154/+101
| | | | | | | | - fading works now, it was broken because RenderW/H was not defined when SwapBuffers() was called for the first time. This caused glOrtho() to set the OpenGL error state. When fading was initialized in UDisplay this error-state was checked to see if glGenTextures failed. Although it didn't the error state was set because of the older error in glOrtho (Note: errors aren't reset after a successful OpenGL call), so it was wrongly assumed that no texture could be allocated. This problem was fixed by defining RenderW/H before the first call of SwapBuffers and resetting OpenGL's error state before calling an OpenGL function whose error state is to be checked. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1188 b956fd51-792f-4845-bead-9b4dfca2ff2c
* cleanup + commentstobigun2008-07-121-6/+19
| | | | git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1187 b956fd51-792f-4845-bead-9b4dfca2ff2c
* unit UScreenStatMain;GogolNr12008-07-123-90/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | interface {$IFDEF FPC} {$MODE Delphi} {$ENDIF} {$I switches.inc} uses UMenu, SDL, SysUtils, UDisplay, UMusic, UIni, UThemes; type TScreenStatMain = class(TMenu) private //Some Stat Value that don't need to be calculated 2 times SongswithVid: Cardinal; public TextOverview: integer; constructor Create; override; function ParseInput(PressedKey: Cardinal; CharCode: WideChar; PressedDown: Boolean): Boolean; override; procedure onShow; override; procedure SetAnimationProgress(Progress: real); override; procedure SetOverview; end; implementation uses UGraphic, UDataBase, USongs, USong, ULanguage, UCommon, {$IFDEF win32} windows, {$ELSE} sysconst, {$ENDIF} ULog; function TScreenStatMain.ParseInput(PressedKey: Cardinal; CharCode: WideChar; PressedDown: Boolean): Boolean; begin Result := true; If (PressedDown) Then begin // Key Down // check normal keys case WideCharUpperCase(CharCode)[1] of 'Q': begin Result := false; Exit; end; end; // check special keys case PressedKey of SDLK_ESCAPE, SDLK_BACKSPACE : begin Ini.Save; AudioPlayback.PlaySound(SoundLib.Back); FadeTo(@ScreenMain); end; SDLK_RETURN: begin //Exit Button Pressed if Interaction = 4 then begin AudioPlayback.PlaySound(SoundLib.Back); FadeTo(@ScreenMain); end else //One of the Stats Buttons Pressed begin AudioPlayback.PlaySound(SoundLib.Back); ScreenStatDetail.Typ := Interaction; FadeTo(@ScreenStatDetail); end; end; SDLK_LEFT: begin InteractPrev; end; SDLK_RIGHT: begin InteractNext; end; SDLK_UP: begin InteractPrev; end; SDLK_DOWN: begin InteractNext; end; end; end; end; constructor TScreenStatMain.Create; var I: integer; begin inherited Create; TextOverview := AddText(Theme.StatMain.TextOverview); LoadFromTheme(Theme.StatMain); AddButton(Theme.StatMain.ButtonScores); if (Length(Button[0].Text)=0) then AddButtonText(14, 20, Theme.StatDetail.Description[0]); AddButton(Theme.StatMain.ButtonSingers); if (Length(Button[1].Text)=0) then AddButtonText(14, 20, Theme.StatDetail.Description[1]); AddButton(Theme.StatMain.ButtonSongs); if (Length(Button[2].Text)=0) then AddButtonText(14, 20, Theme.StatDetail.Description[2]); AddButton(Theme.StatMain.ButtonBands); if (Length(Button[3].Text)=0) then AddButtonText(14, 20, Theme.StatDetail.Description[3]); AddButton(Theme.StatMain.ButtonExit); if (Length(Button[4].Text)=0) then AddButtonText(14, 20, Theme.Options.Description[4]); Interaction := 0; //Set Songs with Vid SongswithVid := 0; For I := 0 to Songs.SongList.Count -1 do if (TSong(Songs.SongList[I]).Video <> '') then Inc(SongswithVid); end; procedure TScreenStatMain.onShow; begin inherited; //Set Overview Text: SetOverview; end; procedure TScreenStatMain.SetOverview; type TwSystemTime = record wYear, wMonth, wDayOfWeek, wDay, wHour, wMinute, wSecond, wMilliseconds: Word; end; var Overview, Formatstr: String; I: Integer; //Some Vars to Save Attributes to A1, A2, A3: Integer; A4, A5: String; Result1, Result2: AStatResult; ResetTime: TSystemTime; begin //Song Overview //Introduction Formatstr := Language.Translate ('STAT_OVERVIEW_INTRO'); (*Format: %0:d Ultrastar Version %1:d Day of Reset (A1) %2:d Month of Reset (A2) %3:d Year of Reset (A3)*) DateTimeToSystemTime(Database.GetStatReset, ResetTime); // ResetTime := GetFileCreation(Database.Filename); {$IFDEF MSWINDOWS} A1 := ResetTime.wDay; A2 := ResetTime.wMonth; A3 := ResetTime.wYear; {$ELSE} A1 := ResetTime.Day; A2 := ResetTime.Month; A3 := ResetTime.Year; {$ENDIF} try Overview := Format(Formatstr, [Language.Translate('US_VERSION'), A1, A2, A3]); except on E: EConvertError do Log.LogError('Error Parsing FormatString "STAT_OVERVIEW_INTRO": ' + E.Message); end; Formatstr := Language.Translate ('STAT_OVERVIEW_SONG'); {Format: %0:d Count Songs (A1) %1:d Count of Sung Songs (A2) %2:d Count of UnSung Songs %3:d Count of Songs with Video (A3) %4:s Name of the most popular Song} A1 := Songs.SongList.Count; A2 := Database.GetTotalEntrys(2); A3 := SongswithVid; SetLength(Result1, 1); Database.GetStats(Result1, 2, 1, 0, False); A4 := Result1[0].Artist; A5 := Result1[0].Title; try Overview := Overview + '\n \n' + Format(Formatstr, [A1, A2, A1-A2, A3, A4, A5]); except on E: EConvertError do Log.LogError('Error Parsing FormatString "STAT_OVERVIEW_SONG": ' + E.Message); end; //Player Overview Formatstr := Language.Translate ('STAT_OVERVIEW_PLAYER'); {Format: %0:d Count Players (A1) %1:s Best Player (Result) %2:d Best Players Score %3:s Best Score Player (Result2) %4:d Best Score} A1 := Database.GetTotalEntrys(1); SetLength(Result1, 1); Database.GetStats(Result1, 1, 1, 0, False); SetLength(Result2, 1); Database.GetStats(Result2, 0, 1, 0, False); try Overview := Overview + '\n \n' + Format(Formatstr, [A1, Result1[0].Player, Result1[0].AverageScore, Result2[0].Singer, Result2[0].Score]); except on E: EConvertError do Log.LogError('Error Parsing FormatString "STAT_OVERVIEW_PLAYER": ' + E.Message); end; Text[0].Text := Overview; end; procedure TScreenStatMain.SetAnimationProgress(Progress: real); var I: Integer; begin For I := 0 to high(Button) do Button[I].Texture.ScaleW := Progress; end; end. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1186 b956fd51-792f-4845-bead-9b4dfca2ff2c
* unit UDataBase;GogolNr12008-07-121-31/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | interface {$IFDEF FPC} {$MODE Delphi} {$ENDIF} {$I switches.inc} uses USongs, USong, SQLiteTable3; //-------------------- //DataBaseSystem - Class including all DB Methods //-------------------- type TStatResult = record Case Typ: Byte of 0: (Singer: ShortString; Score: Word; Difficulty: Byte; SongArtist: ShortString; SongTitle: ShortString); 1: (Player: ShortString; AverageScore: Word); 2: (Artist: ShortString; Title: ShortString; TimesSung: Word); 3: (ArtistName: ShortString; TimesSungtot: Word); end; AStatResult = Array of TStatResult; TDataBaseSystem = class private ScoreDB: TSqliteDatabase; sFilename: string; public property Filename: String read sFilename; Destructor Destroy; override; Procedure Init(const Filename: string); procedure ReadScore(Song: TSong); procedure AddScore(Song: TSong; Level: integer; Name: string; Score: integer); procedure WriteScore(Song: TSong); Function GetStats(var Stats: AStatResult; const Typ, Count: Byte; const Page: Cardinal; const Reversed: Boolean): Boolean; Function GetTotalEntrys(const Typ: Byte): Cardinal; Function GetStatReset: TDateTime; end; var DataBase: TDataBaseSystem; implementation uses IniFiles, ULog, StrUtils, SysUtils; const cUS_Scores = 'us_scores'; cUS_Songs = 'us_songs'; cUS_Statistics_Info = 'us_statistics_info'; //-------------------- //Create - Opens Database and Create Tables if not Exist //-------------------- Procedure TDataBaseSystem.Init(const Filename: string); begin Log.LogStatus('Initializing database: "'+Filename+'"', 'TDataBaseSystem.Init'); //Open Database ScoreDB := TSqliteDatabase.Create( Filename ); sFilename := Filename; try //Look for Tables => When not exist Create them if not ScoreDB.TableExists( cUS_Scores ) then begin ScoreDB.execsql('CREATE TABLE `'+cUS_Scores+'` (`SongID` INT( 11 ) NOT NULL , `Difficulty` INT( 1 ) NOT NULL , `Player` VARCHAR( 150 ) NOT NULL , `Score` INT( 5 ) NOT NULL );'); debugWriteln( 'TDataBaseSystem.Init - CREATED US_Scores' ); end; if not ScoreDB.TableExists( cUS_Songs ) then begin ScoreDB.execsql('CREATE TABLE `'+cUS_Songs+'` (`ID` INTEGER PRIMARY KEY, `Artist` VARCHAR( 255 ) NOT NULL , `Title` VARCHAR( 255 ) NOT NULL , `TimesPlayed` int(5) NOT NULL );'); debugWriteln( 'TDataBaseSystem.Init - CREATED US_Songs' ); end; if not ScoreDB.TableExists( cUS_Statistics_Info ) then begin ScoreDB.execsql('CREATE TABLE `'+cUS_Statistics_Info+'` (`ResetTime` VARCHAR(17) );'); ScoreDB.execsql('INSERT INTO `'+cUS_Statistics_Info+'` (`ResetTime`) VALUES ("'+datetimetostr(now)+'");'); debugWriteln( 'TDataBaseSystem.Init - CREATED US_Statistics_Info' ); end; //Not possible because of String Limitation to 255 Chars //Need to rewrite Wrapper {if not ScoreDB.TableExists('US_SongCache') then ScoreDB.ExecSQL('CREATE TABLE `US_SongCache` (`Path` VARCHAR( 255 ) NOT NULL , `Filename` VARCHAR( 255 ) NOT NULL , `Title` VARCHAR( 255 ) NOT NULL , `Artist` VARCHAR( 255 ) NOT NULL , `Folder` VARCHAR( 255 ) NOT NULL , `Genre` VARCHAR( 255 ) NOT NULL , `Edition` VARCHAR( 255 ) NOT NULL , `Language` VARCHAR( 255 ) NOT NULL , `Creator` VARCHAR( 255 ) NOT NULL , `Cover` VARCHAR( 255 ) NOT NULL , `Background` VARCHAR( 255 ) NOT NULL , `Video` VARCHAR( 255 ) NOT NULL , `VideoGap` FLOAT NOT NULL , `Gap` FLOAT NOT NULL , `Start` FLOAT NOT NULL , `Finish` INT( 11 ) NOT NULL , `BPM` INT( 5 ) NOT NULL , `Relative` BOOLEAN NOT NULL , `NotesGap` INT( 11 ) NOT NULL);');} finally Log.LogInfo( cUS_Songs +' exists: ' + IfThen(ScoreDB.TableExists(cUS_Songs), 'true', 'false'), 'TDataBaseSystem.Init'); Log.LogInfo( cUS_Scores +' exists: ' + IfThen(ScoreDB.TableExists(cUS_Scores), 'true', 'false'), 'TDataBaseSystem.Init'); //ScoreDB.Free; end; end; //-------------------- //Destroy - Frees Database //-------------------- Destructor TDataBaseSystem.Destroy; begin Log.LogInfo('TDataBaseSystem.Free', 'TDataBaseSystem.Destroy'); freeandnil( ScoreDB ); inherited; end; //-------------------- //ReadScore - Read Scores into SongArray //-------------------- procedure TDataBaseSystem.ReadScore(Song: TSong); var TableData: TSqliteTable; Difficulty: Integer; begin if not assigned( ScoreDB ) then exit; //ScoreDB := TSqliteDatabase.Create(sFilename); try try //Search Song in DB TableData := ScoreDB.GetTable('SELECT `Difficulty`, `Player`, `Score` FROM `'+cUS_Scores+'` WHERE `SongID` = (SELECT `ID` FROM `us_songs` WHERE `Artist` = "' + Song.Artist + '" AND `Title` = "' + Song.Title + '" LIMIT 1) ORDER BY `Score` DESC LIMIT 15'); //Empty Old Scores SetLength (Song.Score[0], 0); SetLength (Song.Score[1], 0); SetLength (Song.Score[2], 0); while not TableData.Eof do //Go through all Entrys begin //Add one Entry to Array Difficulty := StrToIntDef(TableData.FieldAsString(TableData.FieldIndex['Difficulty']), -1); if (Difficulty >= 0) AND (Difficulty <= 2) then begin SetLength(Song.Score[Difficulty], Length(Song.Score[Difficulty]) + 1); Song.Score[Difficulty, high(Song.Score[Difficulty])].Name := TableData.FieldAsString(TableData.FieldIndex['Player']); Song.Score[Difficulty, high(Song.Score[Difficulty])].Score := StrtoInt(TableData.FieldAsString(TableData.FieldIndex['Score'])); end; TableData.Next; end; // While not TableData.EOF except for Difficulty := 0 to 2 do begin SetLength(Song.Score[Difficulty], 1); Song.Score[Difficulty, 1].Name := 'Error Reading ScoreDB'; end; end; finally //ScoreDb.Free; end; end; //-------------------- //AddScore - Add one new Score to DB //-------------------- procedure TDataBaseSystem.AddScore(Song: TSong; Level: integer; Name: string; Score: integer); var ID: Integer; TableData: TSqliteTable; begin if not assigned( ScoreDB ) then exit; //ScoreDB := TSqliteDatabase.Create(sFilename); try //Prevent 0 Scores from being added if (Score > 0) then begin ID := ScoreDB.GetTableValue('SELECT `ID` FROM `'+cUS_Songs+'` WHERE `Artist` = "' + Song.Artist + '" AND `Title` = "' + Song.Title + '"'); if ID = 0 then //Song doesn't exist -> Create begin ScoreDB.ExecSQL ('INSERT INTO `'+cUS_Songs+'` ( `ID` , `Artist` , `Title` , `TimesPlayed` ) VALUES (NULL , "' + Song.Artist + '", "' + Song.Title + '", "0");'); ID := ScoreDB.GetTableValue('SELECT `ID` FROM `US_Songs` WHERE `Artist` = "' + Song.Artist + '" AND `Title` = "' + Song.Title + '"'); if ID = 0 then //Could not Create Table exit; end; //Create new Entry ScoreDB.ExecSQL('INSERT INTO `'+cUS_Scores+'` ( `SongID` , `Difficulty` , `Player` , `Score` ) VALUES ("' + InttoStr(ID) + '", "' + InttoStr(Level) + '", "' + Name + '", "' + InttoStr(Score) + '");'); //Delete Last Position when there are more than 5 Entrys if ScoreDB.GetTableValue('SELECT COUNT(`SongID`) FROM `'+cUS_Scores+'` WHERE `SongID` = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'"') > 5 then begin TableData := ScoreDB.GetTable('SELECT `Player`, `Score` FROM `'+cUS_Scores+'` WHERE SongID = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'" ORDER BY `Score` ASC LIMIT 1'); ScoreDB.ExecSQL('DELETE FROM `US_Scores` WHERE SongID = "' + InttoStr(ID) + '" AND `Difficulty` = "' + InttoStr(Level) +'" AND `Player` = "' + TableData.FieldAsString(TableData.FieldIndex['Player']) + '" AND `Score` = "' + TableData.FieldAsString(TableData.FieldIndex['Score']) + '"'); end; end; finally //ScoreDB.Free; end; end; //-------------------- //WriteScore - Not needed with new System; But used for Increment Played Count //-------------------- procedure TDataBaseSystem.WriteScore(Song: TSong); begin if not assigned( ScoreDB ) then exit; try //Increase TimesPlayed ScoreDB.ExecSQL ('UPDATE `'+cUS_Songs+'` SET `TimesPlayed` = `TimesPlayed` + "1" WHERE `Title` = "' + Song.Title + '" AND `Artist` = "' + Song.Artist + '";'); except end; end; //-------------------- //GetStats - Write some Stats to Array, Returns True if Chossen Page has Entrys //Case Typ of //0 - Best Scores //1 - Best Singers //2 - Most sung Songs //3 - Most popular Band //-------------------- Function TDataBaseSystem.GetStats(var Stats: AStatResult; const Typ, Count: Byte; const Page: Cardinal; const Reversed: Boolean): Boolean; var Query: String; TableData: TSqliteTable; begin Result := False; if not assigned( ScoreDB ) then exit; if (Length(Stats) < Count) then Exit; {Todo: Add Prevention that only Players with more than 5 Scores are Selected at Typ 2} //Create Query Case Typ of 0: Query := 'SELECT `Player` , `Difficulty` , `Score` , `Artist` , `Title` FROM `'+cUS_Scores+'` INNER JOIN `US_Songs` ON (`SongID` = `ID`) ORDER BY `Score`'; 1: Query := 'SELECT `Player` , ROUND (Sum(`Score`) / COUNT(`Score`)) FROM `'+cUS_Scores+'` GROUP BY `Player` ORDER BY (Sum(`Score`) / COUNT(`Score`))'; 2: Query := 'SELECT `Artist` , `Title` , `TimesPlayed` FROM `'+cUS_Songs+'` ORDER BY `TimesPlayed`'; 3: Query := 'SELECT `Artist` , Sum(`TimesPlayed`) FROM `'+cUS_Songs+'` GROUP BY `Artist` ORDER BY Sum(`TimesPlayed`)'; end; //Add Order Direction If Reversed then Query := Query + ' ASC' else Query := Query + ' DESC'; //Add Limit Query := Query + ' LIMIT ' + InttoStr(Count * Page) + ', ' + InttoStr(Count) + ';'; //Execute Query try TableData := ScoreDB.GetTable(Query); except exit; // this has a try except, because ( on linux at least ) it seems that doing a GetTable, that returns nothing // causes an exception. and in the case of a new Database file, with no scores stored yet... this seems to except here. end; //if Result empty -> Exit if (TableData.RowCount < 1) then exit; //Copy Result to Stats Array while not TableData.Eof do begin Stats[TableData.Row].Typ := Typ; Case Typ of 0:begin Stats[TableData.Row].Singer := TableData.Fields[0]; Stats[TableData.Row].Difficulty := StrtoIntDef(TableData.Fields[1], 0); Stats[TableData.Row].Score := StrtoIntDef(TableData.Fields[2], 0){TableData.FieldAsInteger(2)}; Stats[TableData.Row].SongArtist := TableData.Fields[3]; Stats[TableData.Row].SongTitle := TableData.Fields[4]; end; 1:begin Stats[TableData.Row].Player := TableData.Fields[0]; Stats[TableData.Row].AverageScore := StrtoIntDef(TableData.Fields[1], 0); end; 2:begin Stats[TableData.Row].Artist := TableData.Fields[0]; Stats[TableData.Row].Title := TableData.Fields[1]; Stats[TableData.Row].TimesSung := StrtoIntDef(TableData.Fields[2], 0); end; 3:begin Stats[TableData.Row].ArtistName := TableData.Fields[0]; Stats[TableData.Row].TimesSungtot := StrtoIntDef(TableData.Fields[1], 0); end; end; TableData.Next; end; Result := True; end; //-------------------- //GetTotalEntrys - Get Total Num of entrys for a Stats Query //-------------------- Function TDataBaseSystem.GetTotalEntrys(const Typ: Byte): Cardinal; var Query: String; begin Result := 0; if not assigned( ScoreDB ) then exit; try //Create Query Case Typ of 0: begin Query := 'SELECT COUNT(`SongID`) FROM `'+cUS_Scores+'`;'; if not ScoreDB.TableExists( cUS_Scores ) then exit; end; 1: begin Query := 'SELECT COUNT(DISTINCT `Player`) FROM `'+cUS_Scores+'`;'; if not ScoreDB.TableExists( cUS_Scores ) then exit; end; 2: begin Query := 'SELECT COUNT(`ID`) FROM `'+cUS_Songs+'`;'; if not ScoreDB.TableExists( cUS_Songs ) then exit; end; 3: begin Query := 'SELECT COUNT(DISTINCT `Artist`) FROM `'+cUS_Songs+'`;'; if not ScoreDB.TableExists( cUS_Songs ) then exit; end; end; Result := ScoreDB.GetTableValue(Query); except // TODO : JB_Linux - Why do we get these exceptions on linux !! -> should be solved! on E:ESQLiteException DO begin exit; end; end; end; //-------------------- //GetStatReset - Get reset date of statistic data //-------------------- Function TDataBaseSystem.GetStatReset: TDateTime; var Query: String; TableData: TSqliteTable; begin if not assigned( ScoreDB ) then exit; Query := 'SELECT `ResetTime` FROM `'+cUS_Statistics_Info+'`;'; TableData := ScoreDB.GetTable(Query); result:=StrToDateTime(TableData.Fields[0]); end; end. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1185 b956fd51-792f-4845-bead-9b4dfca2ff2c