<commit_before>unit KM_GameAppSettings;
{$I KaM_Remake.inc}
interface
uses
  Generics.Collections,
  KM_IoXML,
  KM_Settings;


type
  // Common implementation for settings stored and loaded from XML
  TKMSettingsXML = class(TKMSettings)
  private
    fXML: TKMXmlDocument;
  protected
    fRoot: TKMXmlNode;
    procedure LoadFromFile(const aPath: string); override;
    procedure SaveToFile(const aPath: string); override;
  public
    constructor Create;
    destructor Destroy; override;
  end;


  TKMGameAppSettingsPart = class;


  // GameApp settings, stored in the XML
  // Loaded and saved only once
  TKMGameAppSettings = class(TKMSettingsXML)
  private
    fSettingParts: TList<TKMGameAppSettingsPart>;

    procedure RegisterSettingPart(aSettingPart: TKMGameAppSettingsPart);
    procedure UnRegisterSettingPart(aSettingPart: TKMGameAppSettingsPart);
  protected
    procedure LoadFromFile(const aPath: string); override;
    procedure SaveToFile(const aPath: string); override;
    function GetDefaultSettingsName: string; override;
    function GetSettingsName: string; override;
  public
    constructor Create;
    destructor Destroy; override;

    property Root: TKMXmlNode read fRoot;
  end;


  // Part of GameApp settings, which are stored in the XML
  TKMGameAppSettingsPart = class abstract
  private
    function GetNeedSave: Boolean;
    function GetRoot: TKMXmlNode;
  protected
    procedure Changed;
    property NeedsSave: Boolean read GetNeedSave;
    function GetDefaultSettingsName: string;

    property Root: TKMXmlNode read GetRoot;
  public
    constructor Create;
    destructor Destroy; override;

    procedure SaveToXML; virtual; abstract;
    procedure LoadFromXML; virtual; abstract;
    procedure SaveSettings(aForce: Boolean = False); virtual;
  end;

var
  gGameAppSettings: TKMGameAppSettings;


implementation
uses
  SysUtils, INIfiles, Math,
  KM_Defaults;


{ TKMSettings }
constructor TKMSettingsXML.Create;
begin
  // Create xml Settings in the shared folder
  inherited Create(False);
end;


destructor TKMSettingsXML.Destroy;
begin
//  fXML.Free;

  inherited;
end;


procedure TKMSettingsXML.LoadFromFile(const aPath: string);
begin<commit_msg>Comment fix<commit_after>unit KM_GameAppSettings;
{$I KaM_Remake.inc}
interface
uses
  Generics.Collections,
  KM_IoXML,
  KM_Settings;


type
  // Common implementation for settings stored and loaded from XML
  TKMSettingsXML = class(TKMSettings)
  private
    fXML: TKMXmlDocument;
  protected
    fRoot: TKMXmlNode;
    procedure LoadFromFile(const aPath: string); override;
    procedure SaveToFile(const aPath: string); override;
  public
    constructor Create;
    destructor Destroy; override;
  end;


  TKMGameAppSettingsPart = class;


  // GameApp settings, stored in the XML
  // Loaded and saved only once
  TKMGameAppSettings = class(TKMSettingsXML)
  private
    fSettingParts: TList<TKMGameAppSettingsPart>;

    procedure RegisterSettingPart(aSettingPart: TKMGameAppSettingsPart);
    procedure UnRegisterSettingPart(aSettingPart: TKMGameAppSettingsPart);
  protected
    procedure LoadFromFile(const aPath: string); override;
    procedure SaveToFile(const aPath: string); override;
    function GetDefaultSettingsName: string; override;
    function GetSettingsName: string; override;
  public
    constructor Create;
    destructor Destroy; override;

    property Root: TKMXmlNode read fRoot;
  end;


  // Part of GameApp settings, which are stored in the XML
  TKMGameAppSettingsPart = class abstract
  private
    function GetNeedSave: Boolean;
    function GetRoot: TKMXmlNode;
  protected
    procedure Changed;
    property NeedsSave: Boolean read GetNeedSave;
    function GetDefaultSettingsName: string;

    property Root: TKMXmlNode read GetRoot;
  public
    constructor Create;
    destructor Destroy; override;

    procedure SaveToXML; virtual; abstract;
    procedure LoadFromXML; virtual; abstract;
    procedure SaveSettings(aForce: Boolean = False); virtual;
  end;

var
  gGameAppSettings: TKMGameAppSettings;


implementation
uses
  SysUtils, INIfiles, Math,
  KM_Defaults;


{ TKMSettingsXML }
constructor TKMSettingsXML.Create;
begin
  // Create xml Settings in the shared folder
  inherited Create(False);
end;


destructor TKMSettingsXML.Destroy;
begin
//  fXML.Free;

  inherited;
end;


procedure TKMSettingsXML.LoadFromFile(const aPath: string);
begin
{'fraction_non_alphanumeric': 0.06319618095021595, 'fraction_numerical': 0.0, 'mean_word_length': 4.378973105134475, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1194690', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1254, 'n_words': 378}