unit iSettings;

interface

uses
  Windows, Classes, SysUtils, IniFiles;

type
  TSettings = class
  private
    const SECTIONGRAPHICS = 'Graphics';
    const SECTIONAUDIO = 'Audio';
  public
  const
    FILENAME = 'Settings.ini';  
    WindowWidth = 1920;
    WindowHeight = 1080;
  var
    IsGlowEnabled: Boolean;
    IsMotionBlurEnabled: Boolean;
    IsParticlesEnabled: Boolean;
    IsShowFPS: Boolean;
    IsMaximize: Boolean;
    ApplicationPath: string;
    PlayerColor: Cardinal;
    PlayerColorIndex: Integer;
    MusicVolume: Integer;
    procedure Initialize;
    procedure Finalize;
  end;

var
  Settings: TSettings;

implementation

{ TSettings }

procedure TSettings.Finalize;
var
  ini: TIniFile;
begin
  ApplicationPath := ExtractFilePath(ParamStr(0));

  ini := TIniFile.Create(ApplicationPath + FILENAME);
  try
    ini.WriteBool(SECTIONGRAPHICS, 'Glow', IsGlowEnabled);
    ini.WriteBool(SECTIONGRAPHICS, 'MotionBlur', IsMotionBlurEnabled);
    ini.WriteBool(SECTIONGRAPHICS, 'ShowFPS', IsShowFPS);
    ini.WriteBool(SECTIONGRAPHICS, 'Maximize', IsMaximize);
    ini.WriteInteger(SECTIONGRAPHICS, 'PlayerColor', PlayerColorIndex);
    ini.WriteInteger(SECTIONAUDIO, 'MusicVolume', MusicVolume);
  finally
    ini.Free;
  end;
end;

procedure TSettings.Initialize;
var
  ini: TIniFile;
begin
  ApplicationPath := ExtractFilePath(ParamStr(0));

  ini := TIniFile.Create(ApplicationPath + FILENAME);
  try
    IsGlowEnabled := ini.ReadBool(SECTIONGRAPHICS, 'Glow', True);
    IsMotionBlurEnabled := ini.ReadBool(SECTIONGRAPHICS, 'MotionBlur', True);
    IsShowFPS := ini.ReadBool(SECTIONGRAPHICS, 'ShowFPS', False);
    IsMaximize := ini.ReadBool(SECTIONGRAPHICS, 'Maximize', False);
    PlayerColorIndex := ini.ReadInteger(SECTIONGRAPHICS, 'PlayerColor', 0);
    MusicVolume := ini.ReadInteger(SECTIONAUDIO, 'MusicVolume', 10);
  finally
    ini.Free;
  end;
end;

initialization
  Settings := TSettings.Create;
  Settings.Initialize;

finalization
  Settings.Finalize;
  Settings.Free;

end.
