unit Tile;

interface

uses
  Classes, SysUtils, Generics.Collections, RegistryEx;

type
  TTileAction = (taNone, taMove, taMerge, taAppear);

  { TTile }

  TTile = class
  public
    Index: TPoint;
    Value: Integer;
    NewValue: Integer;
    NewUnmergeable: Boolean;
    Merged: Boolean;
    Action: TTileAction;
    Shift: TPoint;
    Disabled: Boolean;
    Unmergeable: Boolean;
    procedure Clear;
    procedure Assign(Source: TTile);
    procedure SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
    procedure LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
  end;

  TTiles = class(TObjectList<TTile>)
  end;


implementation

{ TTile }

procedure TTile.Clear;
begin
  Value := 0;
  Action := taNone;
  Disabled := False;
  Unmergeable := False;
end;

procedure TTile.Assign(Source: TTile);
begin
  Index := Source.Index;
  Value := Source.Value;
  Merged := Source.Merged;
  Disabled := Source.Disabled;
  Unmergeable := Source.Unmergeable;
end;

procedure TTile.SaveToRegistry(Reg: TRegistryEx; RegContext: TRegistryContext);
begin
  with Reg do begin
    CurrentContext := RegContext;

    WriteInteger('Value', Value);
    WriteBool('Disabled', Disabled);
    WriteBool('Unmergeable', Unmergeable);
  end;
end;

procedure TTile.LoadFromRegistry(Reg: TRegistryEx; RegContext: TRegistryContext
  );
begin
  with Reg do begin
    CurrentContext := RegContext;

    Value := ReadIntegerWithDefault('Value', Value);
    Disabled := ReadBoolWithDefault('Disabled', Disabled);
    Unmergeable := ReadBoolWithDefault('Unmergeable', Unmergeable);
  end;
end;

end.

