<commit_before>unit KM_KeysSettings;
{$I KaM_Remake.inc}
interface
uses
  KM_GameAppSettings;

type
  // Hotkey Settings
  TKMKeysSettings = class(TKMGameAppSettingsPart)
  public
    constructor Create;
    destructor Destroy; override;

    procedure LoadFromXML; override;
    procedure SaveToXML; override;
  end;

var
  gKeySettings: TKMKeysSettings;


implementation
uses
  KM_ResTexts,
  KM_ResKeys,
  KM_ResTypes,

  KM_XmlHelper,
  KM_IoXML;


{ TKMKeysSettings }
constructor TKMKeysSettings.Create;
begin
  inherited;

  gKeySettings := Self;
end;


destructor TKMKeysSettings.Destroy;
begin
  inherited;

  gKeySettings := nil;
end;


procedure TKMKeysSettings.LoadFromXML;
var
  KF: TKMKeyFunction;
  nHotkeys, nKey: TXMLNode;
  keyFuncName: string;
begin
  if Self = nil then Exit;
  inherited;

  nHotkeys := Root.AddOrFindChild('Hotkeys');

  for KF := KEY_FUNC_LOW to High(TKMKeyFunction) do
  begin
    keyFuncName := TKMResKeys.GetKeyFunctionStr(KF);
    if nHotkeys.HasChild(keyFuncName) then
    begin
      nKey := nHotkeys.AddOrFindChild(keyFuncName);
      if nKey.HasAttribute('Key') then
        gResKeys[KF].Key := nKey.Attributes['Key'].AsInteger;
    end;
  end;
end;

procedure TKMKeysSettings.SaveToXML;
var
  KF: TKMKeyFunction;
  nHotkeys, nKey: TXMLNode;
begin
  if Self = nil then Exit;
  inherited;

  nHotkeys := Root.AddOrFindChild('Hotkeys');
<commit_msg>Fix for hotkeys were not loaded from XML on the game start<commit_after>unit KM_KeysSettings;
{$I KaM_Remake.inc}
interface
uses
  KM_GameAppSettings;

type
  // Hotkey Settings
  TKMKeysSettings = class(TKMGameAppSettingsPart)
  public
    constructor Create;
    destructor Destroy; override;

    procedure LoadFromXML; override;
    procedure SaveToXML; override;
  end;

var
  gKeySettings: TKMKeysSettings;


implementation
uses
  KM_ResTexts,
  KM_ResKeys,
  KM_ResTypes,

  KM_XmlHelper,
  KM_IoXML;


{ TKMKeysSettings }
constructor TKMKeysSettings.Create;
begin
  inherited;

  gKeySettings := Self;
end;


destructor TKMKeysSettings.Destroy;
begin
  inherited;

  gKeySettings := nil;
end;


procedure TKMKeysSettings.LoadFromXML;
var
  KF: TKMKeyFunction;
  nHotkeys, nKey: TXMLNode;
  keyFuncName: string;
  keySpec: TKMKeySpec;
begin
  if Self = nil then Exit;
  inherited;

  nHotkeys := Root.AddOrFindChild('Hotkeys');

  for KF := KEY_FUNC_LOW to High(TKMKeyFunction) do
  begin
    keyFuncName := TKMResKeys.GetKeyFunctionStr(KF);
    if nHotkeys.HasChild(keyFuncName) then
    begin
      nKey := nHotkeys.AddOrFindChild(keyFuncName);
      if nKey.HasAttribute('Key') then
      begin
        keySpec := gResKeys[KF];
        keySpec.Key := nKey.Attributes['Key'].AsInteger;
        gResKeys[KF] := keySpec;
      end;
    end;
  end;
end;

procedure TKMKeysSettings.SaveToXML;
var
  KF: TKMKeyFunction;
  nHotkeys, nKey: TXMLNode;
begin
  if Self = nil then Exit;
  inherited;

  nHotkeys := Root.AddOrFindChild('Hotkeys');

{'fraction_non_alphanumeric': 0.08679373723621511, 'fraction_numerical': 0.0, 'mean_word_length': 4.015358361774744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7567461', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1030, 'n_words': 237}